-
Notifications
You must be signed in to change notification settings - Fork 179
/
api.go
50 lines (41 loc) · 1.46 KB
/
api.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
package debug
import (
"encoding/json"
sdk "github.com/okex/exchain/libs/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
clientcontext "github.com/okex/exchain/libs/cosmos-sdk/client/context"
"github.com/okex/exchain/app/rpc/backend"
"github.com/okex/exchain/libs/tendermint/libs/log"
)
// PublicTxPoolAPI offers and API for the transaction pool. It only operates on data that is non confidential.
type PublicDebugAPI struct {
clientCtx clientcontext.CLIContext
logger log.Logger
backend backend.Backend
}
// NewPublicTxPoolAPI creates a new tx pool service that gives information about the transaction pool.
func NewAPI(clientCtx clientcontext.CLIContext, log log.Logger, backend backend.Backend) *PublicDebugAPI {
api := &PublicDebugAPI{
clientCtx: clientCtx,
backend: backend,
logger: log.With("module", "json-rpc", "namespace", "debug"),
}
return api
}
// TraceTransaction returns the structured logs created during the execution of EVM
// and returns them as a JSON object.
func (api *PublicDebugAPI) TraceTransaction(txHash common.Hash) (interface{}, error) {
resTrace, _, err := api.clientCtx.QueryWithData("app/trace", txHash.Bytes())
if err != nil {
return nil, err
}
var res sdk.Result
if err := api.clientCtx.Codec.UnmarshalBinaryBare(resTrace, &res); err != nil {
return nil, err
}
var decodedResult interface{}
if err := json.Unmarshal(res.Data, &decodedResult); err != nil {
return nil, err
}
return decodedResult, nil
}