From 0aaaf34825a72ee5ec2c3f62fc7c67506df31e15 Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Thu, 8 Jun 2023 16:52:33 +0200 Subject: [PATCH] forgot the tracer --- internal/ethapi/transfertracer.go | 80 +++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 internal/ethapi/transfertracer.go diff --git a/internal/ethapi/transfertracer.go b/internal/ethapi/transfertracer.go new file mode 100644 index 0000000000..a853e38e6e --- /dev/null +++ b/internal/ethapi/transfertracer.go @@ -0,0 +1,80 @@ +// Copyright 2023 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + +package ethapi + +import ( + "math/big" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/core/vm" +) + +type callLog struct { + Address common.Address `json:"address"` + Topics []common.Hash `json:"topics"` + Data hexutil.Bytes `json:"data"` +} + +type transfer struct { + From common.Address `json:"from"` + To common.Address `json:"to"` + Value *big.Int `json:"value"` +} + +type tracer struct { + transfers []transfer +} + +func newTracer() *tracer { + return &tracer{transfers: make([]transfer, 0)} +} + +func (t *tracer) CaptureStart(env *vm.EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) { + if value.Cmp(common.Big0) > 0 { + t.transfers = append(t.transfers, transfer{From: from, To: to, Value: value}) + } + +} + +func (t *tracer) CaptureEnd(output []byte, gasUsed uint64, err error) { +} + +func (t *tracer) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, rData []byte, depth int, err error) { +} + +func (t *tracer) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, depth int, err error) { +} + +func (t *tracer) CaptureEnter(typ vm.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) { + toCopy := to + if value.Cmp(common.Big0) > 0 { + t.transfers = append(t.transfers, transfer{From: from, To: toCopy, Value: value}) + } +} + +// CaptureExit is called when EVM exits a scope, even if the scope didn't +// execute any code. +func (t *tracer) CaptureExit(output []byte, gasUsed uint64, err error) {} + +func (t *tracer) CaptureTxStart(gasLimit uint64) {} + +func (t *tracer) CaptureTxEnd(restGas uint64) {} + +func (t *tracer) Transfers() []transfer { + return t.transfers +}