forked from okx/xlayer-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.go
47 lines (38 loc) · 1.19 KB
/
debug.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
package jsonrpc
import (
"context"
"errors"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/hermeznetwork/hermez-core/state"
)
// Debug is the debug jsonrpc endpoint
type Debug struct {
state stateInterface
}
type traceTransactionResponse struct {
Gas uint64 `json:"gas"`
Failed bool `json:"failed"`
ReturnValue string `json:"returnValue"`
StructLogs []interface{} `json:"structLogs"`
}
// TraceTransaction creates a response for debug_traceTransaction request.
// See https://geth.ethereum.org/docs/rpc/ns-debug#debug_tracetransaction
func (d *Debug) TraceTransaction(hash common.Hash) (interface{}, error) {
ctx := context.Background()
tx, err := d.state.GetTransactionByHash(ctx, hash, "")
if errors.Is(err, state.ErrNotFound) {
return genesisIsNotTraceableError{}, nil
}
rcpt, err := d.state.GetTransactionReceipt(ctx, hash, "")
if errors.Is(err, state.ErrNotFound) {
return genesisIsNotTraceableError{}, nil
}
resp := traceTransactionResponse{
Gas: tx.Gas(),
Failed: rcpt.Status == types.ReceiptStatusFailed,
ReturnValue: "",
StructLogs: []interface{}{},
}
return resp, nil
}