From 8c69c5b31da2f58e193bf8da5736dc67fa9205a6 Mon Sep 17 00:00:00 2001 From: KonradStaniec Date: Wed, 28 Sep 2022 22:43:10 +0200 Subject: [PATCH] Proxy missing methods (#1246) --- lc_proxy/rpc/rpc_eth_lc_api.nim | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/lc_proxy/rpc/rpc_eth_lc_api.nim b/lc_proxy/rpc/rpc_eth_lc_api.nim index 9ace14977..16007f620 100644 --- a/lc_proxy/rpc/rpc_eth_lc_api.nim +++ b/lc_proxy/rpc/rpc_eth_lc_api.nim @@ -168,15 +168,40 @@ proc installEthApiHandlers*(lcProxy: LightClientRpcProxy) = else: raise newException(ValueError, dataResult.error) + lcProxy.proxy.rpc("eth_getTransactionCount") do(address: Address, quantityTag: string) -> HexQuantityStr: + let + executionPayload = lcProxy.getPayloadByTag(quantityTag) + blockNumber = executionPayload.blockNumber.uint64 + + info "Forwarding eth_getTransactionCount", executionBn = blockNumber + + let proof = await lcProxy.rpcClient.eth_getProof(address, @[], blockId(blockNumber)) + + let accountResult = getAccountFromProof( + executionPayload.stateRoot, + proof.address, + proof.balance, + proof.nonce, + proof.codeHash, + proof.storageHash, + proof.accountProof + ) + + if accountResult.isOk(): + return hexQuantityStr(encodeQuantity(accountResult.get.nonce)) + else: + raise newException(ValueError, accountResult.error) + # TODO This methods are forwarded directly to provider therefore thay are not # validated in any way lcProxy.proxy.registerProxyMethod("net_version") lcProxy.proxy.registerProxyMethod("eth_call") + lcProxy.proxy.registerProxyMethod("eth_sendRawTransaction") + lcProxy.proxy.registerProxyMethod("eth_getTransactionReceipt") - # TODO cache blocks received from light client, and respond using them in this - # call. It would also enable handling of numerical `quantityTag` for the - # set of cached blocks + # TODO Respond to this calls using BlockCache lcProxy.proxy.registerProxyMethod("eth_getBlockByNumber") + lcProxy.proxy.registerProxyMethod("eth_getBlockByHash") proc new*( T: type LightClientRpcProxy,