github.com/amazechain/amc@v0.1.3/common/transaction/access_list.go (about) 1 // Copyright 2022 The AmazeChain Authors 2 // This file is part of the AmazeChain library. 3 // 4 // The AmazeChain 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 AmazeChain 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 AmazeChain library. If not, see <http://www.gnu.org/licenses/>. 16 17 package transaction 18 19 import ( 20 "github.com/amazechain/amc/common/hash" 21 "github.com/amazechain/amc/common/types" 22 "github.com/holiman/uint256" 23 ) 24 25 type AccessList []AccessTuple 26 27 // AccessTuple is the element type of an access list. 28 type AccessTuple struct { 29 Address types.Address `json:"address" gencodec:"required"` 30 StorageKeys []types.Hash `json:"storageKeys" gencodec:"required"` 31 } 32 33 // StorageKeys returns the total number of storage keys in the access list. 34 func (al AccessList) StorageKeys() int { 35 sum := 0 36 for _, tuple := range al { 37 sum += len(tuple.StorageKeys) 38 } 39 return sum 40 } 41 42 type AccessListTx struct { 43 ChainID *uint256.Int // destination chain ID 44 Nonce uint64 // nonce of sender account 45 GasPrice *uint256.Int // wei per gas 46 Gas uint64 // gas limit 47 To *types.Address `rlp:"nil"` // nil means contract creation 48 From *types.Address `rlp:"nil"` // nil means contract creation 49 Value *uint256.Int // wei amount 50 Data []byte // contract invocation input data 51 AccessList AccessList // EIP-2930 access list 52 Sign []byte // signature values 53 V, R, S *uint256.Int // signature values 54 } 55 56 func (tx *AccessListTx) copy() TxData { 57 cpy := &AccessListTx{ 58 Nonce: tx.Nonce, 59 To: copyAddressPtr(tx.To), 60 From: copyAddressPtr(tx.From), 61 Data: types.CopyBytes(tx.Data), 62 Gas: tx.Gas, 63 // These are copied below. 64 AccessList: make(AccessList, len(tx.AccessList)), 65 Value: new(uint256.Int), 66 ChainID: new(uint256.Int), 67 GasPrice: new(uint256.Int), 68 } 69 copy(cpy.AccessList, tx.AccessList) 70 if tx.Value != nil { 71 cpy.Value.Set(tx.Value) 72 } 73 if tx.ChainID != nil { 74 cpy.ChainID.Set(tx.ChainID) 75 } 76 if tx.GasPrice != nil { 77 cpy.GasPrice.Set(tx.GasPrice) 78 } 79 if tx.V != nil { 80 cpy.V.Set(tx.V) 81 } 82 if tx.R != nil { 83 cpy.R.Set(tx.R) 84 } 85 if tx.S != nil { 86 cpy.S.Set(tx.S) 87 } 88 89 if tx.Sign != nil { 90 copy(cpy.Sign, tx.Sign) 91 } 92 return cpy 93 } 94 95 // accessors for innerTx. 96 func (tx *AccessListTx) txType() byte { return AccessListTxType } 97 func (tx *AccessListTx) chainID() *uint256.Int { return tx.ChainID } 98 func (tx *AccessListTx) accessList() AccessList { return tx.AccessList } 99 func (tx *AccessListTx) data() []byte { return tx.Data } 100 func (tx *AccessListTx) gas() uint64 { return tx.Gas } 101 func (tx *AccessListTx) gasPrice() *uint256.Int { return tx.GasPrice } 102 func (tx *AccessListTx) gasTipCap() *uint256.Int { return tx.GasPrice } 103 func (tx *AccessListTx) gasFeeCap() *uint256.Int { return tx.GasPrice } 104 func (tx *AccessListTx) value() *uint256.Int { return tx.Value } 105 func (tx *AccessListTx) nonce() uint64 { return tx.Nonce } 106 func (tx *AccessListTx) to() *types.Address { return tx.To } 107 func (tx *AccessListTx) from() *types.Address { return tx.From } 108 func (tx *AccessListTx) sign() []byte { return tx.Sign } 109 110 func (tx *AccessListTx) hash() types.Hash { 111 hash := hash.PrefixedRlpHash(AccessListTxType, []interface{}{ 112 tx.ChainID, 113 tx.Nonce, 114 tx.GasPrice, 115 tx.Gas, 116 tx.To, 117 tx.Value, 118 tx.Data, 119 tx.AccessList, 120 tx.V, tx.R, tx.S, 121 }) 122 return hash 123 } 124 125 func (tx *AccessListTx) rawSignatureValues() (v, r, s *uint256.Int) { 126 return tx.V, tx.R, tx.S 127 } 128 129 func (tx *AccessListTx) setSignatureValues(chainID, v, r, s *uint256.Int) { 130 tx.ChainID, tx.V, tx.R, tx.S = chainID, v, r, s 131 }