mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
feat: add to AccountProof to trace (#98)
* init to * update * fix `to` address * fix * fix * refactor
This commit is contained in:
parent
6e872d0826
commit
571dcad4be
3 changed files with 33 additions and 5 deletions
|
|
@ -1375,16 +1375,30 @@ func (bc *BlockChain) writeBlockResult(state *state.StateDB, block *types.Block,
|
|||
blockResult.BlockTrace = types.NewTraceBlock(bc.chainConfig, block, &coinbase)
|
||||
for i, tx := range block.Transactions() {
|
||||
evmTrace := blockResult.ExecutionResults[i]
|
||||
from := evmTrace.Sender.Address
|
||||
|
||||
from := evmTrace.From.Address
|
||||
// Get proof
|
||||
proof, err := state.GetProof(from)
|
||||
if err != nil {
|
||||
log.Error("Failed to get proof", "blockNumber", block.NumberU64(), "address", from.String(), "err", err)
|
||||
} else {
|
||||
evmTrace.Sender.Proof = make([]string, len(proof))
|
||||
evmTrace.From.Proof = make([]string, len(proof))
|
||||
for i := range proof {
|
||||
evmTrace.Sender.Proof[i] = hexutil.Encode(proof[i])
|
||||
evmTrace.From.Proof[i] = hexutil.Encode(proof[i])
|
||||
}
|
||||
}
|
||||
|
||||
if evmTrace.To != nil {
|
||||
to := evmTrace.To.Address
|
||||
// Get proof
|
||||
proof, err = state.GetProof(to)
|
||||
if err != nil {
|
||||
log.Error("Failed to get proof", "blockNumber", block.NumberU64(), "address", to.String(), "err", err)
|
||||
} else {
|
||||
evmTrace.To.Proof = make([]string, len(proof))
|
||||
for i := range proof {
|
||||
evmTrace.To.Proof[i] = hexutil.Encode(proof[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,9 @@ type ExecutionResult struct {
|
|||
Failed bool `json:"failed"`
|
||||
ReturnValue string `json:"returnValue,omitempty"`
|
||||
// Sender's account proof.
|
||||
Sender *AccountProofWrapper `json:"sender,omitempty"`
|
||||
From *AccountProofWrapper `json:"from,omitempty"`
|
||||
// Receiver's account proof.
|
||||
To *AccountProofWrapper `json:"to,omitempty"`
|
||||
// It's exist only when tx is a contract call.
|
||||
CodeHash *common.Hash `json:"codeHash,omitempty"`
|
||||
// If it is a contract call, the contract code is returned.
|
||||
|
|
|
|||
|
|
@ -794,6 +794,17 @@ func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Addres
|
|||
Balance: (*hexutil.Big)(w.current.state.GetBalance(from)),
|
||||
CodeHash: w.current.state.GetCodeHash(from),
|
||||
}
|
||||
// Get receiver's address.
|
||||
var receiver *types.AccountProofWrapper
|
||||
if tx.To() != nil {
|
||||
to := *tx.To()
|
||||
receiver = &types.AccountProofWrapper{
|
||||
Address: to,
|
||||
Nonce: w.current.state.GetNonce(to),
|
||||
Balance: (*hexutil.Big)(w.current.state.GetBalance(to)),
|
||||
CodeHash: w.current.state.GetCodeHash(to),
|
||||
}
|
||||
}
|
||||
|
||||
receipt, err := core.ApplyTransaction(w.chainConfig, w.chain, &coinbase, w.current.gasPool, w.current.state, w.current.header, tx, &w.current.header.GasUsed, *w.chain.GetVMConfig())
|
||||
if err != nil {
|
||||
|
|
@ -805,7 +816,8 @@ func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Addres
|
|||
w.current.receipts = append(w.current.receipts, receipt)
|
||||
w.current.executionResults = append(w.current.executionResults, &types.ExecutionResult{
|
||||
Gas: receipt.GasUsed,
|
||||
Sender: sender,
|
||||
From: sender,
|
||||
To: receiver,
|
||||
Failed: receipt.Status != types.ReceiptStatusSuccessful,
|
||||
ReturnValue: fmt.Sprintf("%x", receipt.ReturnValue),
|
||||
StructLogs: vm.FormatLogs(tracer.StructLogs()),
|
||||
|
|
|
|||
Loading…
Reference in a new issue