github.com/Night-mk/quorum@v21.1.0+incompatible/extension/client.go (about) 1 package extension 2 3 import ( 4 "context" 5 6 "github.com/ethereum/go-ethereum" 7 "github.com/ethereum/go-ethereum/common" 8 "github.com/ethereum/go-ethereum/core/types" 9 "github.com/ethereum/go-ethereum/ethclient" 10 ) 11 12 type Client interface { 13 SubscribeToLogs(query ethereum.FilterQuery) (<-chan types.Log, ethereum.Subscription, error) 14 NextNonce(from common.Address) (uint64, error) 15 TransactionByHash(hash common.Hash) (*types.Transaction, error) 16 TransactionInBlock(blockHash common.Hash, txIndex uint) (*types.Transaction, error) 17 } 18 19 type InProcessClient struct { 20 client *ethclient.Client 21 } 22 23 func NewInProcessClient(client *ethclient.Client) *InProcessClient { 24 return &InProcessClient{ 25 client: client, 26 } 27 } 28 29 func (client *InProcessClient) SubscribeToLogs(query ethereum.FilterQuery) (<-chan types.Log, ethereum.Subscription, error) { 30 retrievedLogsChan := make(chan types.Log) 31 sub, err := client.client.SubscribeFilterLogs(context.Background(), query, retrievedLogsChan) 32 return retrievedLogsChan, sub, err 33 } 34 35 func (client *InProcessClient) NextNonce(from common.Address) (uint64, error) { 36 return client.client.PendingNonceAt(context.Background(), from) 37 } 38 39 func (client *InProcessClient) TransactionByHash(hash common.Hash) (*types.Transaction, error) { 40 tx, _, err := client.client.TransactionByHash(context.Background(), hash) 41 return tx, err 42 } 43 44 func (client *InProcessClient) TransactionInBlock(blockHash common.Hash, txIndex uint) (*types.Transaction, error) { 45 return client.client.TransactionInBlock(context.Background(), blockHash, txIndex) 46 }