Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

fix: align empty account result for old blocks as ethereum #1484

Merged
merged 12 commits into from
Nov 25, 2022
11 changes: 10 additions & 1 deletion rpc/backend/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand Down Expand Up @@ -46,8 +48,15 @@ func (s sortGasAndReward) Less(i, j int) bool {
// Todo: include the ability to specify a blockNumber
func (b *Backend) getAccountNonce(accAddr common.Address, pending bool, height int64, logger log.Logger) (uint64, error) {
queryClient := authtypes.NewQueryClient(b.clientCtx)
res, err := queryClient.Account(types.ContextWithHeight(height), &authtypes.QueryAccountRequest{Address: sdk.AccAddress(accAddr.Bytes()).String()})
adr := sdk.AccAddress(accAddr.Bytes()).String()
ctx := types.ContextWithHeight(height)
res, err := queryClient.Account(ctx, &authtypes.QueryAccountRequest{Address: adr})
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
st, ok := status.FromError(err)
// treat as account doesn't exist yet
if ok && st.Code() == codes.NotFound {
err = nil
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
}
return 0, err
}
var acc authtypes.AccountI
Expand Down