diff --git a/lite2/provider/http/http.go b/lite2/provider/http/http.go index 5e9fc5192..bbe6e92ae 100644 --- a/lite2/provider/http/http.go +++ b/lite2/provider/http/http.go @@ -13,6 +13,8 @@ import ( type SignStatusClient interface { rpcclient.SignClient rpcclient.StatusClient + // Remote returns the remote network address in a string form. + Remote() string } // http provider uses an RPC client (or SignStatusClient more generally) to @@ -45,6 +47,10 @@ func (p *http) ChainID() string { return p.chainID } +func (p *http) String() string { + return fmt.Sprintf("http{%s}", p.client.Remote()) +} + // SignedHeader fetches a SignedHeader at the given height and checks the // chainID matches. func (p *http) SignedHeader(height int64) (*types.SignedHeader, error) { diff --git a/lite2/provider/mock/deadmock.go b/lite2/provider/mock/deadmock.go new file mode 100644 index 000000000..77c474411 --- /dev/null +++ b/lite2/provider/mock/deadmock.go @@ -0,0 +1,33 @@ +package mock + +import ( + "errors" + + "github.com/tendermint/tendermint/lite2/provider" + "github.com/tendermint/tendermint/types" +) + +type deadMock struct { + chainID string +} + +// NewDeadMock creates a mock provider that always errors. +func NewDeadMock(chainID string) provider.Provider { + return &deadMock{chainID: chainID} +} + +func (p *deadMock) ChainID() string { + return p.chainID +} + +func (p *deadMock) String() string { + return "deadMock" +} + +func (p *deadMock) SignedHeader(height int64) (*types.SignedHeader, error) { + return nil, errors.New("no response from provider") +} + +func (p *deadMock) ValidatorSet(height int64) (*types.ValidatorSet, error) { + return nil, errors.New("no response from provider") +} diff --git a/lite2/provider/mock/mock.go b/lite2/provider/mock/mock.go index f41358345..7ff7bc9a1 100644 --- a/lite2/provider/mock/mock.go +++ b/lite2/provider/mock/mock.go @@ -1,7 +1,8 @@ package mock import ( - "github.com/pkg/errors" + "fmt" + "strings" "github.com/tendermint/tendermint/lite2/provider" "github.com/tendermint/tendermint/types" @@ -23,10 +24,25 @@ func New(chainID string, headers map[int64]*types.SignedHeader, vals map[int64]* } } +// ChainID returns the blockchain ID. func (p *mock) ChainID() string { return p.chainID } +func (p *mock) String() string { + var headers strings.Builder + for _, h := range p.headers { + fmt.Fprintf(&headers, " %d:%X", h.Height, h.Hash()) + } + + var vals strings.Builder + for _, v := range p.vals { + fmt.Fprintf(&vals, " %X", v.Hash()) + } + + return fmt.Sprintf("mock{headers: %s, vals: %v}", headers.String(), vals.String()) +} + func (p *mock) SignedHeader(height int64) (*types.SignedHeader, error) { if height == 0 && len(p.headers) > 0 { return p.headers[int64(len(p.headers))], nil @@ -46,24 +62,3 @@ func (p *mock) ValidatorSet(height int64) (*types.ValidatorSet, error) { } return nil, provider.ErrValidatorSetNotFound } - -type deadMock struct { - chainID string -} - -// NewDeadMock creates a mock provider that always errors. -func NewDeadMock(chainID string) provider.Provider { - return &deadMock{chainID: chainID} -} - -func (p *deadMock) ChainID() string { - return p.chainID -} - -func (p *deadMock) SignedHeader(height int64) (*types.SignedHeader, error) { - return nil, errors.New("no response from provider") -} - -func (p *deadMock) ValidatorSet(height int64) (*types.ValidatorSet, error) { - return nil, errors.New("no response from provider") -} diff --git a/lite2/provider/provider.go b/lite2/provider/provider.go index 3f146fc6b..773e17e32 100644 --- a/lite2/provider/provider.go +++ b/lite2/provider/provider.go @@ -1,6 +1,8 @@ package provider -import "github.com/tendermint/tendermint/types" +import ( + "github.com/tendermint/tendermint/types" +) // Provider provides information for the lite client to sync (verification // happens in the client). diff --git a/rpc/client/httpclient.go b/rpc/client/httpclient.go index 021df82e6..c844113c3 100644 --- a/rpc/client/httpclient.go +++ b/rpc/client/httpclient.go @@ -123,10 +123,16 @@ func NewHTTPWithClient(remote, wsEndpoint string, client *http.Client) (*HTTP, e var _ Client = (*HTTP)(nil) +// SetLogger sets a logger. func (c *HTTP) SetLogger(l log.Logger) { c.WSEvents.SetLogger(l) } +// Remote returns the remote network address in a string form. +func (c *HTTP) Remote() string { + return c.remote +} + // NewBatch creates a new batch client for this HTTP client. func (c *HTTP) NewBatch() *BatchHTTP { rpcBatch := c.rpc.NewRequestBatch()