Skip to content

Commit

Permalink
Add transaction in block method.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Sep 16, 2022
1 parent 1a67d68 commit 7e2be37
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
37 changes: 37 additions & 0 deletions jsonrpc/transactioninblock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright © 2022 Attestant Limited.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package jsonrpc

import (
"context"
"fmt"

"github.com/attestantio/go-execution-client/spec"
"github.com/attestantio/go-execution-client/types"
"github.com/pkg/errors"
)

// TransactionInBlock returns the transaction for the given transaction in a block at the given index.
func (s *Service) TransactionInBlock(ctx context.Context, blockHash types.Hash, index uint32) (*spec.Transaction, error) {
if len(blockHash) == 0 {
return nil, errors.New("hash nil")
}

var transaction spec.Transaction
if err := s.client.CallFor(&transaction, "eth_getTransactionByBlockHashAndIndex", fmt.Sprintf("%#x", blockHash), fmt.Sprintf("%#x", index)); err != nil {
return nil, err
}

return &transaction, nil
}
3 changes: 3 additions & 0 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ type SyncingProvider interface {
type TransactionsProvider interface {
// Transaction returns the transaction for the given transaction hash.
Transaction(ctx context.Context, hash types.Hash) (*spec.Transaction, error)

// TransactionInBlock returns the transaction for the given transaction in a block at the given index.
TransactionInBlock(ctx context.Context, blockHash types.Hash, index uint32) (*spec.Transaction, error)
}

// TransactionReceiptsProvider is the interface for providing transaction receipts.
Expand Down

0 comments on commit 7e2be37

Please sign in to comment.