mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-23 04:03:49 +00:00
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package ethapi
|
|
|
|
import (
|
|
"fmt"
|
|
"math/big"
|
|
|
|
"github.com/holiman/uint256"
|
|
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
|
|
|
"github.com/ledgerwatch/erigon/core/state"
|
|
)
|
|
|
|
type StateOverrides map[libcommon.Address]Account
|
|
|
|
func (overrides *StateOverrides) Override(state *state.IntraBlockState) error {
|
|
|
|
for addr, account := range *overrides {
|
|
// Override account nonce.
|
|
if account.Nonce != nil {
|
|
state.SetNonce(addr, uint64(*account.Nonce))
|
|
}
|
|
// Override account(contract) code.
|
|
if account.Code != nil {
|
|
state.SetCode(addr, *account.Code)
|
|
}
|
|
// Override account balance.
|
|
if account.Balance != nil {
|
|
balance, overflow := uint256.FromBig((*big.Int)(*account.Balance))
|
|
if overflow {
|
|
return fmt.Errorf("account.Balance higher than 2^256-1")
|
|
}
|
|
state.SetBalance(addr, balance)
|
|
}
|
|
if account.State != nil && account.StateDiff != nil {
|
|
return fmt.Errorf("account %s has both 'state' and 'stateDiff'", addr.Hex())
|
|
}
|
|
// Replace entire state if caller requires.
|
|
if account.State != nil {
|
|
state.SetStorage(addr, *account.State)
|
|
}
|
|
// Apply state diff into specified accounts.
|
|
if account.StateDiff != nil {
|
|
for key, value := range *account.StateDiff {
|
|
key := key
|
|
state.SetState(addr, &key, value)
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|