Skip to content

Commit

Permalink
golint and handle transaction not found
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Seiler authored and Michael Seiler committed Jun 7, 2024
1 parent bed8908 commit d79644a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 32 deletions.
2 changes: 1 addition & 1 deletion api/api_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ type FullNode interface {
// Replays all transactions in a block returning the requested traces for each transaction
EthTraceReplayBlockTransactions(ctx context.Context, blkNum string, traceTypes []string) ([]*ethtypes.EthTraceReplayBlockTransaction, error) //perm:read

// Implmements OpenEthereum-compatible API method trace_transaction
// Implmements OpenEthereum-compatible API method trace_transaction
EthTraceTransaction(ctx context.Context, txHash string) (*[]ethtypes.EthTraceTransaction, error) //perm:read

// CreateBackup creates node backup onder the specified file name. The
Expand Down
10 changes: 5 additions & 5 deletions chain/types/ethtypes/eth_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1012,11 +1012,11 @@ type EthTraceReplayBlockTransaction struct {
}

type EthTraceTransaction struct {
*EthTrace
BlockHash EthHash `json:"blockHash"`
BlockNumber int64 `json:"blockNumber"`
TransactionHash EthHash `json:"transactionHash"`
TransactionPosition int `json:"transactionPosition"`
*EthTrace
BlockHash EthHash `json:"blockHash"`
BlockNumber int64 `json:"blockNumber"`
TransactionHash EthHash `json:"transactionHash"`
TransactionPosition int `json:"transactionPosition"`
}

type EthCallTraceAction struct {
Expand Down
9 changes: 0 additions & 9 deletions gateway/proxy_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,18 +626,9 @@ func (gw *Node) EthTraceTransaction(ctx context.Context, txHash string) (*[]etht
return nil, err
}

/*
TODO - implement checkTransaction
if err := gw.checkTransaction(ctx, txHash); err != nil {
return nil, err
}
*/

return gw.target.EthTraceTransaction(ctx, txHash)
}


var EthMaxFiltersPerConn = 16 // todo make this configurable

func addUserFilterLimited(ctx context.Context, cb func() (ethtypes.EthFilterID, error)) (ethtypes.EthFilterID, error) {
Expand Down
1 change: 0 additions & 1 deletion node/impl/full/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ func (e *EthModuleDummy) EthTraceTransaction(ctx context.Context, txHash string)
return nil, ErrModuleDisabled
}


var _ EthModuleAPI = &EthModuleDummy{}
var _ EthEventAPI = &EthModuleDummy{}

Expand Down
36 changes: 20 additions & 16 deletions node/impl/full/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,35 +980,39 @@ func (a *EthModule) EthTraceReplayBlockTransactions(ctx context.Context, blkNum
func (a *EthModule) EthTraceTransaction(ctx context.Context, txHash string) (*[]ethtypes.EthTraceTransaction, error) {

// convert from string to internal type
ethTxHash, err := ethtypes.ParseEthHash(txHash);
ethTxHash, err := ethtypes.ParseEthHash(txHash)
if err != nil {
return nil, xerrors.Errorf("cannot parse eth hash: %w", err)
}

tx, err := a.EthGetTransactionByHash(ctx, &ethTxHash);
tx, err := a.EthGetTransactionByHash(ctx, &ethTxHash)
if err != nil {
return nil, xerrors.Errorf("cannot get transaction by hash: %w", err)
}

blockTraces, err := a.EthTraceBlock(ctx, strconv.FormatUint(uint64(*tx.BlockNumber),10));
if tx == nil {
return nil, xerrors.Errorf("transaction not found")
}

blockTraces, err := a.EthTraceBlock(ctx, strconv.FormatUint(uint64(*tx.BlockNumber), 10))
if err != nil {
return nil, xerrors.Errorf("cannot get trace for block: %w", err)
}

txTraces := make([]ethtypes.EthTraceTransaction, 0, len(blockTraces))
for _, blockTrace := range blockTraces {
if blockTrace.TransactionHash == ethTxHash {
// Create a new EthTraceTransaction from the block trace
txTrace := ethtypes.EthTraceTransaction{
EthTrace: blockTrace.EthTrace,
BlockHash: blockTrace.BlockHash,
BlockNumber: blockTrace.BlockNumber,
TransactionHash: blockTrace.TransactionHash,
TransactionPosition: blockTrace.TransactionPosition,
}
txTraces = append(txTraces, txTrace)
}
}
for _, blockTrace := range blockTraces {
if blockTrace.TransactionHash == ethTxHash {
// Create a new EthTraceTransaction from the block trace
txTrace := ethtypes.EthTraceTransaction{
EthTrace: blockTrace.EthTrace,
BlockHash: blockTrace.BlockHash,
BlockNumber: blockTrace.BlockNumber,
TransactionHash: blockTrace.TransactionHash,
TransactionPosition: blockTrace.TransactionPosition,
}
txTraces = append(txTraces, txTrace)
}
}

return &txTraces, nil
}
Expand Down

0 comments on commit d79644a

Please sign in to comment.