ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
我们对比ethereum和ep的transaction的数据结构: 下面是ethereum的transaction的数据结构: ~~~ type Transaction struct { inner TxData // Consensus contents of a transaction time time.Time // Time first seen locally (spam avoidance) // caches hash atomic.Value size atomic.Value from atomic.Value } ~~~ 其中txData数据结构有三种实现:DynamicFeeTx, LegacyTx and AccessListTx. ~~~ type DynamicFeeTx struct { ChainID *big.Int Nonce uint64 GasTipCap *big.Int // a.k.a. maxPriorityFeePerGas GasFeeCap *big.Int // a.k.a. maxFeePerGas Gas uint64 To *common.Address `rlp:"nil"` // nil means contract creation Value *big.Int Data []byte AccessList AccessList // Signature values //`r and s are outputs of an ECDSA signature, and`v`is the recovery id V *big.Int `json:"v" gencodec:"required"` R *big.Int `json:"r" gencodec:"required"` S *big.Int `json:"s" gencodec:"required"` } ~~~ ~~~ // LegacyTx is the transaction data of regular Ethereum transactions. type LegacyTx struct { Nonce uint64 // nonce of sender account GasPrice *big.Int // wei per gas Gas uint64 // gas limit To *common.Address `rlp:"nil"` // nil means contract creation Value *big.Int // wei amount Data []byte // contract invocation input data V, R, S *big.Int // signature values } ~~~ ~~~ // AccessListTx is the data of EIP-2930 access list transactions. type AccessListTx struct { ChainID *big.Int // destination chain ID Nonce uint64 // nonce of sender account GasPrice *big.Int // wei per gas Gas uint64 // gas limit To *common.Address `rlp:"nil"` // nil means contract creation Value *big.Int // wei amount Data []byte // contract invocation input data AccessList AccessList // EIP-2930 access list V, R, S *big.Int // signature values } ~~~ 其中LegacyTx是历史上的ethereum的结构,他们还是有些区别,其它两种都与协议有关。另外,最开始的ethereum的transaction结构是没有chainID的。 我们看看ep的transaction数据结构: ~~~ type Transaction struct { Nonce uint64 GasPrice *big.Int Gas uint64 To *Address Value *big.Int Input []byte V *big.Int R *big.Int S *big.Int Hash Hash From Address // Cache size atomic.Value } ~~~ 这个结构与上面的LegacyTx相比,多了From字段和Cache字段,对比其它的结构,对跨链数据交换影响不大(以太坊必须向后兼容LegacyTx)。 下面是对transaction的关键字段的说明: 1. **nonce**: The number of transaction serial numbers sent by this account (which can be roughly understood as “this is the first transaction of this account”). 2. **gasPrice**: The fee (measured in Wei) paid per unit of gas to perform this transaction and perform calculations. 3. **gasLimit**: The maximum amount of gas that can be used when executing this transaction. 4. **to**: If this transaction is used to send ether, here is the EOA address that receives ether; if this transaction is used to send a message to the contract (for example, calling a method in a smart contract), here is the address of the contract; if this The transaction is used to create the contract, here the value is empty. 5. **value**: If this transaction is used to send and receive ether, here is the amount of tokens measured in Wei in the receiving account; if this transaction is used to send a message call to the contract, here is the amount of Wei paid to the smart contract that receives this message ; if this transaction is used to create a contract, here is the amount of ether in Wei stored in the account when the contract was initialized. 6. **v, r, s**: Values ​​used in the cryptographic signature of the transaction, which can be used to determine the sender of the transaction. 7. **data**(only used for value transfer and sending message calls to smart contracts) input data that accompanies the message call (for example, if you want to execute a setter method in a smart contract, the data field should include the identifier of the setter method, and the parameter value you want to set). All transactions in the block are also stored in the Merkle tree. And the root node hash value of this tree is saved by the block header!