all: use uint256 in state (#28598)
This change makes use of uin256 to represent balance in state. It touches primarily upon statedb, stateobject and state processing, trying to avoid changes in transaction pools, core types, rpc and tracers.
This commit is contained in:
@@ -47,6 +47,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
"github.com/holiman/uint256"
|
||||
"github.com/tyler-smith/go-bip39"
|
||||
)
|
||||
|
||||
@@ -650,7 +651,8 @@ func (s *BlockChainAPI) GetBalance(ctx context.Context, address common.Address,
|
||||
if state == nil || err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return (*hexutil.Big)(state.GetBalance(address)), state.Error()
|
||||
b := state.GetBalance(address).ToBig()
|
||||
return (*hexutil.Big)(b), state.Error()
|
||||
}
|
||||
|
||||
// Result structs for GetProof
|
||||
@@ -748,10 +750,11 @@ func (s *BlockChainAPI) GetProof(ctx context.Context, address common.Address, st
|
||||
if err := tr.Prove(crypto.Keccak256(address.Bytes()), &accountProof); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
balance := statedb.GetBalance(address).ToBig()
|
||||
return &AccountResult{
|
||||
Address: address,
|
||||
AccountProof: accountProof,
|
||||
Balance: (*hexutil.Big)(statedb.GetBalance(address)),
|
||||
Balance: (*hexutil.Big)(balance),
|
||||
CodeHash: codeHash,
|
||||
Nonce: hexutil.Uint64(statedb.GetNonce(address)),
|
||||
StorageHash: storageRoot,
|
||||
@@ -974,7 +977,8 @@ func (diff *StateOverride) Apply(state *state.StateDB) error {
|
||||
}
|
||||
// Override account balance.
|
||||
if account.Balance != nil {
|
||||
state.SetBalance(addr, (*big.Int)(*account.Balance))
|
||||
u256Balance, _ := uint256.FromBig((*big.Int)(*account.Balance))
|
||||
state.SetBalance(addr, u256Balance)
|
||||
}
|
||||
if account.State != nil && account.StateDiff != nil {
|
||||
return fmt.Errorf("account %s has both 'state' and 'stateDiff'", addr.Hex())
|
||||
|
||||
Reference in New Issue
Block a user