You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

67 lines
1.8 KiB

package eth
import (
"fmt"
"github.com/ethereum/go-ethereum/accounts"
ethKeystore "github.com/ethereum/go-ethereum/accounts/keystore"
ethCommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
)
var errTODO = fmt.Errorf("TODO: Not implemented yet")
// ClientInterface is the eth Client interface used by hermez-node modules to
// interact with Ethereum Blockchain and smart contracts.
type ClientInterface interface {
EthereumInterface
RollupInterface
AuctionInterface
}
//
// Implementation
//
// Client is used to interact with Ethereum and the Hermez smart contracts.
type Client struct {
EthereumClient
AuctionClient
RollupClient
}
// RollupConfig is the configuration for the Rollup smart contract interface
type RollupConfig struct {
Address ethCommon.Address
}
// AuctionConfig is the configuration for the Auction smart contract interface
type AuctionConfig struct {
Address ethCommon.Address
TokenHEZAddress ethCommon.Address
}
// ClientConfig is the configuration of the Client
type ClientConfig struct {
Ethereum EthereumConfig
Rollup RollupConfig
Auction AuctionConfig
}
// NewClient creates a new Client to interact with Ethereum and the Hermez smart contracts.
func NewClient(client *ethclient.Client, account *accounts.Account, ks *ethKeystore.KeyStore, cfg *ClientConfig) (*Client, error) {
ethereumClient := NewEthereumClient(client, account, ks, &cfg.Ethereum)
auctionClient, err := NewAuctionClient(ethereumClient, cfg.Auction.Address, cfg.Auction.TokenHEZAddress)
if err != nil {
return nil, err
}
rollupCient, err := NewRollupClient(ethereumClient, cfg.Rollup.Address, cfg.Auction.TokenHEZAddress)
if err != nil {
return nil, err
}
return &Client{
EthereumClient: *ethereumClient,
AuctionClient: *auctionClient,
RollupClient: *rollupCient,
}, nil
}