Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support customized trace config and block hash #126

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ import (
)

type SDKClient struct {
P *params.ChainConfig
tc *tracers.TraceConfig
P *params.ChainConfig
tc *tracers.TraceConfig
customizedTc interface{}

rosettaConfig configuration.RosettaConfig

Expand Down Expand Up @@ -79,9 +80,15 @@ func NewClient(cfg *configuration.Configuration, rpcClient *RPCClient) (*SDKClie
return nil, fmt.Errorf("unable to load trace config: %w", err)
}

var customizedTc interface{}
if cfg.RosettaCfg.SupportCustomizedTraceConfig {
customizedTc = cfg.RosettaCfg.CustomizedTraceConfig
}

return &SDKClient{
P: cfg.ChainConfig,
tc: tc,
customizedTc: customizedTc,
rosettaConfig: cfg.RosettaCfg,
RPCClient: c,
EthClient: ec,
Expand Down Expand Up @@ -411,7 +418,12 @@ func (ec *SDKClient) TraceBlockByHash(

var calls []*rpcCall
var raw json.RawMessage
err := ec.CallContext(ctx, &raw, "debug_traceBlockByHash", blockHash, ec.tc)
var err error
if ec.rosettaConfig.SupportCustomizedTraceConfig {
err = ec.CallContext(ctx, &raw, "debug_traceBlockByHash", blockHash, ec.customizedTc)
} else {
err = ec.CallContext(ctx, &raw, "debug_traceBlockByHash", blockHash, ec.tc)
}
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -938,6 +950,14 @@ func (ec *SDKClient) GetLoadedTransaction(
return loadedTx, nil
}

func (ec *SDKClient) GetBlockHash(ctx context.Context, blockIdentifier RosettaTypes.BlockIdentifier) (string, error) {
return blockIdentifier.Hash, nil
}

func (ec *SDKClient) SkipTxReceiptParsing(contractAddress string) bool {
return false
}

///////////////////////////////////////////////////////////////////////////
// Below are functions that should be implemented by chain specific Rosetta
///////////////////////////////////////////////////////////////////////////
Expand Down
6 changes: 6 additions & 0 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ type RosettaConfig struct {

// PriorityFeeDivisor is the divisor of priority fee for EIP-1559
PriorityFeeDivisor *big.Int

// SupportCustomizedTraceConfig indicates if the blockchain supports customized trace config
SupportCustomizedTraceConfig bool

// CustomizedTraceConfig is the blockchain customized trace config
CustomizedTraceConfig interface{}
}

type Token struct {
Expand Down
25 changes: 23 additions & 2 deletions mocks/client/graph_ql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 23 additions & 1 deletion mocks/client/jsonrpc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading