-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added stateOverride type * solved import cycle * refactoring * imported wrong package * fixed Call arguments * typo * override for traceCall
- Loading branch information
Showing
6 changed files
with
71 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
package tracers | ||
|
||
import "github.com/ledgerwatch/erigon/core/vm" | ||
import ( | ||
"github.com/ledgerwatch/erigon/core/vm" | ||
"github.com/ledgerwatch/erigon/internal/ethapi" | ||
) | ||
|
||
// TraceConfig holds extra parameters to trace functions. | ||
type TraceConfig struct { | ||
*vm.LogConfig | ||
Tracer *string | ||
Timeout *string | ||
Reexec *uint64 | ||
NoRefunds *bool // Turns off gas refunds when tracing | ||
Tracer *string | ||
Timeout *string | ||
Reexec *uint64 | ||
NoRefunds *bool // Turns off gas refunds when tracing | ||
StateOverrides *ethapi.StateOverrides | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package ethapi | ||
|
||
import ( | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/holiman/uint256" | ||
"github.com/ledgerwatch/erigon/common" | ||
"github.com/ledgerwatch/erigon/core/state" | ||
) | ||
|
||
type StateOverrides map[common.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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters