Skip to content

refactor(jsonrpc): centralize block selector parsing into JsonRpcApiUtil#6668

Open
0xbigapple wants to merge 2 commits intotronprotocol:developfrom
0xbigapple:refactor/jsonrpc-block-selector
Open

refactor(jsonrpc): centralize block selector parsing into JsonRpcApiUtil#6668
0xbigapple wants to merge 2 commits intotronprotocol:developfrom
0xbigapple:refactor/jsonrpc-block-selector

Conversation

@0xbigapple
Copy link
Copy Markdown
Collaborator

What does this PR do?
This PR centralizes JSON-RPC block tag and block number resolution in JsonRpcApiUtil so 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 latest sentinel, and simplifies the block range resolution logic in LogFilterWrapper.

  • Added JsonRpcApiUtil.isBlockTag, parseBlockTag, and parseBlockNumber, and moved block tag constants and related errors, including safe, into JsonRpcApiUtil.
  • Updated TronJsonRpcImpl to delegate block selector parsing to JsonRpcApiUtil; eth_getBlock* paths now use shared block resolution logic.
  • Centralized the existing latest-only validation for state-read APIs such as getTrxBalance, getStorageAt, getABIOfSmartContract, and eth_call.
  • Removed JSON-RPC block parsing helpers from Wallet, replaced the -1 sentinel behavior, and added getHeadBlockNum().
  • Simplified the branching logic in LogFilterWrapper by making block range handling strategy-based and easier to reason about.
  • Added tests for block tag parsing and log filter strategy behavior.

Why are these changes required?
Block selector parsing is currently duplicated across Wallet, JsonRpcApiUtil, and TronJsonRpcImpl, with slightly different responsibilities and control flow in each layer.

This creates several problems:

  • duplicated and inconsistent block tag resolution logic
  • an undesirable reverse dependency from core Wallet code to the JSON-RPC layer
  • ambiguous -1 sentinel handling that forces callers to reinterpret results differently
  • complex block range branching in LogFilterWrapper that is harder to maintain and verify

By 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:

  • Unit Tests
  • Manual Testing

Follow up
None.

Extra details

  • This PR is intended as a refactor and cleanup. All JSON-RPC endpoints return identical results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants