-
Notifications
You must be signed in to change notification settings - Fork 39
/
interface.go
52 lines (40 loc) · 3.15 KB
/
interface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package ethadapter
import (
"context"
"math/big"
"github.com/ten-protocol/go-ten/go/common"
"github.com/ethereum/go-ethereum"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
)
// EthClient defines the interface for RPC communications with the ethereum nodes
// todo (#1617) - some of these methods are composed calls that should be decoupled in the future (ie: BlocksBetween or IsBlockAncestor)
type EthClient interface {
BlockNumber() (uint64, error) // retrieves the number of the head block
BlockByHash(id gethcommon.Hash) (*types.Block, error) // retrieves a block given a hash
BlockByNumber(n *big.Int) (*types.Block, error) // retrieves a block given a number - returns head block if n is nil
SendTransaction(signedTx *types.Transaction) error // issues an ethereum transaction (expects signed tx)
TransactionReceipt(hash gethcommon.Hash) (*types.Receipt, error) // fetches the ethereum transaction receipt
Nonce(address gethcommon.Address) (uint64, error) // fetches the account nonce to use in the next transaction
BalanceAt(account gethcommon.Address, blockNumber *big.Int) (*big.Int, error) // fetches the balance of the account
GetLogs(q ethereum.FilterQuery) ([]types.Log, error) // fetches the logs for a given query
Info() Info // retrieves the node Info
FetchHeadBlock() (*types.Block, error) // retrieves the block at head height
BlocksBetween(block *types.Block, head *types.Block) []*types.Block // returns the blocks between two blocks
IsBlockAncestor(block *types.Block, proof common.L1BlockHash) bool // returns if the node considers a block the ancestor
BlockListener() (chan *types.Header, ethereum.Subscription) // subscribes to new blocks and returns a listener with the blocks heads and the subscription handler
CallContract(msg ethereum.CallMsg) ([]byte, error) // Runs the provided call message on the latest block.
// PrepareTransactionToSend updates the tx with from address, current nonce and current estimates for the gas and the gas price
PrepareTransactionToSend(ctx context.Context, txData types.TxData, from gethcommon.Address) (types.TxData, error)
PrepareTransactionToRetry(ctx context.Context, txData types.TxData, from gethcommon.Address, nonce uint64, retries int) (types.TxData, error)
FetchLastBatchSeqNo(address gethcommon.Address) (*big.Int, error)
Stop() // tries to cleanly stop the client and release any resources
EthClient() *ethclient.Client // returns the underlying eth client
ReconnectIfClosed() error // closes and creates a new connection
Alive() bool // returns whether the connection is live or not
}
// Info forces the RPC EthClient to return the data in the same format (independently of its implementation)
type Info struct {
L2ID gethcommon.Address // the address of the Obscuro node this client is dedicated to
}