feat(tx): revert tx trace struct (#186)

revert tx trace struct
This commit is contained in:
maskpp 2022-11-25 10:56:12 +08:00 committed by GitHub
parent 0bdd2e0575
commit 4ea77a7577
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 10 deletions

View file

@ -4,13 +4,25 @@ 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 {
IsCreate bool `json:"isCreate"`
From common.Address `json:"from"`
Transaction
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
@ -18,9 +30,22 @@ type TransactionData struct {
func NewTraceTransaction(tx *Transaction, blockNumber uint64, config *params.ChainConfig) *TransactionData {
signer := MakeSigner(config, big.NewInt(0).SetUint64(blockNumber))
from, _ := Sender(signer, tx)
return &TransactionData{
From: from,
IsCreate: tx.To() == nil,
Transaction: *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
}

View file

@ -131,7 +131,7 @@ func checkChainAndProof(t *testing.T, b *testBackend, parent *types.Block, block
storageProof := blockTrace.StorageTrace.StorageProofs
for _, tx := range blockTrace.Transactions {
for _, addr := range []common.Address{tx.From, *tx.To()} {
for _, addr := range []common.Address{tx.From, *tx.To} {
// verify proofs
if data2, ok := storgeTrace.Proofs[addr.String()]; ok {
data1, err := statedb.GetProof(addr)
@ -154,8 +154,8 @@ func checkTxs(t *testing.T, expect []*types.Transaction, actual []*types.Transac
assert.Equal(t, len(expect), len(actual))
for i := range expect {
eTx, aTx := expect[i], actual[i]
assert.Equal(t, eTx.Hash().String(), aTx.Hash())
assert.Equal(t, eTx.Gas(), aTx.Gas())
assert.Equal(t, eTx.Hash().String(), aTx.TxHash)
assert.Equal(t, eTx.Gas(), aTx.Gas)
}
}