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.

51 lines
1.3 KiB

  1. package light
  2. import (
  3. "context"
  4. "github.com/tendermint/tendermint/light/provider"
  5. "github.com/tendermint/tendermint/light/provider/http"
  6. "github.com/tendermint/tendermint/light/store"
  7. )
  8. // NewHTTPClient initiates an instance of a light client using HTTP addresses
  9. // for both the primary provider and witnesses of the light client. A trusted
  10. // header and hash must be passed to initialize the client.
  11. //
  12. // See all Option(s) for the additional configuration.
  13. // See NewClient.
  14. func NewHTTPClient(
  15. ctx context.Context,
  16. chainID string,
  17. trustOptions TrustOptions,
  18. primaryAddress string,
  19. witnessesAddresses []string,
  20. trustedStore store.Store,
  21. options ...Option) (*Client, error) {
  22. providers, err := providersFromAddresses(append(witnessesAddresses, primaryAddress), chainID)
  23. if err != nil {
  24. return nil, err
  25. }
  26. return NewClient(
  27. ctx,
  28. chainID,
  29. trustOptions,
  30. providers[len(providers)-1],
  31. providers[:len(providers)-1],
  32. trustedStore,
  33. options...)
  34. }
  35. func providersFromAddresses(addrs []string, chainID string) ([]provider.Provider, error) {
  36. providers := make([]provider.Provider, len(addrs))
  37. for idx, address := range addrs {
  38. p, err := http.New(chainID, address)
  39. if err != nil {
  40. return nil, err
  41. }
  42. providers[idx] = p
  43. }
  44. return providers, nil
  45. }