-
Notifications
You must be signed in to change notification settings - Fork 82
refactor: create TransactionService class #3646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: create TransactionService class #3646
Conversation
dc202fb
to
58d2386
Compare
081948b
to
b790ba2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Much cleaner and more organized now. Left some Qs and suggestions around.
packages/relay/src/lib/services/factories/ITransactionReceiptFactoryParams.ts
Outdated
Show resolved
Hide resolved
packages/relay/src/lib/services/factories/ITransactionReceiptFactoryParams.ts
Outdated
Show resolved
Hide resolved
packages/relay/src/lib/services/transactionService/TransactionService.ts
Outdated
Show resolved
Hide resolved
* @param requestDetails The request details for logging and tracking | ||
* @returns {Promise<string>} A promise that resolves to the gas price as a hex string | ||
*/ | ||
private async getCurrentGasPriceForBlock(blockHash: string, requestDetails: RequestDetails): Promise<string> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm I think we should think about migrating these private methods, e.g. getCurrentGasPriceForBlock(), getCurrentNetworkExchangeRateInCents(), etc., to a different module as to me these are not necessarily related to transaction
per se but more of helper or utility function. wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the thing is they are only used here, thus i moved them i nthe service, since only this service need them. Maybe we can create a util file for each service, but that kinda seems like an overkill
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see thanks for clarifying. Yeah, maybe if we consider grouping services like BlockService, AccountService, TransactionService, FeeService, etc. into the ethService folder like discussed last time we can migrate these into an ethCommonService or perhaps create a new module like ethServiceHelper or ethServiceUtils to house all the helper functions. That way, we avoid cluttering the space with public transaction-related or account-related etc. methods. Just a suggestion though it’s not within the scope of this PR.
this.eventEmitter.emit(constants.EVENTS.ETH_EXECUTION, { | ||
method: EthImpl.ethEstimateGas, | ||
functionSelector: callData!.substring(0, constants.FUNCTION_SELECTOR_CHAR_LENGTH), | ||
from: transaction.from || '', | ||
to: transaction.to || '', | ||
requestDetails: requestDetails, | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I like this centralized solution, but it does make me a bit angsty. Let’s ensure the metrics work as expected and use the correct keyword for the metric names. Otherwise, Grafana might fail to collect them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what exactly do you think should be changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh it's not about changing things but just make sure that we don't accidentally rename the metrics name or labels or arguments. Make sure we preserve them so no issue on Grafana. Please resolve the conversation if you're confident we got things right.
packages/relay/src/lib/services/transactionService/TransactionService.ts
Outdated
Show resolved
Hide resolved
packages/relay/src/lib/services/transactionService/TransactionService.ts
Outdated
Show resolved
Hide resolved
packages/relay/src/lib/services/transactionService/TransactionService.ts
Outdated
Show resolved
Hide resolved
packages/relay/src/lib/services/transactionService/TransactionService.ts
Show resolved
Hide resolved
packages/relay/src/lib/services/transactionService/TransactionService.ts
Show resolved
Hide resolved
…ion methods from eth.ts to TransactionService Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
bc8fa3b
to
fdc0b6b
Compare
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
packages/relay/src/lib/services/transactionService/TransactionService.ts
Show resolved
Hide resolved
packages/relay/src/lib/services/transactionService/TransactionService.ts
Show resolved
Hide resolved
/** | ||
* Removes the '0x' prefix from a string if present | ||
* @param input The input string | ||
* @returns {string} The input string without the '0x' prefix | ||
*/ | ||
private prune0x(input: string): string { | ||
return input.startsWith(CommonService.EMPTY_HEX) ? input.substring(2) : input; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick note I see an exact prune0x in the SDKClient class too. If it's newly introduced then I guess we can refactor the other one in SDKClient to utils and reuse it but if it's migrated then nvm we can roll with it since it's outside the scope. Anywho if changes needed we can do it in follow-up PRs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would require using common service in sdk client and do more changes, can we address in another PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha — yeah, it was just a quick observation. We should do it in another PR if it requires many changes. Also I see several topics that need to be addressed in different PRs particularly for this topic. Let’s create a centralized technical debt issue for the ETH refactor and house all those topics there. We can create the actual tickets when we actually work on them so we have clear priorities and don’t clutter the ticket board too much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Just left some notes and suggestions if you agree let's create tickets to keep track! Otherwise all good on my end
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]>
Signed-off-by: Konstantina Blazhukova <[email protected]> Signed-off-by: Logan Nguyen <[email protected]>
Description:
This PR refactors the JSON-RPC relay by extracting transaction-related functionality from the eth.ts file into a dedicated TransactionService class and moving shared code into a CommonService. This improves code organization, testability, and maintainability.
Changes:
Moved methods to TransactionService
Fixes:
#3570
#3622