rpc: fix balance overflow (#219)

Closes #218
This commit is contained in:
yihuang
2021-07-02 05:29:47 -04:00
committed by GitHub
parent f7d975ada2
commit 6e983a9da1
8 changed files with 408 additions and 187 deletions
+12 -2
View File
@@ -215,7 +215,12 @@ func (e *PublicAPI) GetBalance(address common.Address, blockNum rpctypes.BlockNu
return nil, err
}
return (*hexutil.Big)(big.NewInt(res.Balance)), nil
val, ok := sdk.NewIntFromString(res.Balance)
if !ok {
return nil, errors.New("invalid balance")
}
return (*hexutil.Big)(val.BigInt()), nil
}
// GetStorageAt returns the contract storage at the given address, block number, and key.
@@ -992,10 +997,15 @@ func (e *PublicAPI) GetProof(address common.Address, storageKeys []string, block
accProofStr = proof.String()
}
balance, ok := sdk.NewIntFromString(res.Balance)
if !ok {
return nil, errors.New("invalid balance")
}
return &rpctypes.AccountResult{
Address: address,
AccountProof: []string{accProofStr},
Balance: (*hexutil.Big)(big.NewInt(res.Balance)),
Balance: (*hexutil.Big)(balance.BigInt()),
CodeHash: common.HexToHash(res.CodeHash),
Nonce: hexutil.Uint64(res.Nonce),
StorageHash: common.Hash{}, // NOTE: Ethermint doesn't have a storage hash. TODO: implement?