2021-08-31 20:29:09 +00:00
|
|
|
package wrappers
|
|
|
|
|
|
|
|
import (
|
2021-09-03 22:20:49 +00:00
|
|
|
"math/big"
|
2022-05-25 20:07:38 +00:00
|
|
|
"encoding/json"
|
2021-09-03 22:20:49 +00:00
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2021-09-08 21:38:17 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/state"
|
2021-09-03 22:20:49 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/vm"
|
|
|
|
"github.com/ethereum/go-ethereum/node"
|
2023-09-13 19:57:48 +00:00
|
|
|
|
2021-09-03 22:20:49 +00:00
|
|
|
"github.com/openrelayxyz/plugeth-utils/core"
|
2021-08-31 20:29:09 +00:00
|
|
|
)
|
|
|
|
|
2021-09-08 21:38:17 +00:00
|
|
|
type WrappedScopeContext struct {
|
2021-09-03 22:20:49 +00:00
|
|
|
s *vm.ScopeContext
|
|
|
|
}
|
|
|
|
|
2021-09-08 21:38:17 +00:00
|
|
|
func NewWrappedScopeContext(s *vm.ScopeContext) *WrappedScopeContext {
|
|
|
|
return &WrappedScopeContext{s}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *WrappedScopeContext) Memory() core.Memory {
|
2021-09-03 22:20:49 +00:00
|
|
|
return w.s.Memory
|
|
|
|
}
|
|
|
|
|
2021-09-08 21:38:17 +00:00
|
|
|
func (w *WrappedScopeContext) Stack() core.Stack {
|
2021-09-03 22:20:49 +00:00
|
|
|
return w.s.Stack
|
|
|
|
}
|
|
|
|
|
2021-09-08 21:38:17 +00:00
|
|
|
func (w *WrappedScopeContext) Contract() core.Contract {
|
|
|
|
return &WrappedContract{w.s.Contract}
|
|
|
|
}
|
2021-09-03 22:20:49 +00:00
|
|
|
|
|
|
|
type WrappedContract struct {
|
|
|
|
c *vm.Contract
|
|
|
|
}
|
|
|
|
|
2021-09-08 21:38:17 +00:00
|
|
|
func (w *WrappedContract) AsDelegate() core.Contract {
|
|
|
|
return &WrappedContract{w.c.AsDelegate()}
|
2021-09-03 22:20:49 +00:00
|
|
|
}
|
|
|
|
|
2021-09-08 21:38:17 +00:00
|
|
|
func (w *WrappedContract) GetOp(n uint64) core.OpCode {
|
2021-09-03 22:20:49 +00:00
|
|
|
return core.OpCode(w.c.GetOp(n))
|
|
|
|
}
|
|
|
|
|
2021-09-08 21:38:17 +00:00
|
|
|
func (w *WrappedContract) GetByte(n uint64) byte {
|
2021-12-27 22:43:35 +00:00
|
|
|
return byte(w.c.GetOp(n))
|
2021-09-03 22:20:49 +00:00
|
|
|
}
|
|
|
|
|
2021-09-08 21:38:17 +00:00
|
|
|
func (w *WrappedContract) Caller() core.Address {
|
2021-09-03 22:20:49 +00:00
|
|
|
return core.Address(w.c.Caller())
|
|
|
|
}
|
|
|
|
|
2021-09-08 21:38:17 +00:00
|
|
|
func (w *WrappedContract) Address() core.Address {
|
2021-09-03 22:20:49 +00:00
|
|
|
return core.Address(w.c.Address())
|
|
|
|
}
|
|
|
|
|
2021-09-08 21:38:17 +00:00
|
|
|
func (w *WrappedContract) Value() *big.Int {
|
2021-09-03 22:20:49 +00:00
|
|
|
return w.c.Value()
|
|
|
|
}
|
|
|
|
|
2022-01-14 21:39:38 +00:00
|
|
|
func (w *WrappedContract) Input() []byte {
|
|
|
|
return w.c.Input
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *WrappedContract) Code() []byte {
|
|
|
|
return w.c.Code
|
|
|
|
}
|
|
|
|
|
2021-09-08 21:38:17 +00:00
|
|
|
// added UseGas bc compiler compained without it. Should investigate if the false return with effect performance.
|
|
|
|
// take this out of core.interface
|
|
|
|
func (w *WrappedContract) UseGas(gas uint64) (ok bool) {
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
type WrappedTracer struct {
|
|
|
|
r core.TracerResult
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewWrappedTracer(r core.TracerResult) *WrappedTracer {
|
|
|
|
return &WrappedTracer{r}
|
|
|
|
}
|
2022-02-16 00:56:50 +00:00
|
|
|
func (w WrappedTracer) CapturePreStart(from common.Address, to *common.Address, input []byte, gas uint64, value *big.Int) {
|
|
|
|
if v, ok := w.r.(core.PreTracer); ok {
|
|
|
|
v.CapturePreStart(core.Address(from), (*core.Address)(to), input, gas, value)}
|
|
|
|
}
|
2021-09-08 21:38:17 +00:00
|
|
|
func (w WrappedTracer) CaptureStart(env *vm.EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) {
|
|
|
|
w.r.CaptureStart(core.Address(from), core.Address(to), create, input, gas, value)
|
|
|
|
}
|
2021-11-27 00:43:34 +00:00
|
|
|
func (w WrappedTracer) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, rData []byte, depth int, err error) {
|
2021-09-08 21:38:17 +00:00
|
|
|
w.r.CaptureState(pc, core.OpCode(op), gas, cost, &WrappedScopeContext{scope}, rData, depth, err)
|
|
|
|
}
|
2021-10-18 21:48:51 +00:00
|
|
|
func (w WrappedTracer) CaptureEnter(typ vm.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
|
|
|
|
w.r.CaptureEnter(core.OpCode(typ), core.Address(from), core.Address(to), input, gas, value)
|
|
|
|
}
|
|
|
|
func (w WrappedTracer) CaptureExit(output []byte, gasUsed uint64, err error) {
|
|
|
|
w.r.CaptureExit(output, gasUsed, err)
|
|
|
|
}
|
2021-11-27 00:43:34 +00:00
|
|
|
func (w WrappedTracer) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, depth int, err error) {
|
|
|
|
w.r.CaptureFault(pc, core.OpCode(op), gas, cost, &WrappedScopeContext{scope}, depth, err)
|
|
|
|
}
|
2023-02-21 18:29:25 +00:00
|
|
|
// passing zero as a dummy value is foundation PluGeth only, it is being done to preserve compatability with other networks
|
2023-02-17 16:29:46 +00:00
|
|
|
func (w WrappedTracer) CaptureEnd(output []byte, gasUsed uint64, err error) {
|
2023-02-21 18:29:25 +00:00
|
|
|
w.r.CaptureEnd(output, gasUsed, 0, err)
|
2021-11-27 00:43:34 +00:00
|
|
|
}
|
2022-05-25 20:07:38 +00:00
|
|
|
func (w WrappedTracer) GetResult() (json.RawMessage, error) {
|
|
|
|
data, err := w.r.Result()
|
|
|
|
if err != nil { return nil, err}
|
|
|
|
result, err := json.Marshal(data)
|
|
|
|
return json.RawMessage(result), err
|
2021-09-08 21:38:17 +00:00
|
|
|
}
|
2022-05-25 20:07:38 +00:00
|
|
|
func (w WrappedTracer) CaptureTxStart (gasLimit uint64) {}
|
|
|
|
|
|
|
|
func (w WrappedTracer) CaptureTxEnd (restGas uint64) {}
|
|
|
|
|
|
|
|
func (w WrappedTracer) Stop(err error) {}
|
|
|
|
|
2021-09-08 21:38:17 +00:00
|
|
|
|
|
|
|
type WrappedStateDB struct {
|
|
|
|
s *state.StateDB
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewWrappedStateDB(d *state.StateDB) *WrappedStateDB {
|
|
|
|
return &WrappedStateDB{d}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBalance(Address) *big.Int
|
|
|
|
func (w *WrappedStateDB) GetBalance(addr core.Address) *big.Int {
|
|
|
|
return w.s.GetBalance(common.Address(addr))
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetNonce(Address) uint64
|
|
|
|
func (w *WrappedStateDB) GetNonce(addr core.Address) uint64 {
|
|
|
|
return w.s.GetNonce(common.Address(addr))
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetCodeHash(Address) Hash
|
|
|
|
func (w *WrappedStateDB) GetCodeHash(addr core.Address) core.Hash {
|
|
|
|
return core.Hash(w.s.GetCodeHash(common.Address(addr)))
|
|
|
|
} // sort this out
|
|
|
|
|
|
|
|
// GetCode(Address) []byte
|
|
|
|
func (w *WrappedStateDB) GetCode(addr core.Address) []byte {
|
|
|
|
return w.s.GetCode(common.Address(addr))
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetCodeSize(Address) int
|
|
|
|
func (w *WrappedStateDB) GetCodeSize(addr core.Address) int {
|
|
|
|
return w.s.GetCodeSize(common.Address(addr))
|
|
|
|
}
|
|
|
|
|
|
|
|
//GetRefund() uint64
|
|
|
|
func (w *WrappedStateDB) GetRefund() uint64 { //are we sure we want to include this? getting a refund seems like changing state
|
|
|
|
return w.s.GetRefund()
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetCommittedState(Address, Hash) Hash
|
|
|
|
func (w *WrappedStateDB) GetCommittedState(addr core.Address, hsh core.Hash) core.Hash {
|
|
|
|
return core.Hash(w.s.GetCommittedState(common.Address(addr), common.Hash(hsh)))
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetState(Address, Hash) Hash
|
|
|
|
func (w *WrappedStateDB) GetState(addr core.Address, hsh core.Hash) core.Hash {
|
|
|
|
return core.Hash(w.s.GetState(common.Address(addr), common.Hash(hsh)))
|
|
|
|
}
|
|
|
|
|
|
|
|
// HasSuicided(Address) bool
|
2023-09-13 19:57:48 +00:00
|
|
|
func (w *WrappedStateDB) HasSuicided(addr core.Address) bool {
|
|
|
|
return w.s.HasSelfDestructed(common.Address(addr))
|
2021-09-08 21:38:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// // Exist reports whether the given account exists in state.
|
|
|
|
// // Notably this should also return true for suicided accounts.
|
|
|
|
// Exist(Address) bool
|
|
|
|
func (w *WrappedStateDB) Exist(addr core.Address) bool {
|
|
|
|
return w.s.Exist(common.Address(addr))
|
|
|
|
}
|
|
|
|
|
|
|
|
// // Empty returns whether the given account is empty. Empty
|
|
|
|
// // is defined according to EIP161 (balance = nonce = code = 0).
|
|
|
|
// Empty(Address) bool
|
|
|
|
func (w *WrappedStateDB) Empty(addr core.Address) bool {
|
|
|
|
return w.s.Empty(common.Address(addr))
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddressInAccessList(addr Address) bool
|
|
|
|
func (w *WrappedStateDB) AddressInAccessList(addr core.Address) bool {
|
|
|
|
return w.s.AddressInAccessList(common.Address(addr))
|
|
|
|
}
|
|
|
|
|
|
|
|
// SlotInAccessList(addr Address, slot Hash) (addressOk bool, slotOk bool)
|
|
|
|
func (w *WrappedStateDB) SlotInAccessList(addr core.Address, slot core.Hash) (addressOK, slotOk bool) {
|
|
|
|
return w.s.SlotInAccessList(common.Address(addr), common.Hash(slot))
|
|
|
|
}
|
|
|
|
|
2023-06-12 16:52:46 +00:00
|
|
|
// IntermediateRoot(deleteEmptyObjects bool) common.Hash
|
|
|
|
func (w *WrappedStateDB) IntermediateRoot(deleteEmptyObjects bool) core.Hash {
|
|
|
|
return core.Hash(w.s.IntermediateRoot(deleteEmptyObjects))
|
|
|
|
}
|
2023-10-10 21:32:52 +00:00
|
|
|
|
|
|
|
func (w *WrappedStateDB) AddBalance(addr core.Address, amount *big.Int) {
|
|
|
|
w.s.AddBalance(common.Address(addr), amount)
|
|
|
|
}
|
2023-06-12 16:52:46 +00:00
|
|
|
|
2021-08-31 20:29:09 +00:00
|
|
|
type Node struct {
|
2021-09-03 22:20:49 +00:00
|
|
|
n *node.Node
|
2021-08-31 20:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewNode(n *node.Node) *Node {
|
2021-09-03 22:20:49 +00:00
|
|
|
return &Node{n}
|
2021-08-31 20:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Node) Server() core.Server {
|
2021-09-15 20:09:43 +00:00
|
|
|
return n.n.Server()
|
2021-08-31 20:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Node) DataDir() string {
|
2021-09-03 22:20:49 +00:00
|
|
|
return n.n.DataDir()
|
2021-08-31 20:29:09 +00:00
|
|
|
}
|
|
|
|
func (n *Node) InstanceDir() string {
|
2021-09-03 22:20:49 +00:00
|
|
|
return n.n.InstanceDir()
|
2021-08-31 20:29:09 +00:00
|
|
|
}
|
|
|
|
func (n *Node) IPCEndpoint() string {
|
2021-09-03 22:20:49 +00:00
|
|
|
return n.n.IPCEndpoint()
|
2021-08-31 20:29:09 +00:00
|
|
|
}
|
|
|
|
func (n *Node) HTTPEndpoint() string {
|
2021-09-03 22:20:49 +00:00
|
|
|
return n.n.HTTPEndpoint()
|
2021-08-31 20:29:09 +00:00
|
|
|
}
|
|
|
|
func (n *Node) WSEndpoint() string {
|
2021-09-03 22:20:49 +00:00
|
|
|
return n.n.WSEndpoint()
|
2021-08-31 20:29:09 +00:00
|
|
|
}
|
|
|
|
func (n *Node) ResolvePath(x string) string {
|
2021-09-03 22:20:49 +00:00
|
|
|
return n.n.ResolvePath(x)
|
2021-08-31 20:29:09 +00:00
|
|
|
}
|
2021-10-10 20:08:52 +00:00
|
|
|
func (n *Node) Attach() (core.Client, error) {
|
2023-09-13 19:57:48 +00:00
|
|
|
return n.n.Attach(), nil
|
2021-10-10 20:08:52 +00:00
|
|
|
}
|
2022-05-16 16:48:46 +00:00
|
|
|
func (n *Node) Close() error {
|
|
|
|
return n.n.Close()
|
|
|
|
}
|
2022-02-03 04:46:25 +00:00
|
|
|
|
2023-02-21 18:29:25 +00:00
|
|
|
type WrappedBlockContext struct {
|
|
|
|
b vm.BlockContext
|
|
|
|
}
|
|
|
|
|
|
|
|
// type WrappedBlockContext vm.BlockContext
|
|
|
|
|
|
|
|
func NewWrappedBlockContext(c vm.BlockContext) *WrappedBlockContext {
|
|
|
|
return &WrappedBlockContext{c}
|
|
|
|
}
|
|
|
|
func (w *WrappedBlockContext) Coinbase() core.Address {
|
|
|
|
return core.Address(w.b.Coinbase)
|
|
|
|
}
|
|
|
|
func (w *WrappedBlockContext) GasLimit() uint64 {
|
|
|
|
return w.b.GasLimit
|
|
|
|
}
|
|
|
|
func (w *WrappedBlockContext) BlockNumber() *big.Int {
|
|
|
|
return w.b.BlockNumber
|
|
|
|
}
|
|
|
|
func (w *WrappedBlockContext) Time() *big.Int {
|
|
|
|
return new(big.Int).SetInt64(int64(w.b.Time))
|
|
|
|
}
|
|
|
|
func (w *WrappedBlockContext) Difficulty() *big.Int {
|
|
|
|
return w.b.Difficulty
|
|
|
|
}
|
|
|
|
func (w *WrappedBlockContext) BaseFee() *big.Int {
|
|
|
|
return w.b.BaseFee
|
|
|
|
}
|