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.

73 lines
1.9 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. // TokenConfig is used to define the information about token
  27. type TokenConfig struct {
  28. Address ethCommon.Address
  29. Name string
  30. }
  31. // RollupConfig is the configuration for the Rollup smart contract interface
  32. type RollupConfig struct {
  33. Address ethCommon.Address
  34. }
  35. // AuctionConfig is the configuration for the Auction smart contract interface
  36. type AuctionConfig struct {
  37. Address ethCommon.Address
  38. TokenHEZ TokenConfig
  39. }
  40. // ClientConfig is the configuration of the Client
  41. type ClientConfig struct {
  42. Ethereum EthereumConfig
  43. Rollup RollupConfig
  44. Auction AuctionConfig
  45. }
  46. // NewClient creates a new Client to interact with Ethereum and the Hermez smart contracts.
  47. func NewClient(client *ethclient.Client, account *accounts.Account, ks *ethKeystore.KeyStore, cfg *ClientConfig) (*Client, error) {
  48. ethereumClient := NewEthereumClient(client, account, ks, &cfg.Ethereum)
  49. auctionClient, err := NewAuctionClient(ethereumClient, cfg.Auction.Address, cfg.Auction.TokenHEZ)
  50. if err != nil {
  51. return nil, err
  52. }
  53. rollupCient, err := NewRollupClient(ethereumClient, cfg.Rollup.Address, cfg.Auction.TokenHEZ)
  54. if err != nil {
  55. return nil, err
  56. }
  57. return &Client{
  58. EthereumClient: *ethereumClient,
  59. AuctionClient: *auctionClient,
  60. RollupClient: *rollupCient,
  61. }, nil
  62. }