From 016b30eb7d3e7a2d76071fd4943e68c05de63249 Mon Sep 17 00:00:00 2001 From: maskpp Date: Fri, 2 Dec 2022 10:46:26 +0800 Subject: [PATCH] refactor(trace): move `TransactionData` into l2trace.go (#189) combine trace_block.go --- core/types/l2trace.go | 44 ++++++++++++++++++++++++++++++++ core/types/l2trace_block.go | 51 ------------------------------------- 2 files changed, 44 insertions(+), 51 deletions(-) delete mode 100644 core/types/l2trace_block.go diff --git a/core/types/l2trace.go b/core/types/l2trace.go index 99e34a64b2..7fa0890930 100644 --- a/core/types/l2trace.go +++ b/core/types/l2trace.go @@ -2,11 +2,13 @@ package types import ( "encoding/json" + "math/big" "runtime" "sync" "github.com/scroll-tech/go-ethereum/common" "github.com/scroll-tech/go-ethereum/common/hexutil" + "github.com/scroll-tech/go-ethereum/params" ) var ( @@ -145,3 +147,45 @@ type StorageWrapper struct { Key string `json:"key,omitempty"` Value string `json:"value,omitempty"` } + +type TransactionData struct { + Type uint8 `json:"type"` + Nonce uint64 `json:"nonce"` + TxHash string `json:"txHash"` + Gas uint64 `json:"gas"` + GasPrice *hexutil.Big `json:"gasPrice"` + From common.Address `json:"from"` + To *common.Address `json:"to"` + ChainId *hexutil.Big `json:"chainId"` + Value *hexutil.Big `json:"value"` + Data string `json:"data"` + IsCreate bool `json:"isCreate"` + V *hexutil.Big `json:"v"` + R *hexutil.Big `json:"r"` + S *hexutil.Big `json:"s"` +} + +// NewTraceTransaction returns a transaction that will serialize to the trace +// representation, with the given location metadata set (if available). +func NewTraceTransaction(tx *Transaction, blockNumber uint64, config *params.ChainConfig) *TransactionData { + signer := MakeSigner(config, big.NewInt(0).SetUint64(blockNumber)) + from, _ := Sender(signer, tx) + v, r, s := tx.RawSignatureValues() + result := &TransactionData{ + Type: tx.Type(), + TxHash: tx.Hash().String(), + Nonce: tx.Nonce(), + ChainId: (*hexutil.Big)(tx.ChainId()), + From: from, + Gas: tx.Gas(), + GasPrice: (*hexutil.Big)(tx.GasPrice()), + To: tx.To(), + Value: (*hexutil.Big)(tx.Value()), + Data: hexutil.Encode(tx.Data()), + IsCreate: tx.To() == nil, + V: (*hexutil.Big)(v), + R: (*hexutil.Big)(r), + S: (*hexutil.Big)(s), + } + return result +} diff --git a/core/types/l2trace_block.go b/core/types/l2trace_block.go deleted file mode 100644 index 71a5d8c10e..0000000000 --- a/core/types/l2trace_block.go +++ /dev/null @@ -1,51 +0,0 @@ -package types - -import ( - "math/big" - - "github.com/scroll-tech/go-ethereum/common" - "github.com/scroll-tech/go-ethereum/common/hexutil" - "github.com/scroll-tech/go-ethereum/params" -) - -type TransactionData struct { - Type uint8 `json:"type"` - Nonce uint64 `json:"nonce"` - TxHash string `json:"txHash"` - Gas uint64 `json:"gas"` - GasPrice *hexutil.Big `json:"gasPrice"` - From common.Address `json:"from"` - To *common.Address `json:"to"` - ChainId *hexutil.Big `json:"chainId"` - Value *hexutil.Big `json:"value"` - Data string `json:"data"` - IsCreate bool `json:"isCreate"` - V *hexutil.Big `json:"v"` - R *hexutil.Big `json:"r"` - S *hexutil.Big `json:"s"` -} - -// NewTraceTransaction returns a transaction that will serialize to the trace -// representation, with the given location metadata set (if available). -func NewTraceTransaction(tx *Transaction, blockNumber uint64, config *params.ChainConfig) *TransactionData { - signer := MakeSigner(config, big.NewInt(0).SetUint64(blockNumber)) - from, _ := Sender(signer, tx) - v, r, s := tx.RawSignatureValues() - result := &TransactionData{ - Type: tx.Type(), - TxHash: tx.Hash().String(), - Nonce: tx.Nonce(), - ChainId: (*hexutil.Big)(tx.ChainId()), - From: from, - Gas: tx.Gas(), - GasPrice: (*hexutil.Big)(tx.GasPrice()), - To: tx.To(), - Value: (*hexutil.Big)(tx.Value()), - Data: hexutil.Encode(tx.Data()), - IsCreate: tx.To() == nil, - V: (*hexutil.Big)(v), - R: (*hexutil.Big)(r), - S: (*hexutil.Big)(s), - } - return result -}