This repository has been archived by the owner on Sep 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
call_trace.go
81 lines (72 loc) · 2.17 KB
/
call_trace.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package debug
import (
"encoding/json"
"math/big"
"github.com/celo-org/celo-blockchain/common"
"github.com/celo-org/celo-blockchain/common/hexutil"
"github.com/grassrootseconomics/w3-celo-patch/internal/module"
"github.com/grassrootseconomics/w3-celo-patch/w3types"
)
// CallTraceCall requests the call trace of the given message.
func CallTraceCall(msg *w3types.Message, blockNumber *big.Int, overrides w3types.State) w3types.CallerFactory[CallTrace] {
return module.NewFactory(
"debug_traceCall",
[]any{msg, module.BlockNumberArg(blockNumber), &traceConfig{Tracer: "callTracer", Overrides: overrides}},
module.WithArgsWrapper[CallTrace](msgArgsWrapper),
)
}
// CallTraceTx requests the call trace of the transaction with the given hash.
func CallTraceTx(txHash common.Hash, overrides w3types.State) w3types.CallerFactory[CallTrace] {
return module.NewFactory[CallTrace](
"debug_traceTransaction",
[]any{txHash, &traceConfig{Tracer: "callTracer", Overrides: overrides}},
)
}
type CallTrace struct {
From common.Address
To common.Address
Type string
Gas uint64
GasUsed uint64
Value *big.Int
Input []byte
Output []byte
Error string
Calls []*CallTrace
}
// UnmarshalJSON implements the [json.Unmarshaler].
func (c *CallTrace) UnmarshalJSON(data []byte) error {
type call struct {
From common.Address `json:"from"`
To common.Address `json:"to"`
Type string `json:"type"`
Gas hexutil.Uint64 `json:"gas"`
GasUsed hexutil.Uint64 `json:"gasUsed"`
Value *hexutil.Big `json:"value"`
Input hexutil.Bytes `json:"input"`
Output hexutil.Bytes `json:"output"`
Error string `json:"error"`
Calls []*CallTrace `json:"calls"`
}
var dec call
if err := json.Unmarshal(data, &dec); err != nil {
return err
}
c.From = dec.From
c.To = dec.To
c.Type = dec.Type
c.Gas = uint64(dec.Gas)
c.GasUsed = uint64(dec.GasUsed)
if dec.Value != nil {
c.Value = (*big.Int)(dec.Value)
}
c.Input = dec.Input
c.Output = dec.Output
c.Error = dec.Error
c.Calls = dec.Calls
return nil
}
type traceConfig struct {
Tracer string `json:"tracer"`
Overrides w3types.State `json:"stateOverrides,omitempty"`
}