feat(ton): Implement HTTP-RPC based on toncenter v2#3929
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 📝 WalkthroughWalkthroughA new HTTP-RPC client for the TON blockchain was introduced, including comprehensive types, client logic, and live integration tests. Environment variable support and docker-compose configuration were updated to facilitate the new functionality. Documentation was amended to reflect the addition. Changes
Sequence Diagram(s)sequenceDiagram
participant ClientApp
participant TONRPCClient
participant TONCenterAPI
ClientApp->>TONRPCClient: New(endpoint, opts)
ClientApp->>TONRPCClient: GetMasterchainInfo()
TONRPCClient->>TONCenterAPI: POST /jsonRPC getMasterchainInfo
TONCenterAPI-->>TONRPCClient: JSON response
TONRPCClient-->>ClientApp: MasterchainInfo
ClientApp->>TONRPCClient: GetAccountState(account)
TONRPCClient->>TONCenterAPI: POST /jsonRPC getAccountState
TONCenterAPI-->>TONRPCClient: JSON response
TONRPCClient-->>ClientApp: Account
ClientApp->>TONRPCClient: SendMessage(payload)
TONRPCClient->>TONCenterAPI: POST /jsonRPC sendMessage
TONCenterAPI-->>TONRPCClient: JSON response
TONRPCClient-->>ClientApp: Result
Assessment against linked issues
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
|
!!!WARNING!!! Be very careful about using Only suppress a single rule (or a specific set of rules) within a section of code, while continuing to scan for other problems. To do this, you can list the rule(s) to be suppressed within the #nosec annotation, e.g: /* #nosec G401 */ or //#nosec G201 G202 G203 Pay extra attention to the way |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #3929 +/- ##
===========================================
- Coverage 64.87% 64.21% -0.66%
===========================================
Files 472 474 +2
Lines 34442 34796 +354
===========================================
Hits 22343 22343
- Misses 11071 11425 +354
Partials 1028 1028
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (4)
zetaclient/chains/ton/rpc/types.go (1)
116-127: Consider using a more flexible request ID generation strategy.The hardcoded ID "1" in
newRPCRequestcould cause issues with concurrent requests or request tracking.Consider generating unique request IDs:
+import ( + "strconv" + "sync/atomic" +) + +var requestCounter int64 + func newRPCRequest(method string, params map[string]any) rpcRequest { if params == nil { params = make(map[string]any) } + id := atomic.AddInt64(&requestCounter, 1) return rpcRequest{ Jsonrpc: "2.0", - ID: "1", + ID: strconv.FormatInt(id, 10), Method: method, Params: params, } }zetaclient/chains/ton/rpc/client.go (3)
78-92: Consider implementing caching for block headers.The TODO comment correctly identifies an optimization opportunity. Block headers are immutable once finalized, making them ideal candidates for caching.
Would you like me to implement a simple LRU cache for block headers to improve performance?
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 78-91: zetaclient/chains/ton/rpc/client.go#L78-L91
Added lines #L78 - L91 were not covered by tests
322-322: Fix typo in comment.- // Not we take the latest item in the list (oldest tx in the page) + // Note we take the latest item in the list (oldest tx in the page)
346-349: Verify response code parsing in SendMessage.The TODO indicates uncertainty about response parsing. The current implementation may not handle all response scenarios correctly.
Please verify the response handling during e2e testing and ensure all status codes are properly parsed and returned.
Would you like me to research the toncenter API documentation to determine the correct response parsing approach?
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
changelog.md(1 hunks)contrib/localnet/docker-compose.yml(1 hunks)zetaclient/chains/ton/rpc/client.go(1 hunks)zetaclient/chains/ton/rpc/client_live_test.go(1 hunks)zetaclient/chains/ton/rpc/types.go(1 hunks)zetaclient/common/env.go(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
**/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
zetaclient/common/env.gozetaclient/chains/ton/rpc/client_live_test.gozetaclient/chains/ton/rpc/types.gozetaclient/chains/ton/rpc/client.go
🪛 GitHub Check: codecov/patch
zetaclient/chains/ton/rpc/client.go
[warning] 37-38: zetaclient/chains/ton/rpc/client.go#L37-L38
Added lines #L37 - L38 were not covered by tests
[warning] 45-65: zetaclient/chains/ton/rpc/client.go#L45-L65
Added lines #L45 - L65 were not covered by tests
[warning] 67-67: zetaclient/chains/ton/rpc/client.go#L67
Added line #L67 was not covered by tests
[warning] 70-75: zetaclient/chains/ton/rpc/client.go#L70-L75
Added lines #L70 - L75 were not covered by tests
[warning] 78-91: zetaclient/chains/ton/rpc/client.go#L78-L91
Added lines #L78 - L91 were not covered by tests
[warning] 94-98: zetaclient/chains/ton/rpc/client.go#L94-L98
Added lines #L94 - L98 were not covered by tests
[warning] 100-103: zetaclient/chains/ton/rpc/client.go#L100-L103
Added lines #L100 - L103 were not covered by tests
[warning] 105-107: zetaclient/chains/ton/rpc/client.go#L105-L107
Added lines #L105 - L107 were not covered by tests
[warning] 110-119: zetaclient/chains/ton/rpc/client.go#L110-L119
Added lines #L110 - L119 were not covered by tests
[warning] 123-127: zetaclient/chains/ton/rpc/client.go#L123-L127
Added lines #L123 - L127 were not covered by tests
[warning] 129-131: zetaclient/chains/ton/rpc/client.go#L129-L131
Added lines #L129 - L131 were not covered by tests
[warning] 133-133: zetaclient/chains/ton/rpc/client.go#L133
Added line #L133 was not covered by tests
[warning] 136-144: zetaclient/chains/ton/rpc/client.go#L136-L144
Added lines #L136 - L144 were not covered by tests
[warning] 146-149: zetaclient/chains/ton/rpc/client.go#L146-L149
Added lines #L146 - L149 were not covered by tests
[warning] 151-159: zetaclient/chains/ton/rpc/client.go#L151-L159
Added lines #L151 - L159 were not covered by tests
[warning] 169-177: zetaclient/chains/ton/rpc/client.go#L169-L177
Added lines #L169 - L177 were not covered by tests
[warning] 179-181: zetaclient/chains/ton/rpc/client.go#L179-L181
Added lines #L179 - L181 were not covered by tests
[warning] 187-190: zetaclient/chains/ton/rpc/client.go#L187-L190
Added lines #L187 - L190 were not covered by tests
[warning] 193-196: zetaclient/chains/ton/rpc/client.go#L193-L196
Added lines #L193 - L196 were not covered by tests
[warning] 198-204: zetaclient/chains/ton/rpc/client.go#L198-L204
Added lines #L198 - L204 were not covered by tests
[warning] 206-206: zetaclient/chains/ton/rpc/client.go#L206
Added line #L206 was not covered by tests
[warning] 209-209: zetaclient/chains/ton/rpc/client.go#L209
Added line #L209 was not covered by tests
[warning] 217-221: zetaclient/chains/ton/rpc/client.go#L217-L221
Added lines #L217 - L221 were not covered by tests
[warning] 223-225: zetaclient/chains/ton/rpc/client.go#L223-L225
Added lines #L223 - L225 were not covered by tests
[warning] 227-227: zetaclient/chains/ton/rpc/client.go#L227
Added line #L227 was not covered by tests
[warning] 237-241: zetaclient/chains/ton/rpc/client.go#L237-L241
Added lines #L237 - L241 were not covered by tests
[warning] 243-249: zetaclient/chains/ton/rpc/client.go#L243-L249
Added lines #L243 - L249 were not covered by tests
[warning] 252-260: zetaclient/chains/ton/rpc/client.go#L252-L260
Added lines #L252 - L260 were not covered by tests
[warning] 262-263: zetaclient/chains/ton/rpc/client.go#L262-L263
Added lines #L262 - L263 were not covered by tests
[warning] 266-269: zetaclient/chains/ton/rpc/client.go#L266-L269
Added lines #L266 - L269 were not covered by tests
🔇 Additional comments (6)
zetaclient/common/env.go (1)
18-18: LGTM: Clean constant addition following established patterns.The new
EnvTONRPCconstant follows the existing naming convention and maintains consistency with other environment variable definitions in the file.contrib/localnet/docker-compose.yml (1)
283-283: LGTM: Appropriate configuration for enabling TON RPC.The addition of
ENABLE_RPC: trueproperly enables RPC functionality for the TON service in the local testing environment, supporting the new HTTP-RPC client implementation.zetaclient/chains/ton/rpc/types.go (1)
97-107: LGTM: Well-structured base64 BOC unmarshaling with proper error handling.The
unmarshalFromBase64function demonstrates good error handling practices and follows Go conventions for utility functions.changelog.md (1)
32-32: LGTM: Proper documentation of the new TON HTTP-RPC feature.The changelog entry appropriately documents the new feature with the correct PR reference, maintaining consistency with the existing documentation format.
zetaclient/chains/ton/rpc/client_live_test.go (1)
18-144: Well-structured integration tests with comprehensive coverage.The test suite effectively validates the HTTP-RPC client functionality against a live endpoint. The tests cover all major client methods and include proper assertions for both successful and edge cases.
zetaclient/chains/ton/rpc/client.go (1)
43-68: Clean constructor implementation with sensible defaults.The functional options pattern and automatic endpoint normalization are well-implemented. The comment clearly explains the URL handling logic.
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 45-65: zetaclient/chains/ton/rpc/client.go#L45-L65
Added lines #L45 - L65 were not covered by tests
[warning] 67-67: zetaclient/chains/ton/rpc/client.go#L67
Added line #L67 was not covered by tests
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (7)
zetaclient/chains/ton/rpc/client_live_test.go (2)
28-28: Consider documenting the hardcoded gateway account.The hardcoded testnet gateway account should be documented to explain its purpose and ensure it remains valid for testing.
+// TON testnet gateway account used for live testing gatewayTestnet := ton.MustParseAccountID("EQB6TUFJZyaq2yJ89NMTyVkS8f5sx0LBjr3jBv9ZiB2IFjrk")
96-96: Consider adding error case testing for invalid parameters.While the current tests cover successful scenarios, consider adding test cases for error conditions such as invalid account IDs or network failures to ensure robust error handling.
t.Run("GetTransactions_InvalidAccount", func(t *testing.T) { // Test with malformed account ID invalidID := ton.MustParseAccountID("0:0000000000000000000000000000000000000000000000000000000000000000") txs, err := client.GetTransactions(ctx, 10, invalidID, 0, ton.Bits256{}) // Validate error handling behavior require.NoError(t, err) // or require.Error depending on expected behavior })zetaclient/chains/ton/rpc/types.go (1)
73-83: Consider more robust state parsing.The current approach using
strings.Containsfor state determination could be fragile and match unintended values. Consider using exact string matching or a more structured approach.Apply this more robust implementation:
- switch { - case ltRaw == "0" && strings.Contains(stateRaw, "uninit"): - acc.Status = tlb.AccountNone - return nil - case strings.Contains(stateRaw, "uninit"): - acc.Status = tlb.AccountUninit - case stateRaw == "raw.accountState": - acc.Status = tlb.AccountActive - case frozenHashRaw != "": - acc.Status = tlb.AccountFrozen - } + switch stateRaw { + case "wallet.accountState.walletStateUninit", "wallet.accountState.walletV3StateUninit": + if ltRaw == "0" { + acc.Status = tlb.AccountNone + return nil + } + acc.Status = tlb.AccountUninit + case "raw.accountState": + acc.Status = tlb.AccountActive + case "raw.frozenAccountState": + acc.Status = tlb.AccountFrozen + default: + // Handle any unexpected states + if strings.Contains(stateRaw, "uninit") && ltRaw == "0" { + acc.Status = tlb.AccountNone + return nil + } + return errors.Errorf("unexpected account state: %s", stateRaw) + }zetaclient/chains/ton/rpc/client.go (4)
48-53: Document the automatic URL path modification.The constructor automatically appends
/jsonRPCto the endpoint URL. While this is helpful, it should be clearly documented in the function comment to avoid confusion.Add documentation above the
Newfunction:// New Client constructor // The endpoint URL will be automatically modified to append "/jsonRPC" if not present. // To enable generic client metrics, use WithHTTPClient() + metrics.GetInstrumentedHTTPClient()
78-79: Address the caching TODO for immutable data.Block headers are immutable once created and would benefit from caching to reduce RPC calls.
Would you like me to implement a simple LRU cache for block headers or create an issue to track this optimization?
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 78-91: zetaclient/chains/ton/rpc/client.go#L78-L91
Added lines #L78 - L91 were not covered by tests
146-160: Consider reusing the unmarshalFromBase64 helper.The cell deserialization logic here duplicates similar code. Consider using the existing
unmarshalFromBase64function for consistency.- cells, err := boc.DeserializeBocBase64(rawBase64) - - switch { - case err != nil: - return nil, errors.Wrapf(err, "unable to deserialize boc from %q", rawBase64) - case len(cells) == 0: - return nil, errors.Errorf("expected at least one cell, got 0") - default: - return cells[0], nil - } + var cell *boc.Cell + // We can't use unmarshalFromBase64 directly as it expects a TLB-unmarshalable type + cells, err := boc.DeserializeBocBase64(rawBase64) + if err != nil { + return nil, errors.Wrapf(err, "unable to deserialize boc from %q", rawBase64) + } + if len(cells) == 0 { + return nil, errors.Errorf("expected at least one cell, got 0") + } + return cells[0], nil🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 146-149: zetaclient/chains/ton/rpc/client.go#L146-L149
Added lines #L146 - L149 were not covered by tests
[warning] 151-159: zetaclient/chains/ton/rpc/client.go#L151-L159
Added lines #L151 - L159 were not covered by tests
320-322: Fix typo in comment.- // Not we take the latest item in the list (oldest tx in the page) + // Now we take the latest item in the list (oldest tx in the page)
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
changelog.md(1 hunks)contrib/localnet/docker-compose.yml(1 hunks)zetaclient/chains/ton/rpc/client.go(1 hunks)zetaclient/chains/ton/rpc/client_live_test.go(1 hunks)zetaclient/chains/ton/rpc/types.go(1 hunks)zetaclient/common/env.go(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
**/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
zetaclient/common/env.gozetaclient/chains/ton/rpc/client_live_test.gozetaclient/chains/ton/rpc/types.gozetaclient/chains/ton/rpc/client.go
🪛 GitHub Check: codecov/patch
zetaclient/chains/ton/rpc/client.go
[warning] 37-38: zetaclient/chains/ton/rpc/client.go#L37-L38
Added lines #L37 - L38 were not covered by tests
[warning] 45-65: zetaclient/chains/ton/rpc/client.go#L45-L65
Added lines #L45 - L65 were not covered by tests
[warning] 67-67: zetaclient/chains/ton/rpc/client.go#L67
Added line #L67 was not covered by tests
[warning] 70-75: zetaclient/chains/ton/rpc/client.go#L70-L75
Added lines #L70 - L75 were not covered by tests
[warning] 78-91: zetaclient/chains/ton/rpc/client.go#L78-L91
Added lines #L78 - L91 were not covered by tests
[warning] 94-98: zetaclient/chains/ton/rpc/client.go#L94-L98
Added lines #L94 - L98 were not covered by tests
[warning] 100-103: zetaclient/chains/ton/rpc/client.go#L100-L103
Added lines #L100 - L103 were not covered by tests
[warning] 105-107: zetaclient/chains/ton/rpc/client.go#L105-L107
Added lines #L105 - L107 were not covered by tests
[warning] 110-119: zetaclient/chains/ton/rpc/client.go#L110-L119
Added lines #L110 - L119 were not covered by tests
[warning] 123-127: zetaclient/chains/ton/rpc/client.go#L123-L127
Added lines #L123 - L127 were not covered by tests
[warning] 129-131: zetaclient/chains/ton/rpc/client.go#L129-L131
Added lines #L129 - L131 were not covered by tests
[warning] 133-133: zetaclient/chains/ton/rpc/client.go#L133
Added line #L133 was not covered by tests
[warning] 136-144: zetaclient/chains/ton/rpc/client.go#L136-L144
Added lines #L136 - L144 were not covered by tests
[warning] 146-149: zetaclient/chains/ton/rpc/client.go#L146-L149
Added lines #L146 - L149 were not covered by tests
[warning] 151-159: zetaclient/chains/ton/rpc/client.go#L151-L159
Added lines #L151 - L159 were not covered by tests
[warning] 169-177: zetaclient/chains/ton/rpc/client.go#L169-L177
Added lines #L169 - L177 were not covered by tests
[warning] 179-181: zetaclient/chains/ton/rpc/client.go#L179-L181
Added lines #L179 - L181 were not covered by tests
[warning] 187-190: zetaclient/chains/ton/rpc/client.go#L187-L190
Added lines #L187 - L190 were not covered by tests
[warning] 193-196: zetaclient/chains/ton/rpc/client.go#L193-L196
Added lines #L193 - L196 were not covered by tests
[warning] 198-204: zetaclient/chains/ton/rpc/client.go#L198-L204
Added lines #L198 - L204 were not covered by tests
[warning] 206-206: zetaclient/chains/ton/rpc/client.go#L206
Added line #L206 was not covered by tests
[warning] 209-209: zetaclient/chains/ton/rpc/client.go#L209
Added line #L209 was not covered by tests
[warning] 217-221: zetaclient/chains/ton/rpc/client.go#L217-L221
Added lines #L217 - L221 were not covered by tests
[warning] 223-225: zetaclient/chains/ton/rpc/client.go#L223-L225
Added lines #L223 - L225 were not covered by tests
[warning] 227-227: zetaclient/chains/ton/rpc/client.go#L227
Added line #L227 was not covered by tests
[warning] 237-241: zetaclient/chains/ton/rpc/client.go#L237-L241
Added lines #L237 - L241 were not covered by tests
[warning] 243-249: zetaclient/chains/ton/rpc/client.go#L243-L249
Added lines #L243 - L249 were not covered by tests
[warning] 252-260: zetaclient/chains/ton/rpc/client.go#L252-L260
Added lines #L252 - L260 were not covered by tests
[warning] 262-263: zetaclient/chains/ton/rpc/client.go#L262-L263
Added lines #L262 - L263 were not covered by tests
[warning] 266-269: zetaclient/chains/ton/rpc/client.go#L266-L269
Added lines #L266 - L269 were not covered by tests
🔇 Additional comments (15)
zetaclient/common/env.go (1)
18-18: LGTM: Clean environment variable constant addition.The
EnvTONRPCconstant follows the established naming convention and pattern used by other environment variables in this package.changelog.md (1)
32-32: LGTM: Proper changelog documentation.The changelog entry correctly documents the new TON HTTP-RPC feature and follows the established format.
contrib/localnet/docker-compose.yml (1)
283-283: LGTM: Appropriate Docker configuration for TON RPC enablement.The
ENABLE_RPC: trueenvironment variable correctly enables RPC functionality for the TON service in the localnet setup, supporting the new HTTP-RPC client implementation.zetaclient/chains/ton/rpc/client_live_test.go (4)
18-32: Well-structured test setup with proper conditional execution.The test setup correctly uses environment variables for conditional execution and endpoint configuration. The fallback to testnet endpoint is appropriate for live testing.
44-74: Comprehensive account state testing with both positive and negative cases.The test properly validates both existing and non-existing accounts, ensuring correct behavior for different account states. The assertions are thorough and appropriate.
105-142: Well-designed pagination test with proper validation.The
GetTransactionsSincetest demonstrates good test design with clear arrange/act/assert structure and validates both the ordering logic and pagination behavior. The assertions ensure data consistency between different query methods.
146-161: Clean helper functions for test output formatting.The
printTxandsimplifyTxhelper functions provide clean abstractions for test logging and debugging, making the test output more readable and maintainable.zetaclient/chains/ton/rpc/types.go (4)
1-15: Imports and package declaration look good.The package structure and imports are well-organized and appropriate for the TON RPC client implementation.
17-40: Type definitions are well-structured.The struct definitions properly represent TON blockchain entities with appropriate field types and JSON tags.
69-71: Clarify the special balance value "-1".The check for
balanceRaw != "-1"appears to handle a special case. Please add a comment explaining when the API returns "-1" as a balance value and what it signifies.
96-143: Helper functions and RPC types are well-implemented.The
unmarshalFromBase64function has proper error handling, and the RPC request/response types correctly implement JSON-RPC 2.0 specification.zetaclient/chains/ton/rpc/client.go (4)
1-42: Package structure and client definition are well-organized.Good documentation with reference links to the toncenter API specifications. The client struct is simple and focused.
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 37-38: zetaclient/chains/ton/rpc/client.go#L37-L38
Added lines #L37 - L38 were not covered by tests
232-288: Efficient implementation of transaction pagination.The use of
deferto reverse the results and the clear pagination logic make this method easy to understand and maintain. Good handling of the edge case when the target transaction is found.🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 237-241: zetaclient/chains/ton/rpc/client.go#L237-L241
Added lines #L237 - L241 were not covered by tests
[warning] 243-249: zetaclient/chains/ton/rpc/client.go#L243-L249
Added lines #L243 - L249 were not covered by tests
[warning] 252-260: zetaclient/chains/ton/rpc/client.go#L252-L260
Added lines #L252 - L260 were not covered by tests
[warning] 262-263: zetaclient/chains/ton/rpc/client.go#L262-L263
Added lines #L262 - L263 were not covered by tests
[warning] 266-269: zetaclient/chains/ton/rpc/client.go#L266-L269
Added lines #L266 - L269 were not covered by tests
332-390: Clean abstraction for RPC calls.The
SendMessage,callAndUnmarshal, andcallmethods provide a well-structured abstraction layer for RPC communication with consistent error handling.
392-441: Robust HTTP handling and metrics implementation.The HTTP request handling follows best practices with proper resource cleanup and comprehensive error handling. The metrics collection appropriately tracks both success/failure status and request duration.
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (7)
zetaclient/chains/ton/rpc/types.go (1)
116-127: Consider making RPC request parameters more configurable.The hardcoded JSON-RPC version and ID values may limit flexibility for different use cases.
Consider parameterizing these values:
-func newRPCRequest(method string, params map[string]any) rpcRequest { +func newRPCRequest(method string, params map[string]any) rpcRequest { + return newRPCRequestWithID(method, params, "1") +} + +func newRPCRequestWithID(method string, params map[string]any, id string) rpcRequest { if params == nil { params = make(map[string]any) } return rpcRequest{ Jsonrpc: "2.0", - ID: "1", + ID: id, Method: method, Params: params, } }This would allow for request tracking and potential concurrent request handling.
zetaclient/chains/ton/rpc/client_live_test.go (1)
28-28: Consider making the test account configurable.The hard-coded test account could become problematic if its state changes on the testnet. Consider making it configurable via an environment variable with this address as the default.
-gatewayTestnet := ton.MustParseAccountID("EQB6TUFJZyaq2yJ89NMTyVkS8f5sx0LBjr3jBv9ZiB2IFjrk") +testAccount := os.Getenv("TON_TEST_ACCOUNT") +if testAccount == "" { + testAccount = "EQB6TUFJZyaq2yJ89NMTyVkS8f5sx0LBjr3jBv9ZiB2IFjrk" +} +gatewayTestnet := ton.MustParseAccountID(testAccount)zetaclient/chains/ton/rpc/client.go (5)
43-68: Document the automatic endpoint modification.The constructor automatically appends
/jsonRPCto the endpoint URL. While convenient, this behavior should be clearly documented in the function comment to avoid confusion.// New Client constructor // To enable generic client metrics, use WithHTTPClient() + metrics.GetInstrumentedHTTPClient() +// Note: The endpoint URL will automatically have "/jsonRPC" appended to it. func New(endpoint string, chainID int64, opts ...Opt) *Client {🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 45-65: zetaclient/chains/ton/rpc/client.go#L45-L65
Added lines #L45 - L65 were not covered by tests
[warning] 67-67: zetaclient/chains/ton/rpc/client.go#L67
Added line #L67 was not covered by tests
79-79: Address the caching TODO.Block headers are immutable once finalized, making them excellent candidates for caching to reduce API calls.
Would you like me to implement a caching layer for block headers or create an issue to track this optimization?
183-185: Consider implementing archival node support.The TODO comment indicates missing support for archival nodes, which is essential for accessing historical transactions beyond the lite server's retention period.
Would you like me to implement archival node support by adding an
archivalparameter to the RPC request?
230-288: Elegant handling of transaction ordering.The implementation correctly transforms the API's reverse chronological order into chronological order. Consider adding a comment explaining the pagination logic for future maintainers.
func (c *Client) GetTransactionsSince( ctx context.Context, acc ton.AccountID, oldestLT uint64, oldestHash ton.Bits256, ) (txs []ton.Transaction, err error) { + // The TON API returns transactions in reverse chronological order (newest first). + // This method reverses that to return transactions in chronological order (oldest first). lt, hash, err := c.getLastTransactionHash(ctx, acc)🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 237-241: zetaclient/chains/ton/rpc/client.go#L237-L241
Added lines #L237 - L241 were not covered by tests
[warning] 243-249: zetaclient/chains/ton/rpc/client.go#L243-L249
Added lines #L243 - L249 were not covered by tests
[warning] 252-260: zetaclient/chains/ton/rpc/client.go#L252-L260
Added lines #L252 - L260 were not covered by tests
[warning] 262-263: zetaclient/chains/ton/rpc/client.go#L262-L263
Added lines #L262 - L263 were not covered by tests
[warning] 266-269: zetaclient/chains/ton/rpc/client.go#L266-L269
Added lines #L266 - L269 were not covered by tests
346-348: Complete the response parsing implementation.The TODO comments indicate that response parsing needs to be explored during e2e testing. This should be addressed to ensure proper error handling.
Would you like me to research the toncenter API response format and implement proper response code parsing?
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
changelog.md(1 hunks)contrib/localnet/docker-compose.yml(1 hunks)zetaclient/chains/ton/rpc/client.go(1 hunks)zetaclient/chains/ton/rpc/client_live_test.go(1 hunks)zetaclient/chains/ton/rpc/types.go(1 hunks)zetaclient/common/env.go(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
**/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
zetaclient/common/env.gozetaclient/chains/ton/rpc/types.gozetaclient/chains/ton/rpc/client_live_test.gozetaclient/chains/ton/rpc/client.go
🪛 GitHub Check: codecov/patch
zetaclient/chains/ton/rpc/client.go
[warning] 37-38: zetaclient/chains/ton/rpc/client.go#L37-L38
Added lines #L37 - L38 were not covered by tests
[warning] 45-65: zetaclient/chains/ton/rpc/client.go#L45-L65
Added lines #L45 - L65 were not covered by tests
[warning] 67-67: zetaclient/chains/ton/rpc/client.go#L67
Added line #L67 was not covered by tests
[warning] 70-75: zetaclient/chains/ton/rpc/client.go#L70-L75
Added lines #L70 - L75 were not covered by tests
[warning] 78-91: zetaclient/chains/ton/rpc/client.go#L78-L91
Added lines #L78 - L91 were not covered by tests
[warning] 94-98: zetaclient/chains/ton/rpc/client.go#L94-L98
Added lines #L94 - L98 were not covered by tests
[warning] 100-103: zetaclient/chains/ton/rpc/client.go#L100-L103
Added lines #L100 - L103 were not covered by tests
[warning] 105-107: zetaclient/chains/ton/rpc/client.go#L105-L107
Added lines #L105 - L107 were not covered by tests
[warning] 110-119: zetaclient/chains/ton/rpc/client.go#L110-L119
Added lines #L110 - L119 were not covered by tests
[warning] 123-127: zetaclient/chains/ton/rpc/client.go#L123-L127
Added lines #L123 - L127 were not covered by tests
[warning] 129-131: zetaclient/chains/ton/rpc/client.go#L129-L131
Added lines #L129 - L131 were not covered by tests
[warning] 133-133: zetaclient/chains/ton/rpc/client.go#L133
Added line #L133 was not covered by tests
[warning] 136-144: zetaclient/chains/ton/rpc/client.go#L136-L144
Added lines #L136 - L144 were not covered by tests
[warning] 146-149: zetaclient/chains/ton/rpc/client.go#L146-L149
Added lines #L146 - L149 were not covered by tests
[warning] 151-159: zetaclient/chains/ton/rpc/client.go#L151-L159
Added lines #L151 - L159 were not covered by tests
[warning] 169-177: zetaclient/chains/ton/rpc/client.go#L169-L177
Added lines #L169 - L177 were not covered by tests
[warning] 179-181: zetaclient/chains/ton/rpc/client.go#L179-L181
Added lines #L179 - L181 were not covered by tests
[warning] 187-190: zetaclient/chains/ton/rpc/client.go#L187-L190
Added lines #L187 - L190 were not covered by tests
[warning] 193-196: zetaclient/chains/ton/rpc/client.go#L193-L196
Added lines #L193 - L196 were not covered by tests
[warning] 198-204: zetaclient/chains/ton/rpc/client.go#L198-L204
Added lines #L198 - L204 were not covered by tests
[warning] 206-206: zetaclient/chains/ton/rpc/client.go#L206
Added line #L206 was not covered by tests
[warning] 209-209: zetaclient/chains/ton/rpc/client.go#L209
Added line #L209 was not covered by tests
[warning] 217-221: zetaclient/chains/ton/rpc/client.go#L217-L221
Added lines #L217 - L221 were not covered by tests
[warning] 223-225: zetaclient/chains/ton/rpc/client.go#L223-L225
Added lines #L223 - L225 were not covered by tests
[warning] 227-227: zetaclient/chains/ton/rpc/client.go#L227
Added line #L227 was not covered by tests
[warning] 237-241: zetaclient/chains/ton/rpc/client.go#L237-L241
Added lines #L237 - L241 were not covered by tests
[warning] 243-249: zetaclient/chains/ton/rpc/client.go#L243-L249
Added lines #L243 - L249 were not covered by tests
[warning] 252-260: zetaclient/chains/ton/rpc/client.go#L252-L260
Added lines #L252 - L260 were not covered by tests
[warning] 262-263: zetaclient/chains/ton/rpc/client.go#L262-L263
Added lines #L262 - L263 were not covered by tests
[warning] 266-269: zetaclient/chains/ton/rpc/client.go#L266-L269
Added lines #L266 - L269 were not covered by tests
🔇 Additional comments (13)
zetaclient/common/env.go (1)
18-18: LGTM! Environment variable constant follows established patterns.The constant naming and placement are consistent with existing code standards.
changelog.md (1)
32-32: LGTM! Changelog entry properly documents the new feature.The entry follows the established format and includes the appropriate PR reference.
contrib/localnet/docker-compose.yml (1)
283-283: LGTM! Environment variable enables the new TON RPC functionality.The configuration change correctly enables RPC support for local development testing.
zetaclient/chains/ton/rpc/types.go (3)
1-15: LGTM! Package structure and imports are well-organized.The imports are appropriate for TON blockchain interaction with proper use of external libraries for JSON parsing and TON-specific operations.
17-40: LGTM! Struct definitions are clean and well-structured.The type definitions appropriately represent TON blockchain entities with proper JSON tags and type safety.
129-143: LGTM! Request serialization and response structure are well-implemented.The
asBodymethod properly handles JSON marshaling with appropriate error wrapping, and the response structure correctly maps the expected JSON-RPC response format.zetaclient/chains/ton/rpc/client_live_test.go (4)
34-42: Well-structured health check test.The test appropriately validates the blockchain's liveness by ensuring the latest block time is recent.
44-74: Comprehensive account state testing.Excellent coverage of both active and non-existent account scenarios with appropriate assertions for each case.
105-142: Thorough pagination and ordering validation.The test effectively validates the pagination logic and ensures correct ordering transformation between GetTransactions (DESC) and GetTransactionsSince (ASC).
146-161: Clean helper functions for transaction debugging.The helper functions provide a clean way to log transaction details during test execution.
zetaclient/chains/ton/rpc/client.go (3)
122-134: Proper validation in transaction hash retrieval.Good defensive programming by checking account status before accessing transaction fields.
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 123-127: zetaclient/chains/ton/rpc/client.go#L123-L127
Added lines #L123 - L127 were not covered by tests
[warning] 129-131: zetaclient/chains/ton/rpc/client.go#L129-L131
Added lines #L129 - L131 were not covered by tests
[warning] 133-133: zetaclient/chains/ton/rpc/client.go#L133
Added line #L133 was not covered by tests
136-161: Well-implemented configuration parameter retrieval.The method properly handles BOC deserialization with comprehensive error handling and informative error messages.
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 136-144: zetaclient/chains/ton/rpc/client.go#L136-L144
Added lines #L136 - L144 were not covered by tests
[warning] 146-149: zetaclient/chains/ton/rpc/client.go#L146-L149
Added lines #L146 - L149 were not covered by tests
[warning] 151-159: zetaclient/chains/ton/rpc/client.go#L151-L159
Added lines #L151 - L159 were not covered by tests
391-429: Well-structured RPC request handling.The method properly constructs HTTP requests, handles responses, and ensures resource cleanup with deferred body closure.
* Add TON HTTP-RPC client skeleton * RPC WIP [1] * RPC WIP [2] * RPC WIP [3] * Metrics note * Record metrics * Update changelog
* feat: migrate to golangci-lint v2 (#3960) * Migrate linter to V2 * Apply lint * Improve makefile * feat(ton): Implement HTTP-RPC based on toncenter v2 (#3929) * Add TON HTTP-RPC client skeleton * RPC WIP [1] * RPC WIP [2] * RPC WIP [3] * Metrics note * Record metrics * Update changelog * feat(zetaclient): integrate TON HTTP-RPC (#3958) * Refactor observer; refactor mocks * Fix signer & unit tests * Drop liteapi * Restore tx hash conversion aliases * Fix E2E, adapt Tongo x RPC * Update wait-for-ton * Move tlb to rpc package * fix e2e tests; simplify ensureLastScannedTx; fix client * rename .rpc to .Endpoint in config * Simplify config * Update changelog * lint * Address PR comments * PR fixes * fix merge conflict * bump linter timeout * use ton localnet v2 * bump ton localnet * bump ton localnet * Bump changelog
GetMasterchainInfoGetBlockHeaderHealthCheckGetAccountStateGetConfigParamGetTransactionsGetTransactionGetTransactionsSinceGetFirstTransactionSendMessageCloses #3927
Note: This PR implements only the required subset of RPC methods necessary for zetaclient's needs.
Integration of this client will be done in #3928
Summary by CodeRabbit
New Features
Tests
Documentation