github.com/matthieu/go-ethereum@v1.13.2/core/internals_processor.go (about) 1 package core 2 3 import ( 4 "math/big" 5 6 "github.com/matthieu/go-ethereum/common" 7 "github.com/matthieu/go-ethereum/core/types" 8 "github.com/matthieu/go-ethereum/core/vm" 9 ) 10 11 // Implementation of evm.InternalTxListener 12 13 type InternalTxWatcher struct { 14 internals types.InternalTransactions 15 } 16 17 func NewInternalTxWatcher() *InternalTxWatcher { 18 return &InternalTxWatcher{ 19 internals: make(types.InternalTransactions, 0), 20 } 21 } 22 23 // Public API: for users 24 func (self *InternalTxWatcher) SetParentHash(ph common.Hash) { 25 for i := range self.internals { 26 self.internals[i].ParentHash = ph 27 } 28 } 29 30 func (self *InternalTxWatcher) InternalTransactions() types.InternalTransactions { 31 return self.internals 32 } 33 34 // Public API: For interfacing with EVM 35 func (self *InternalTxWatcher) RegisterCall(nonce uint64, gasPrice *big.Int, gas uint64, srcAddr, dstAddr common.Address, value *big.Int, data []byte, depth uint64) { 36 self.internals = append(self.internals, 37 types.NewInternalTransaction(nonce, gasPrice, gas, 38 srcAddr, dstAddr, value, data, depth, self.index(), "call")) 39 } 40 41 func (self *InternalTxWatcher) RegisterStaticCall(nonce uint64, gasPrice *big.Int, gas uint64, srcAddr, dstAddr common.Address, data []byte, depth uint64) { 42 43 self.internals = append(self.internals, 44 types.NewInternalTransaction(nonce, gasPrice, gas, 45 srcAddr, dstAddr, big.NewInt(0), data, depth, self.index(), 46 "staticcall")) 47 } 48 49 func (self *InternalTxWatcher) RegisterCallCode(nonce uint64, gasPrice *big.Int, gas uint64, contractAddr common.Address, value *big.Int, data []byte, depth uint64) { 50 self.internals = append(self.internals, 51 types.NewInternalTransaction(nonce, gasPrice, gas, 52 contractAddr, contractAddr, value, data, depth, self.index(), 53 "call")) 54 } 55 56 func (self *InternalTxWatcher) RegisterCreate(nonce uint64, gasPrice *big.Int, gas uint64, srcAddr, newContractAddr common.Address, value *big.Int, data []byte, depth uint64) { 57 self.internals = append(self.internals, 58 types.NewInternalTransaction(nonce, gasPrice, gas, 59 srcAddr, newContractAddr, value, data, depth, self.index(), 60 "create")) 61 } 62 63 func (self *InternalTxWatcher) RegisterDelegateCall(nonce uint64, gasPrice *big.Int, gas uint64, callerAddr common.Address, value *big.Int, data []byte, depth uint64) { 64 self.internals = append(self.internals, 65 types.NewInternalTransaction(nonce, gasPrice, gas, 66 callerAddr, callerAddr, value, data, depth, self.index(), "call")) 67 } 68 69 func (self *InternalTxWatcher) RegisterSuicide(nonce uint64, gasPrice *big.Int, gas uint64, contractAddr, creatorAddr common.Address, remainingValue *big.Int, depth uint64) { 70 self.internals = append(self.internals, 71 types.NewInternalTransaction(nonce, gasPrice, gas, 72 contractAddr, creatorAddr, remainingValue, 73 append([]byte{byte(vm.SELFDESTRUCT)}, creatorAddr[:]...), 74 depth, self.index(), "suicide")) 75 } 76 77 // Utilities 78 func (self *InternalTxWatcher) index() uint64 { 79 return uint64(len(self.internals)) 80 } 81 82 func toBigInt(g uint64) *big.Int { 83 return big.NewInt(0).SetUint64(g) 84 }