Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

fix truffle migrate issue, return 0 nonce if account doesn't exist #345

Merged
merged 4 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

* (rpc) [\#305](https://github.com/ChainSafe/ethermint/issues/305) Update eth_getTransactionCount to check for account existence before getting sequence and return 0 as the nonce if it doesn't exist.
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
* (rpc) [\#231](https://github.com/ChainSafe/ethermint/issues/231) Implement NewBlockFilter in rpc/filters.go which instantiates a polling block filter
* Polls for new blocks via BlockNumber rpc call; if block number changes, it requests the new block via GetBlockByNumber rpc call and adds it to its internal list of blocks
* Update uninstallFilter and getFilterChanges accordingly
Expand Down
14 changes: 13 additions & 1 deletion rpc/eth_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ func (e *PublicEthAPI) GetTransactionCount(address common.Address, blockNum Bloc
authclient.Codec = codec.NewAppCodec(ctx.Codec)
accRet := authtypes.NewAccountRetriever(authclient.Codec, ctx)

err := accRet.EnsureExists(from)
if err != nil {
// account doesn't exist yet, return 0
n := hexutil.Uint64(0)
return &n, nil
}

_, nonce, err := accRet.GetAccountNumberSequence(from)
if err != nil {
return nil, err
Expand Down Expand Up @@ -415,7 +422,6 @@ type account struct {
func (e *PublicEthAPI) doCall(
args CallArgs, blockNr rpc.BlockNumber, globalGasCap *big.Int,
) (*sdk.SimulationResponse, error) {

// Set height for historical queries
ctx := e.cliCtx

Expand Down Expand Up @@ -900,6 +906,12 @@ func (e *PublicEthAPI) generateFromArgs(args params.SendTxArgs) (*types.MsgEther
authclient.Codec = codec.NewAppCodec(e.cliCtx.Codec)
accRet := authtypes.NewAccountRetriever(authclient.Codec, e.cliCtx)

err = accRet.EnsureExists(from)
if err != nil {
// account doesn't exist
return nil, fmt.Errorf("nonexistent account %s: %s", args.From.Hex(), err)
}

_, nonce, err = accRet.GetAccountNumberSequence(from)
if err != nil {
return nil, err
Expand Down