2023-07-08 17:01:26 +00:00
|
|
|
package jsonrpc
|
2022-11-03 04:32:15 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-10-21 23:17:18 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/common/hexutil"
|
2022-11-03 04:32:15 +00:00
|
|
|
|
2022-11-30 01:31:39 +00:00
|
|
|
"github.com/holiman/uint256"
|
2023-01-27 04:34:04 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/common"
|
2023-01-13 18:12:18 +00:00
|
|
|
|
2022-11-03 04:32:15 +00:00
|
|
|
"github.com/ledgerwatch/erigon/core/vm"
|
|
|
|
)
|
|
|
|
|
|
|
|
type OperationType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
OP_TRANSFER OperationType = 0
|
|
|
|
OP_SELF_DESTRUCT OperationType = 1
|
|
|
|
OP_CREATE OperationType = 2
|
|
|
|
OP_CREATE2 OperationType = 3
|
|
|
|
)
|
|
|
|
|
|
|
|
type InternalOperation struct {
|
2023-01-27 04:34:04 +00:00
|
|
|
Type OperationType `json:"type"`
|
|
|
|
From common.Address `json:"from"`
|
|
|
|
To common.Address `json:"to"`
|
|
|
|
Value *hexutil.Big `json:"value"`
|
2022-11-03 04:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type OperationsTracer struct {
|
|
|
|
DefaultTracer
|
|
|
|
ctx context.Context
|
|
|
|
Results []*InternalOperation
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewOperationsTracer(ctx context.Context) *OperationsTracer {
|
|
|
|
return &OperationsTracer{
|
|
|
|
ctx: ctx,
|
|
|
|
Results: make([]*InternalOperation, 0),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-27 04:34:04 +00:00
|
|
|
func (t *OperationsTracer) CaptureEnter(typ vm.OpCode, from common.Address, to common.Address, precompile bool, create bool, input []byte, gas uint64, value *uint256.Int, code []byte) {
|
2022-12-19 03:12:08 +00:00
|
|
|
if typ == vm.CALL && value.Uint64() != 0 {
|
2022-11-30 01:31:39 +00:00
|
|
|
t.Results = append(t.Results, &InternalOperation{OP_TRANSFER, from, to, (*hexutil.Big)(value.ToBig())})
|
2022-11-03 04:32:15 +00:00
|
|
|
return
|
|
|
|
}
|
2022-12-19 03:12:08 +00:00
|
|
|
if typ == vm.CREATE {
|
2022-11-30 01:31:39 +00:00
|
|
|
t.Results = append(t.Results, &InternalOperation{OP_CREATE, from, to, (*hexutil.Big)(value.ToBig())})
|
2022-11-03 04:32:15 +00:00
|
|
|
}
|
2022-12-19 03:12:08 +00:00
|
|
|
if typ == vm.CREATE2 {
|
2022-11-30 01:31:39 +00:00
|
|
|
t.Results = append(t.Results, &InternalOperation{OP_CREATE2, from, to, (*hexutil.Big)(value.ToBig())})
|
2022-11-03 04:32:15 +00:00
|
|
|
}
|
2022-12-26 04:56:39 +00:00
|
|
|
if typ == vm.SELFDESTRUCT {
|
|
|
|
t.Results = append(t.Results, &InternalOperation{OP_SELF_DESTRUCT, from, to, (*hexutil.Big)(value.ToBig())})
|
|
|
|
}
|
2022-11-03 04:32:15 +00:00
|
|
|
}
|