refactor(jsonrpc): centralize block selector parsing into JsonRpcApiUtil#6668
Open
0xbigapple wants to merge 2 commits intotronprotocol:developfrom
Open
refactor(jsonrpc): centralize block selector parsing into JsonRpcApiUtil#66680xbigapple wants to merge 2 commits intotronprotocol:developfrom
0xbigapple wants to merge 2 commits intotronprotocol:developfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR centralizes JSON-RPC block tag and block number resolution in
JsonRpcApiUtilso block selectors are parsed consistently across the JSON-RPC layer.It also removes
Wallet's reverse dependency on JSON-RPC code, eliminates the-1 means latestsentinel, and simplifies the block range resolution logic inLogFilterWrapper.JsonRpcApiUtil.isBlockTag,parseBlockTag, andparseBlockNumber, and moved block tag constants and related errors, includingsafe, intoJsonRpcApiUtil.TronJsonRpcImplto delegate block selector parsing toJsonRpcApiUtil;eth_getBlock*paths now use shared block resolution logic.latest-only validation for state-read APIs such asgetTrxBalance,getStorageAt,getABIOfSmartContract, andeth_call.Wallet, replaced the-1sentinel behavior, and addedgetHeadBlockNum().LogFilterWrapperby making block range handling strategy-based and easier to reason about.Why are these changes required?
Block selector parsing is currently duplicated across
Wallet,JsonRpcApiUtil, andTronJsonRpcImpl, with slightly different responsibilities and control flow in each layer.This creates several problems:
Walletcode to the JSON-RPC layer-1sentinel handling that forces callers to reinterpret results differentlyLogFilterWrapperthat is harder to maintain and verifyBy centralizing parsing in
JsonRpcApiUtil, this PR makes the behavior easier to reason about, reduces coupling, and preserves existing JSON-RPC semantics while removing fragile internal conventions.This PR has been tested by:
Follow up
None.
Extra details