diff --git a/hmy/api_backend.go b/hmy/api_backend.go index f87a46a7a..43e922ab0 100644 --- a/hmy/api_backend.go +++ b/hmy/api_backend.go @@ -7,6 +7,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/bloombits" "github.com/ethereum/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rpc" @@ -185,3 +186,8 @@ func (b *APIBackend) GetPoolTransactions() (types.Transactions, error) { } return txs, nil } + +// GetBalance ... +func (b *APIBackend) GetBalance(address common.Address) (*hexutil.Big, error) { + return nil, nil +} diff --git a/hmy/backend.go b/hmy/backend.go index b92b6b3c8..296bc932a 100644 --- a/hmy/backend.go +++ b/hmy/backend.go @@ -1,6 +1,9 @@ package hmy import ( + "math/big" + + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/bloombits" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" @@ -34,6 +37,7 @@ type NodeAPI interface { AddPendingTransaction(newTx *types.Transaction) Blockchain() *core.BlockChain AccountManager() *accounts.Manager + GetBalanceOfAddress(address common.Address) (*big.Int, error) } // New creates a new Harmony object (including the diff --git a/internal/hmyapi/backend.go b/internal/hmyapi/backend.go index 70517e037..ceafa5b99 100644 --- a/internal/hmyapi/backend.go +++ b/internal/hmyapi/backend.go @@ -4,6 +4,7 @@ import ( "context" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/params" @@ -54,6 +55,8 @@ type Backend interface { ChainConfig() *params.ChainConfig CurrentBlock() *types.Block + // Get balance + GetBalance(address common.Address) (*hexutil.Big, error) } // GetAPIs returns all the APIs. diff --git a/internal/hmyapi/blockchain.go b/internal/hmyapi/blockchain.go index 372f6e313..967c6d8d3 100644 --- a/internal/hmyapi/blockchain.go +++ b/internal/hmyapi/blockchain.go @@ -72,11 +72,7 @@ func (s *PublicBlockChainAPI) GetStorageAt(ctx context.Context, address common.A // given block number. The rpc.LatestBlockNumber and rpc.PendingBlockNumber meta // block numbers are also allowed. func (s *PublicBlockChainAPI) GetBalance(ctx context.Context, address common.Address, blockNr rpc.BlockNumber) (*hexutil.Big, error) { - state, _, err := s.b.StateAndHeaderByNumber(ctx, blockNr) - if state == nil || err != nil { - return nil, err - } - return (*hexutil.Big)(state.GetBalance(address)), state.Error() + return s.b.GetBalance(address) } // BlockNumber returns the block number of the chain head.