hermez-node/eth/client.go
eth/client.goRaw
1package eth
2
3import (
4 "fmt"
5
6 "github.com/ethereum/go-ethereum/accounts"
7 ethKeystore "github.com/ethereum/go-ethereum/accounts/keystore"
8 ethCommon "github.com/ethereum/go-ethereum/common"
9 "github.com/ethereum/go-ethereum/ethclient"
10)
11
12var errTODO = fmt.Errorf("TODO: Not implemented yet")
13
14// ClientInterface is the eth Client interface used by hermez-node modules to
15// interact with Ethereum Blockchain and smart contracts.
16type ClientInterface interface {
17 EthereumInterface
18 RollupInterface
19 AuctionInterface
20}
21
22//
23// Implementation
24//
25
26// Client is used to interact with Ethereum and the Hermez smart contracts.
27type Client struct {
28 EthereumClient
29 AuctionClient
30 RollupClient
31}
32
33// TokenConfig is used to define the information about token
34type TokenConfig struct {
35 Address ethCommon.Address
36 Name string
37}
38
39// RollupConfig is the configuration for the Rollup smart contract interface
40type RollupConfig struct {
41 Address ethCommon.Address
42}
43
44// AuctionConfig is the configuration for the Auction smart contract interface
45type AuctionConfig struct {
46 Address ethCommon.Address
47 TokenHEZ TokenConfig
48}
49
50// ClientConfig is the configuration of the Client
51type ClientConfig struct {
52 Ethereum EthereumConfig
53 Rollup RollupConfig
54 Auction AuctionConfig
55}
56
57// NewClient creates a new Client to interact with Ethereum and the Hermez smart contracts.
58func NewClient(client *ethclient.Client, account *accounts.Account, ks *ethKeystore.KeyStore, cfg *ClientConfig) (*Client, error) {
59 ethereumClient := NewEthereumClient(client, account, ks, &cfg.Ethereum)
60 auctionClient, err := NewAuctionClient(ethereumClient, cfg.Auction.Address, cfg.Auction.TokenHEZ)
61 if err != nil {
62 return nil, err
63 }
64 rollupCient, err := NewRollupClient(ethereumClient, cfg.Rollup.Address, cfg.Auction.TokenHEZ)
65 if err != nil {
66 return nil, err
67 }
68 return &Client{
69 EthereumClient: *ethereumClient,
70 AuctionClient: *auctionClient,
71 RollupClient: *rollupCient,
72 }, nil
73}