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

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