mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-10 05:53:46 +00:00
refactor(trace): move TransactionData into l2trace.go (#189)
combine trace_block.go
This commit is contained in:
parent
4ea77a7577
commit
016b30eb7d
2 changed files with 44 additions and 51 deletions
|
|
@ -2,11 +2,13 @@ package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"math/big"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/scroll-tech/go-ethereum/common"
|
"github.com/scroll-tech/go-ethereum/common"
|
||||||
"github.com/scroll-tech/go-ethereum/common/hexutil"
|
"github.com/scroll-tech/go-ethereum/common/hexutil"
|
||||||
|
"github.com/scroll-tech/go-ethereum/params"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -145,3 +147,45 @@ type StorageWrapper struct {
|
||||||
Key string `json:"key,omitempty"`
|
Key string `json:"key,omitempty"`
|
||||||
Value string `json:"value,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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
Loading…
Reference in a new issue