github.com/soomindae/tendermint@v0.0.5-0.20210528140126-84a0c70c8162/rpc/client/interface.go (about)

     1  package client
     2  
     3  /*
     4  The client package provides a general purpose interface (Client) for connecting
     5  to a tendermint node, as well as higher-level functionality.
     6  
     7  The main implementation for production code is client.HTTP, which
     8  connects via http to the jsonrpc interface of the tendermint node.
     9  
    10  For connecting to a node running in the same process (eg. when
    11  compiling the abci app in the same process), you can use the client.Local
    12  implementation.
    13  
    14  For mocking out server responses during testing to see behavior for
    15  arbitrary return values, use the mock package.
    16  
    17  In addition to the Client interface, which should be used externally
    18  for maximum flexibility and testability, and two implementations,
    19  this package also provides helper functions that work on any Client
    20  implementation.
    21  */
    22  
    23  import (
    24  	"context"
    25  
    26  	"github.com/soomindae/tendermint/libs/bytes"
    27  	"github.com/soomindae/tendermint/libs/service"
    28  	ctypes "github.com/soomindae/tendermint/rpc/core/types"
    29  	"github.com/soomindae/tendermint/types"
    30  )
    31  
    32  // Client wraps most important rpc calls a client would make if you want to
    33  // listen for events, test if it also implements events.EventSwitch.
    34  type Client interface {
    35  	service.Service
    36  	ABCIClient
    37  	EventsClient
    38  	HistoryClient
    39  	NetworkClient
    40  	SignClient
    41  	StatusClient
    42  	EvidenceClient
    43  	MempoolClient
    44  }
    45  
    46  // ABCIClient groups together the functionality that principally affects the
    47  // ABCI app.
    48  //
    49  // In many cases this will be all we want, so we can accept an interface which
    50  // is easier to mock.
    51  type ABCIClient interface {
    52  	// Reading from abci app
    53  	ABCIInfo(context.Context) (*ctypes.ResultABCIInfo, error)
    54  	ABCIQuery(ctx context.Context, path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error)
    55  	ABCIQueryWithOptions(ctx context.Context, path string, data bytes.HexBytes,
    56  		opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error)
    57  
    58  	// Writing to abci app
    59  	BroadcastTxCommit(context.Context, types.Tx) (*ctypes.ResultBroadcastTxCommit, error)
    60  	BroadcastTxAsync(context.Context, types.Tx) (*ctypes.ResultBroadcastTx, error)
    61  	BroadcastTxSync(context.Context, types.Tx) (*ctypes.ResultBroadcastTx, error)
    62  }
    63  
    64  // SignClient groups together the functionality needed to get valid signatures
    65  // and prove anything about the chain.
    66  type SignClient interface {
    67  	Block(ctx context.Context, height *int64) (*ctypes.ResultBlock, error)
    68  	BlockByHash(ctx context.Context, hash []byte) (*ctypes.ResultBlock, error)
    69  	BlockResults(ctx context.Context, height *int64) (*ctypes.ResultBlockResults, error)
    70  	Commit(ctx context.Context, height *int64) (*ctypes.ResultCommit, error)
    71  	Validators(ctx context.Context, height *int64, page, perPage *int) (*ctypes.ResultValidators, error)
    72  	Tx(ctx context.Context, hash []byte, prove bool) (*ctypes.ResultTx, error)
    73  
    74  	// TxSearch defines a method to search for a paginated set of transactions by
    75  	// DeliverTx event search criteria.
    76  	TxSearch(
    77  		ctx context.Context,
    78  		query string,
    79  		prove bool,
    80  		page, perPage *int,
    81  		orderBy string,
    82  	) (*ctypes.ResultTxSearch, error)
    83  
    84  	// BlockSearch defines a method to search for a paginated set of blocks by
    85  	// BeginBlock and EndBlock event search criteria.
    86  	BlockSearch(
    87  		ctx context.Context,
    88  		query string,
    89  		page, perPage *int,
    90  		orderBy string,
    91  	) (*ctypes.ResultBlockSearch, error)
    92  }
    93  
    94  // HistoryClient provides access to data from genesis to now in large chunks.
    95  type HistoryClient interface {
    96  	Genesis(context.Context) (*ctypes.ResultGenesis, error)
    97  	BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error)
    98  }
    99  
   100  // StatusClient provides access to general chain info.
   101  type StatusClient interface {
   102  	Status(context.Context) (*ctypes.ResultStatus, error)
   103  }
   104  
   105  // NetworkClient is general info about the network state. May not be needed
   106  // usually.
   107  type NetworkClient interface {
   108  	NetInfo(context.Context) (*ctypes.ResultNetInfo, error)
   109  	DumpConsensusState(context.Context) (*ctypes.ResultDumpConsensusState, error)
   110  	ConsensusState(context.Context) (*ctypes.ResultConsensusState, error)
   111  	ConsensusParams(ctx context.Context, height *int64) (*ctypes.ResultConsensusParams, error)
   112  	Health(context.Context) (*ctypes.ResultHealth, error)
   113  }
   114  
   115  // EventsClient is reactive, you can subscribe to any message, given the proper
   116  // string. see tendermint/types/events.go
   117  type EventsClient interface {
   118  	// Subscribe subscribes given subscriber to query. Returns a channel with
   119  	// cap=1 onto which events are published. An error is returned if it fails to
   120  	// subscribe. outCapacity can be used optionally to set capacity for the
   121  	// channel. Channel is never closed to prevent accidental reads.
   122  	//
   123  	// ctx cannot be used to unsubscribe. To unsubscribe, use either Unsubscribe
   124  	// or UnsubscribeAll.
   125  	Subscribe(ctx context.Context, subscriber, query string, outCapacity ...int) (out <-chan ctypes.ResultEvent, err error)
   126  	// Unsubscribe unsubscribes given subscriber from query.
   127  	Unsubscribe(ctx context.Context, subscriber, query string) error
   128  	// UnsubscribeAll unsubscribes given subscriber from all the queries.
   129  	UnsubscribeAll(ctx context.Context, subscriber string) error
   130  }
   131  
   132  // MempoolClient shows us data about current mempool state.
   133  type MempoolClient interface {
   134  	UnconfirmedTxs(ctx context.Context, limit *int) (*ctypes.ResultUnconfirmedTxs, error)
   135  	NumUnconfirmedTxs(context.Context) (*ctypes.ResultUnconfirmedTxs, error)
   136  	CheckTx(context.Context, types.Tx) (*ctypes.ResultCheckTx, error)
   137  }
   138  
   139  // EvidenceClient is used for submitting an evidence of the malicious
   140  // behaviour.
   141  type EvidenceClient interface {
   142  	BroadcastEvidence(context.Context, types.Evidence) (*ctypes.ResultBroadcastEvidence, error)
   143  }
   144  
   145  // RemoteClient is a Client, which can also return the remote network address.
   146  type RemoteClient interface {
   147  	Client
   148  
   149  	// Remote returns the remote network address in a string form.
   150  	Remote() string
   151  }