feat: add support for non infura rpc read calls#1370
Conversation
|
I'm not seeing where eth_accounts and eth_chainId are cached. Both actually shouldn't be callable via wallet_invokeMethod in the first place though |
Good point. We will need to do the caching and expose "simulations" of these methods in our backwards compatibility layer |
| t.it('should redirect to provider for methods in METHODS_TO_REDIRECT', async () => { | ||
| const redirectOptions: InvokeMethodOptions = { | ||
| scope: 'eip155:1' as Scope, | ||
| request: { | ||
| method: RPC_METHODS.ETH_SENDTRANSACTION, | ||
| params: { to: '0x123', value: '0x100' }, | ||
| }, | ||
| }; | ||
| mockTransport.request.mockResolvedValue({ result: '0xhash' }); | ||
| const result = await rpcClient.invokeMethod(redirectOptions); | ||
| t.expect(result).toBe('0xhash'); | ||
| t.expect(mockTransport.request).toHaveBeenCalledWith({ | ||
| method: 'wallet_invokeMethod', | ||
| params: redirectOptions, | ||
| }); | ||
| t.expect(mockFetch).not.toHaveBeenCalled(); |
There was a problem hiding this comment.
should we preserve this test but make it
should redirect to provider for EVM methods not in EVM_RPC_PASSTHROUGH_METHODS ?
There was a problem hiding this comment.
there's one that tests this via personal_sign. Perhaps we just rename that test title?
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1370 +/- ##
=======================================
Coverage 74.99% 74.99%
=======================================
Files 184 184
Lines 4519 4519
Branches 1108 1108
=======================================
Hits 3389 3389
Misses 1130 1130 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…ead-calls # Conflicts: # packages/sdk-multichain/src/domain/multichain/api/constants.ts # packages/sdk-multichain/src/multichain/rpc/client.test.ts # packages/sdk-multichain/src/multichain/rpc/client.ts
| if (SDK_HANDLED_METHODS.has(method)) { | ||
| return this.handleWithSdkState(options); | ||
| } |
There was a problem hiding this comment.
I'm okay leaving this here for now, but we should consider whether to pull this into a separate method since these methods don't technically go through wallet_invokeMethod
|
|
Going to wait for new monorepo and then migrate these changes over |
|
closed in favor of MetaMask/connect-monorepo#7 |



Explanation
RPC_URLS_MAPtoRpcUrlsMapapi.readonlyRPCMapentries over built in infura endpoint entriesRpcClienttoRequestRouterRpcClientand move rpc node request logic thereMissingRpcEndpointErrfromRpcClientwhen no endpoint exists for target scopeRpcClientis unable to serve the requestReferences
See: https://consensyssoftware.atlassian.net/browse/WAPI-780
Checklist
Note
Adds a RequestRouter and RpcClient to handle readonly RPC methods via configured RPC endpoints (favoring custom map over Infura), renames RPC_URLS_MAP to RpcUrlsMap, and updates tests accordingly.
RequestRouterto dispatch RPC calls: routesRPC_HANDLED_METHODSto RPC nodes,SDK_HANDLED_METHODSto SDK (placeholder), others to wallet; falls back to wallet if no RPC endpoint.RpcClientto perform JSON-RPC over HTTP to endpoints derived fromapi.readonlyRPCMap(preferred) and Infura viagetInfuraRpcUrls.MultichainSDK.invokeMethodnow usesRequestRouter+RpcClientinstead ofRPCClient.RPC_URLS_MAP->RpcUrlsMapand keys byCaipChainId; updates usages inconstants,infura, andMultichainOptions.RPC_HANDLED_METHODSandSDK_HANDLED_METHODSinapi/constants.rpc/client.testwith newrpc/handlers/rpcClient.testand addsrpc/requestRouter.test; updatesinvoke.testto useRequestRouter.Written by Cursor Bugbot for commit 9fdc2bb. This will update automatically on new commits. Configure here.