github.com/noirx94/tendermintmp@v0.0.1/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/tendermint/tendermint/libs/bytes"
    27  	"github.com/tendermint/tendermint/libs/service"
    28  	ctypes "github.com/tendermint/tendermint/rpc/core/types"
    29  	"github.com/tendermint/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  	GenesisChunked(context.Context, uint) (*ctypes.ResultGenesisChunk, error)
    98  	BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error)
    99  }
   100  
   101  // StatusClient provides access to general chain info.
   102  type StatusClient interface {
   103  	Status(context.Context) (*ctypes.ResultStatus, error)
   104  }
   105  
   106  // NetworkClient is general info about the network state. May not be needed
   107  // usually.
   108  type NetworkClient interface {
   109  	NetInfo(context.Context) (*ctypes.ResultNetInfo, error)
   110  	DumpConsensusState(context.Context) (*ctypes.ResultDumpConsensusState, error)
   111  	ConsensusState(context.Context) (*ctypes.ResultConsensusState, error)
   112  	ConsensusParams(ctx context.Context, height *int64) (*ctypes.ResultConsensusParams, error)
   113  	Health(context.Context) (*ctypes.ResultHealth, error)
   114  }
   115  
   116  // EventsClient is reactive, you can subscribe to any message, given the proper
   117  // string. see tendermint/types/events.go
   118  type EventsClient interface {
   119  	// Subscribe subscribes given subscriber to query. Returns a channel with
   120  	// cap=1 onto which events are published. An error is returned if it fails to
   121  	// subscribe. outCapacity can be used optionally to set capacity for the
   122  	// channel. Channel is never closed to prevent accidental reads.
   123  	//
   124  	// ctx cannot be used to unsubscribe. To unsubscribe, use either Unsubscribe
   125  	// or UnsubscribeAll.
   126  	Subscribe(ctx context.Context, subscriber, query string, outCapacity ...int) (out <-chan ctypes.ResultEvent, err error)
   127  	// Unsubscribe unsubscribes given subscriber from query.
   128  	Unsubscribe(ctx context.Context, subscriber, query string) error
   129  	// UnsubscribeAll unsubscribes given subscriber from all the queries.
   130  	UnsubscribeAll(ctx context.Context, subscriber string) error
   131  }
   132  
   133  // MempoolClient shows us data about current mempool state.
   134  type MempoolClient interface {
   135  	UnconfirmedTxs(ctx context.Context, limit *int) (*ctypes.ResultUnconfirmedTxs, error)
   136  	NumUnconfirmedTxs(context.Context) (*ctypes.ResultUnconfirmedTxs, error)
   137  	CheckTx(context.Context, types.Tx) (*ctypes.ResultCheckTx, error)
   138  }
   139  
   140  // EvidenceClient is used for submitting an evidence of the malicious
   141  // behaviour.
   142  type EvidenceClient interface {
   143  	BroadcastEvidence(context.Context, types.Evidence) (*ctypes.ResultBroadcastEvidence, error)
   144  }
   145  
   146  // RemoteClient is a Client, which can also return the remote network address.
   147  type RemoteClient interface {
   148  	Client
   149  
   150  	// Remote returns the remote network address in a string form.
   151  	Remote() string
   152  }