github.com/shrimpyuk/bor@v0.2.15-0.20220224151350-fb4ec6020bae/core/bor_fee_log.go (about) 1 package core 2 3 import ( 4 "math/big" 5 6 "github.com/ethereum/go-ethereum/common" 7 "github.com/ethereum/go-ethereum/core/types" 8 "github.com/ethereum/go-ethereum/core/vm" 9 ) 10 11 var transferLogSig = common.HexToHash("0xe6497e3ee548a3372136af2fcb0696db31fc6cf20260707645068bd3fe97f3c4") 12 var transferFeeLogSig = common.HexToHash("0x4dfe1bbbcf077ddc3e01291eea2d5c70c2b422b415d95645b9adcfd678cb1d63") 13 var feeAddress = common.HexToAddress("0x0000000000000000000000000000000000001010") 14 var bigZero = big.NewInt(0) 15 16 // AddTransferLog adds transfer log into state 17 func AddTransferLog( 18 state vm.StateDB, 19 20 sender, 21 recipient common.Address, 22 23 amount, 24 input1, 25 input2, 26 output1, 27 output2 *big.Int, 28 ) { 29 addTransferLog( 30 state, 31 transferLogSig, 32 33 sender, 34 recipient, 35 36 amount, 37 input1, 38 input2, 39 output1, 40 output2, 41 ) 42 } 43 44 // AddFeeTransferLog adds transfer log into state 45 // Deprecating transfer log and will be removed in future fork. PLEASE DO NOT USE this transfer log going forward. Parameters won't get updated as expected going forward with EIP1559 46 func AddFeeTransferLog( 47 state vm.StateDB, 48 49 sender, 50 recipient common.Address, 51 52 amount, 53 input1, 54 input2, 55 output1, 56 output2 *big.Int, 57 ) { 58 addTransferLog( 59 state, 60 transferFeeLogSig, 61 62 sender, 63 recipient, 64 65 amount, 66 input1, 67 input2, 68 output1, 69 output2, 70 ) 71 } 72 73 // addTransferLog adds transfer log into state 74 func addTransferLog( 75 state vm.StateDB, 76 eventSig common.Hash, 77 78 sender, 79 recipient common.Address, 80 81 amount, 82 input1, 83 input2, 84 output1, 85 output2 *big.Int, 86 ) { 87 // ignore if amount is 0 88 if amount.Cmp(bigZero) <= 0 { 89 return 90 } 91 92 dataInputs := []*big.Int{ 93 amount, 94 input1, 95 input2, 96 output1, 97 output2, 98 } 99 100 var data []byte 101 for _, v := range dataInputs { 102 data = append(data, common.LeftPadBytes(v.Bytes(), 32)...) 103 } 104 105 // add transfer log 106 state.AddLog(&types.Log{ 107 Address: feeAddress, 108 Topics: []common.Hash{ 109 eventSig, 110 feeAddress.Hash(), 111 sender.Hash(), 112 recipient.Hash(), 113 }, 114 Data: data, 115 }) 116 }