add get balance for rpc api

pull/919/head
Minh Doan 6 years ago committed by Minh Doan
parent 0209277255
commit dc1f95a725
  1. 6
      hmy/api_backend.go
  2. 4
      hmy/backend.go
  3. 3
      internal/hmyapi/backend.go
  4. 6
      internal/hmyapi/blockchain.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
}

@ -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

@ -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.

@ -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.

Loading…
Cancel
Save