Skip to content

Commit

Permalink
feat: support customized trace config and block hash (#126)
Browse files Browse the repository at this point in the history
* feat: support customized trace config and block hash

Signed-off-by: Jingfu Wang <[email protected]>

* test: fix CI

Signed-off-by: Jingfu Wang <[email protected]>

---------

Signed-off-by: Jingfu Wang <[email protected]>
  • Loading branch information
GeekArthur authored Jul 29, 2024
1 parent 0e198c3 commit 3b6a8e4
Show file tree
Hide file tree
Showing 8 changed files with 393 additions and 35 deletions.
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

0 comments on commit 3b6a8e4

Please sign in to comment.