From 2c03cb6ebddf816f00bbeee2f33d15408d23b29f Mon Sep 17 00:00:00 2001 From: KamiD <44460798+KamiD@users.noreply.github.com> Date: Wed, 18 Aug 2021 11:08:44 +0800 Subject: [PATCH] =?UTF-8?q?Merge=20PR=20=EF=BC=9Afix=20query=20failed=20wh?= =?UTF-8?q?en=20using=20height=20of=20pending=20block=20(#975)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/rpc/namespaces/eth/api.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/rpc/namespaces/eth/api.go b/app/rpc/namespaces/eth/api.go index d91e74f169..f5697768be 100644 --- a/app/rpc/namespaces/eth/api.go +++ b/app/rpc/namespaces/eth/api.go @@ -503,11 +503,15 @@ func (api *PublicEthereumAPI) GetUncleCountByBlockNumber(_ rpctypes.BlockNumber) func (api *PublicEthereumAPI) GetCode(address common.Address, blockNumber rpctypes.BlockNumber) (hexutil.Bytes, error) { monitor := monitor.GetMonitor("eth_getCode", api.logger, api.Metrics).OnBegin() defer monitor.OnEnd("address", address, "block number", blockNumber) - code, err := api.wrappedBackend.GetCode(address, uint64(blockNumber)) + height := blockNumber.Int64() + if blockNumber == rpctypes.PendingBlockNumber || blockNumber == rpctypes.LatestBlockNumber { + height, _ = api.backend.LatestBlockNumber() + } + code, err := api.wrappedBackend.GetCode(address, uint64(height)) if err == nil { return code, nil } - clientCtx := api.clientCtx.WithHeight(blockNumber.Int64()) + clientCtx := api.clientCtx.WithHeight(height) res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/%s/%s", evmtypes.ModuleName, evmtypes.QueryCode, address.Hex()), nil) if err != nil { return nil, err