2020-08-29 15:50:24 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-10-02 12:52:02 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/params"
|
2020-08-29 15:50:24 +00:00
|
|
|
|
2020-09-25 12:12:36 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/cmd/rpcdaemon/cli"
|
2020-08-29 15:50:24 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/common/hexutil"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/core/rawdb"
|
2020-09-25 12:12:36 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/core/types"
|
2020-08-29 15:50:24 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
2020-09-25 12:12:36 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/rpc"
|
2020-08-29 15:50:24 +00:00
|
|
|
)
|
|
|
|
|
2020-09-25 12:12:36 +00:00
|
|
|
// TraceAPI RPC interface into tracing API
|
2020-08-29 15:50:24 +00:00
|
|
|
type TraceAPI interface {
|
2020-09-25 12:12:36 +00:00
|
|
|
// Ad-hoc
|
2020-09-26 06:41:34 +00:00
|
|
|
ReplayBlockTransactions(ctx context.Context, blockNr rpc.BlockNumber, traceTypes []string) ([]interface{}, error)
|
|
|
|
ReplayTransaction(ctx context.Context, txHash common.Hash, traceTypes []string) ([]interface{}, error)
|
|
|
|
Call(ctx context.Context, call CallParam, blockNr rpc.BlockNumber) ([]interface{}, error)
|
|
|
|
CallMany(ctx context.Context, calls CallParams) ([]interface{}, error)
|
|
|
|
RawTransaction(ctx context.Context, txHash common.Hash, traceTypes []string) ([]interface{}, error)
|
2020-09-25 12:12:36 +00:00
|
|
|
|
|
|
|
// Filtering
|
|
|
|
Transaction(ctx context.Context, txHash common.Hash) (ParityTraces, error)
|
|
|
|
Get(ctx context.Context, txHash common.Hash, txIndicies []hexutil.Uint64) (*ParityTrace, error)
|
|
|
|
Block(ctx context.Context, blockNr rpc.BlockNumber) (ParityTraces, error)
|
|
|
|
Filter(ctx context.Context, req TraceFilterRequest) (ParityTraces, error)
|
|
|
|
|
|
|
|
// Custom (turbo geth exclusive)
|
|
|
|
BlockReward(ctx context.Context, blockNr rpc.BlockNumber) (Issuance, error)
|
|
|
|
UncleReward(ctx context.Context, blockNr rpc.BlockNumber) (Issuance, error)
|
|
|
|
Issuance(ctx context.Context, blockNr rpc.BlockNumber) (Issuance, error)
|
2020-08-29 15:50:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TraceAPIImpl is implementation of the TraceAPI interface based on remote Db access
|
|
|
|
type TraceAPIImpl struct {
|
2020-10-02 12:52:02 +00:00
|
|
|
db ethdb.KV
|
|
|
|
dbReader ethdb.Getter
|
|
|
|
maxTraces uint64
|
|
|
|
traceType string
|
|
|
|
chainConfig *params.ChainConfig
|
2020-08-29 15:50:24 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 12:12:36 +00:00
|
|
|
// NewTraceAPI returns NewTraceAPI instance
|
2020-10-02 12:52:02 +00:00
|
|
|
func NewTraceAPI(db ethdb.KV, dbReader ethdb.Getter, cfg *cli.Flags, chainConfig *params.ChainConfig) *TraceAPIImpl {
|
2020-08-29 15:50:24 +00:00
|
|
|
return &TraceAPIImpl{
|
2020-10-02 12:52:02 +00:00
|
|
|
db: db,
|
|
|
|
dbReader: dbReader,
|
|
|
|
maxTraces: cfg.MaxTraces,
|
|
|
|
traceType: cfg.TraceType,
|
|
|
|
chainConfig: chainConfig,
|
2020-08-29 15:50:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-25 12:12:36 +00:00
|
|
|
func (api *TraceAPIImpl) getBlockByRPCNumber(blockNr rpc.BlockNumber) (*types.Block, error) {
|
|
|
|
blockNum, err := getBlockNumber(blockNr, api.dbReader)
|
|
|
|
if err != nil {
|
2020-08-29 15:50:24 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2020-09-25 12:12:36 +00:00
|
|
|
return rawdb.ReadBlockByNumber(api.dbReader, blockNum), nil
|
2020-08-29 15:50:24 +00:00
|
|
|
}
|