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.

86 lines
2.3 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. WDelayerInterface
  17. }
  18. //
  19. // Implementation
  20. //
  21. // Client is used to interact with Ethereum and the Hermez smart contracts.
  22. type Client struct {
  23. EthereumClient
  24. AuctionClient
  25. RollupClient
  26. WDelayerClient
  27. }
  28. // TokenConfig is used to define the information about token
  29. type TokenConfig struct {
  30. Address ethCommon.Address
  31. Name string
  32. }
  33. // RollupConfig is the configuration for the Rollup smart contract interface
  34. type RollupConfig struct {
  35. Address ethCommon.Address
  36. }
  37. // AuctionConfig is the configuration for the Auction smart contract interface
  38. type AuctionConfig struct {
  39. Address ethCommon.Address
  40. TokenHEZ TokenConfig
  41. }
  42. // WDelayerConfig is the configuration for the WDelayer smart contract interface
  43. type WDelayerConfig struct {
  44. Address ethCommon.Address
  45. }
  46. // ClientConfig is the configuration of the Client
  47. type ClientConfig struct {
  48. Ethereum EthereumConfig
  49. Rollup RollupConfig
  50. Auction AuctionConfig
  51. WDelayer WDelayerConfig
  52. }
  53. // NewClient creates a new Client to interact with Ethereum and the Hermez smart contracts.
  54. func NewClient(client *ethclient.Client, account *accounts.Account, ks *ethKeystore.KeyStore, cfg *ClientConfig) (*Client, error) {
  55. ethereumClient := NewEthereumClient(client, account, ks, &cfg.Ethereum)
  56. auctionClient, err := NewAuctionClient(ethereumClient, cfg.Auction.Address, cfg.Auction.TokenHEZ)
  57. if err != nil {
  58. return nil, err
  59. }
  60. rollupClient, err := NewRollupClient(ethereumClient, cfg.Rollup.Address, cfg.Auction.TokenHEZ)
  61. if err != nil {
  62. return nil, err
  63. }
  64. wDelayerClient, err := NewWDelayerClient(ethereumClient, cfg.WDelayer.Address)
  65. if err != nil {
  66. return nil, err
  67. }
  68. return &Client{
  69. EthereumClient: *ethereumClient,
  70. AuctionClient: *auctionClient,
  71. RollupClient: *rollupClient,
  72. WDelayerClient: *wDelayerClient,
  73. }, nil
  74. }