Skip to content

Commit

Permalink
Merge branch 'master' into tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrubabasu authored Feb 8, 2022
2 parents a567528 + e395e1b commit 621d5b0
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 13 deletions.
1 change: 1 addition & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Client interface {
TransactionByHash(context.Context, ethcommon.Hash) (*ethtypes.Transaction, bool, error)
TransactionReceipt(context.Context, ethcommon.Hash) (*ethtypes.Receipt, error)
TraceTransaction(context.Context, string) (*Call, []*FlatCall, error)
TraceBlockByHash(context.Context, string) ([]*Call, [][]*FlatCall, error)
SendTransaction(context.Context, *ethtypes.Transaction) error
BalanceAt(context.Context, ethcommon.Address, *big.Int) (*big.Int, error)
NonceAt(context.Context, ethcommon.Address, *big.Int) (uint64, error)
Expand Down
28 changes: 25 additions & 3 deletions client/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,35 @@ func (c *EthClient) TxPoolContent(ctx context.Context) (*TxPoolContent, error) {

// TraceTransaction returns a transaction trace
func (c *EthClient) TraceTransaction(ctx context.Context, hash string) (*Call, []*FlatCall, error) {
result := &Call{}
var result Call
args := []interface{}{hash, c.traceConfig}

err := c.rpc.SendJSONRPCRequest(ctx, prefixEth, "debug_traceTransaction", args, &result)
if err != nil {
if err := c.rpc.SendJSONRPCRequest(ctx, prefixEth, "debug_traceTransaction", args, &result); err != nil {
return nil, nil, err
}

flattened := result.init()

return &result, flattened, nil
}

// TraceBlockByHash returns the transaction traces of all transactions in the block
func (c *EthClient) TraceBlockByHash(ctx context.Context, hash string) ([]*Call, [][]*FlatCall, error) {
var raw []struct {
*Call `json:"result"`
}

args := []interface{}{hash, c.traceConfig}
if err := c.rpc.SendJSONRPCRequest(ctx, prefixEth, "debug_traceBlockByHash", args, &raw); err != nil {
return nil, nil, err
}

result := make([]*Call, len(raw))
flattened := make([][]*FlatCall, len(raw))
for i, tx := range raw {
result[i] = tx.Call
flattened[i] = tx.Call.init()
}

return result, flattened, nil
}
32 changes: 32 additions & 0 deletions mocks/client/client.go

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

28 changes: 18 additions & 10 deletions service/service_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,13 @@ func (s *BlockService) BlockTransaction(
return nil, nil
}

transaction, terr := s.fetchTransaction(ctx, tx, header)
trace, flattened, err := s.client.TraceTransaction(ctx, tx.Hash().String())
if err != nil {
return nil, wrapError(errClientError, err)
}

transaction, terr := s.fetchTransaction(ctx, tx, header, trace, flattened)
if terr != nil {
return nil, terr
}

Expand All @@ -157,11 +162,17 @@ func (s *BlockService) fetchTransactions(
) ([]*types.Transaction, *types.Error) {
transactions := []*types.Transaction{}

for _, tx := range block.Transactions() {
transaction, err := s.fetchTransaction(ctx, tx, block.Header())
if err != nil {
return nil, err
trace, flattened, err := s.client.TraceBlockByHash(ctx, block.Hash().String())
if err != nil {
return nil, wrapError(errClientError, err)
}

for i, tx := range block.Transactions() {
transaction, terr := s.fetchTransaction(ctx, tx, block.Header(), trace[i], flattened[i])
if terr != nil {
return nil, terr
}

transactions = append(transactions, transaction)
}

Expand All @@ -172,6 +183,8 @@ func (s *BlockService) fetchTransaction(
ctx context.Context,
tx *corethTypes.Transaction,
header *corethTypes.Header,
trace *client.Call,
flattened []*client.FlatCall,
) (*types.Transaction, *types.Error) {
msg, err := tx.AsMessage(s.config.Signer(), header.BaseFee)
if err != nil {
Expand All @@ -183,11 +196,6 @@ func (s *BlockService) fetchTransaction(
return nil, wrapError(errClientError, err)
}

trace, flattened, err := s.client.TraceTransaction(ctx, tx.Hash().String())
if err != nil {
return nil, wrapError(errClientError, err)
}

transaction, err := mapper.Transaction(header, tx, &msg, receipt, trace, flattened, s.client, s.config.IsAnalyticsMode(), s.config.TokenWhiteList, s.config.IndexUnknownTokens)
if err != nil {
return nil, wrapError(errInternalError, err)
Expand Down

0 comments on commit 621d5b0

Please sign in to comment.