github.com/tacshi/go-ethereum@v0.0.0-20230616113857-84a434e20921/eth/tracers/native/tracer_arbitrum.go (about) 1 // Copyright 2022 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package native 18 19 import ( 20 "math/big" 21 "strconv" 22 "strings" 23 24 "github.com/tacshi/go-ethereum/common" 25 "github.com/tacshi/go-ethereum/core/vm" 26 ) 27 28 type arbitrumTransfer struct { 29 Purpose string `json:"purpose"` 30 From *string `json:"from"` 31 To *string `json:"to"` 32 Value string `json:"value"` 33 } 34 35 func (t *callTracer) CaptureArbitrumTransfer( 36 env *vm.EVM, from, to *common.Address, value *big.Int, before bool, purpose string, 37 ) { 38 transfer := arbitrumTransfer{ 39 Purpose: purpose, 40 Value: bigToHex(value), 41 } 42 if from != nil { 43 from := from.String() 44 transfer.From = &from 45 } 46 if to != nil { 47 to := to.String() 48 transfer.To = &to 49 } 50 if before { 51 t.beforeEVMTransfers = append(t.beforeEVMTransfers, transfer) 52 } else { 53 t.afterEVMTransfers = append(t.afterEVMTransfers, transfer) 54 } 55 } 56 57 func (*fourByteTracer) CaptureArbitrumTransfer(env *vm.EVM, from, to *common.Address, value *big.Int, before bool, purpose string) { 58 } 59 func (*noopTracer) CaptureArbitrumTransfer(env *vm.EVM, from, to *common.Address, value *big.Int, before bool, purpose string) { 60 } 61 func (*prestateTracer) CaptureArbitrumTransfer(env *vm.EVM, from, to *common.Address, value *big.Int, before bool, purpose string) { 62 } 63 func (t *flatCallTracer) CaptureArbitrumTransfer(env *vm.EVM, from, to *common.Address, value *big.Int, before bool, purpose string) { 64 transfer := arbitrumTransfer{ 65 Purpose: purpose, 66 Value: bigToHex(value), 67 } 68 if from != nil { 69 from := from.String() 70 transfer.From = &from 71 } 72 if to != nil { 73 to := to.String() 74 transfer.To = &to 75 } 76 if before { 77 t.beforeEVMTransfers = append(t.beforeEVMTransfers, transfer) 78 } else { 79 t.afterEVMTransfers = append(t.afterEVMTransfers, transfer) 80 } 81 } 82 83 func (*callTracer) CaptureArbitrumStorageGet(key common.Hash, depth int, before bool) {} 84 func (*fourByteTracer) CaptureArbitrumStorageGet(key common.Hash, depth int, before bool) {} 85 func (*noopTracer) CaptureArbitrumStorageGet(key common.Hash, depth int, before bool) {} 86 func (*prestateTracer) CaptureArbitrumStorageGet(key common.Hash, depth int, before bool) {} 87 func (*flatCallTracer) CaptureArbitrumStorageGet(key common.Hash, depth int, before bool) {} 88 89 func (*callTracer) CaptureArbitrumStorageSet(key, value common.Hash, depth int, before bool) {} 90 func (*fourByteTracer) CaptureArbitrumStorageSet(key, value common.Hash, depth int, before bool) {} 91 func (*noopTracer) CaptureArbitrumStorageSet(key, value common.Hash, depth int, before bool) {} 92 func (*prestateTracer) CaptureArbitrumStorageSet(key, value common.Hash, depth int, before bool) {} 93 func (*flatCallTracer) CaptureArbitrumStorageSet(key, value common.Hash, depth int, before bool) {} 94 95 func bigToHex(n *big.Int) string { 96 if n == nil { 97 return "" 98 } 99 return "0x" + n.Text(16) 100 } 101 102 func uintToHex(n uint64) string { 103 return "0x" + strconv.FormatUint(n, 16) 104 } 105 106 func addrToHex(a common.Address) string { 107 return strings.ToLower(a.Hex()) 108 }