Skip to content

Commit ac0f220

Browse files
authored
eth/tracers, internal/ethapi: remove unnecessary map pointer in state override (ethereum#30094)
1 parent 4dfc75d commit ac0f220

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

eth/tracers/api_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ func TestTracingWithOverrides(t *testing.T) {
843843
byte(vm.PUSH1), 00,
844844
byte(vm.RETURN),
845845
}),
846-
StateDiff: &map[common.Hash]common.Hash{
846+
StateDiff: map[common.Hash]common.Hash{
847847
common.HexToHash("0x03"): common.HexToHash("0x11"),
848848
},
849849
},
@@ -898,25 +898,25 @@ func newAccounts(n int) (accounts []Account) {
898898
return accounts
899899
}
900900

901-
func newRPCBalance(balance *big.Int) **hexutil.Big {
901+
func newRPCBalance(balance *big.Int) *hexutil.Big {
902902
rpcBalance := (*hexutil.Big)(balance)
903-
return &rpcBalance
903+
return rpcBalance
904904
}
905905

906906
func newRPCBytes(bytes []byte) *hexutil.Bytes {
907907
rpcBytes := hexutil.Bytes(bytes)
908908
return &rpcBytes
909909
}
910910

911-
func newStates(keys []common.Hash, vals []common.Hash) *map[common.Hash]common.Hash {
911+
func newStates(keys []common.Hash, vals []common.Hash) map[common.Hash]common.Hash {
912912
if len(keys) != len(vals) {
913913
panic("invalid input")
914914
}
915915
m := make(map[common.Hash]common.Hash)
916916
for i := 0; i < len(keys); i++ {
917917
m[keys[i]] = vals[i]
918918
}
919-
return &m
919+
return m
920920
}
921921

922922
func TestTraceChain(t *testing.T) {

internal/ethapi/api.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -968,11 +968,11 @@ func (api *BlockChainAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rp
968968
// if stateDiff is set, all diff will be applied first and then execute the call
969969
// message.
970970
type OverrideAccount struct {
971-
Nonce *hexutil.Uint64 `json:"nonce"`
972-
Code *hexutil.Bytes `json:"code"`
973-
Balance **hexutil.Big `json:"balance"`
974-
State *map[common.Hash]common.Hash `json:"state"`
975-
StateDiff *map[common.Hash]common.Hash `json:"stateDiff"`
971+
Nonce *hexutil.Uint64 `json:"nonce"`
972+
Code *hexutil.Bytes `json:"code"`
973+
Balance *hexutil.Big `json:"balance"`
974+
State map[common.Hash]common.Hash `json:"state"`
975+
StateDiff map[common.Hash]common.Hash `json:"stateDiff"`
976976
}
977977

978978
// StateOverride is the collection of overridden accounts.
@@ -994,19 +994,19 @@ func (diff *StateOverride) Apply(statedb *state.StateDB) error {
994994
}
995995
// Override account balance.
996996
if account.Balance != nil {
997-
u256Balance, _ := uint256.FromBig((*big.Int)(*account.Balance))
997+
u256Balance, _ := uint256.FromBig((*big.Int)(account.Balance))
998998
statedb.SetBalance(addr, u256Balance, tracing.BalanceChangeUnspecified)
999999
}
10001000
if account.State != nil && account.StateDiff != nil {
10011001
return fmt.Errorf("account %s has both 'state' and 'stateDiff'", addr.Hex())
10021002
}
10031003
// Replace entire state if caller requires.
10041004
if account.State != nil {
1005-
statedb.SetStorage(addr, *account.State)
1005+
statedb.SetStorage(addr, account.State)
10061006
}
10071007
// Apply state diff into specified accounts.
10081008
if account.StateDiff != nil {
1009-
for key, value := range *account.StateDiff {
1009+
for key, value := range account.StateDiff {
10101010
statedb.SetState(addr, key, value)
10111011
}
10121012
}

internal/ethapi/api_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ func TestCall(t *testing.T) {
913913
overrides: StateOverride{
914914
randomAccounts[2].addr: OverrideAccount{
915915
Code: hex2Bytes("6080604052348015600f57600080fd5b506004361060285760003560e01c80638381f58a14602d575b600080fd5b60336049565b6040518082815260200191505060405180910390f35b6000548156fea2646970667358221220eab35ffa6ab2adfe380772a48b8ba78e82a1b820a18fcb6f59aa4efb20a5f60064736f6c63430007040033"),
916-
StateDiff: &map[common.Hash]common.Hash{{}: common.BigToHash(big.NewInt(123))},
916+
StateDiff: map[common.Hash]common.Hash{{}: common.BigToHash(big.NewInt(123))},
917917
},
918918
},
919919
want: "0x000000000000000000000000000000000000000000000000000000000000007b",
@@ -1343,9 +1343,9 @@ func newAccounts(n int) (accounts []account) {
13431343
return accounts
13441344
}
13451345

1346-
func newRPCBalance(balance *big.Int) **hexutil.Big {
1346+
func newRPCBalance(balance *big.Int) *hexutil.Big {
13471347
rpcBalance := (*hexutil.Big)(balance)
1348-
return &rpcBalance
1348+
return rpcBalance
13491349
}
13501350

13511351
func hex2Bytes(str string) *hexutil.Bytes {

0 commit comments

Comments
 (0)