Skip to content

Commit

Permalink
accounts,ethclient,internal,mobile: add eth api to get mru number (et…
Browse files Browse the repository at this point in the history
…hereum#250) (ethereum#251)

* accounts,ethclient,internal,mobile: add eth api to get mru number

* internal: use github.com/kevinburke/go-bindata
  • Loading branch information
hadv authored Jul 16, 2019
1 parent e7037ac commit b6e070b
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 14 deletions.
11 changes: 11 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,17 @@ func (s *PublicBlockChainAPI) GetBalance(ctx context.Context, address common.Add
return (*hexutil.Big)(state.GetBalance(address)), state.Error()
}

// GetMRUNumber returns the most recent used blocknumber for the given address in the state of the
// given block number. The rpc.LatestBlockNumber and rpc.PendingBlockNumber meta
// block numbers are also allowed.
func (s *PublicBlockChainAPI) GetMRUNumber(ctx context.Context, address common.Address, blockNr rpc.BlockNumber) (uint64, error) {
state, _, err := s.b.StateAndHeaderByNumber(ctx, blockNr)
if state == nil || err != nil {
return 0, err
}
return state.GetMRUNumber(address), state.Error()
}

// Result structs for GetProof
type AccountResult struct {
Address common.Address `json:"address"`
Expand Down
69 changes: 55 additions & 14 deletions internal/jsre/deps/bindata.go

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions internal/jsre/deps/web3.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions mobile/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,17 @@ func (ec *EthereumClient) GetNonceAt(ctx *Context, account *Address, number int6
return int64(rawNonce), err
}

// GetMRUNumberAt returns the last recent used block number of the given account.
// The block number can be <0, in which case the nonce is taken from the latest known block.
func (ec *EthereumClient) GetMRUNumberAt(ctx *Context, account *Address, number int64) (nonce int64, _ error) {
if number < 0 {
rawNumber, err := ec.client.MRUNumberAt(ctx.context, account.address, nil)
return int64(rawNumber), err
}
rawNumber, err := ec.client.MRUNumberAt(ctx.context, account.address, big.NewInt(number))
return int64(rawNumber), err
}

// Filters

// FilterLogs executes a filter query.
Expand Down

0 comments on commit b6e070b

Please sign in to comment.