github.com/okex/exchain@v1.8.0/libs/tendermint/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  	"crypto/sha256"
    26  
    27  	"github.com/okex/exchain/libs/tendermint/libs/bytes"
    28  	"github.com/okex/exchain/libs/tendermint/libs/service"
    29  	ctypes "github.com/okex/exchain/libs/tendermint/rpc/core/types"
    30  	"github.com/okex/exchain/libs/tendermint/types"
    31  )
    32  
    33  // Client wraps most important rpc calls a client would make if you want to
    34  // listen for events, test if it also implements events.EventSwitch.
    35  type Client interface {
    36  	service.Service
    37  	ABCIClient
    38  	EventsClient
    39  	HistoryClient
    40  	NetworkClient
    41  	SignClient
    42  	StatusClient
    43  	EvidenceClient
    44  	MempoolClient
    45  }
    46  
    47  // ABCIClient groups together the functionality that principally affects the
    48  // ABCI app.
    49  //
    50  // In many cases this will be all we want, so we can accept an interface which
    51  // is easier to mock.
    52  type ABCIClient interface {
    53  	// Reading from abci app
    54  	ABCIInfo() (*ctypes.ResultABCIInfo, error)
    55  	ABCIQuery(path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error)
    56  	ABCIQueryWithOptions(path string, data bytes.HexBytes,
    57  		opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error)
    58  
    59  	// Writing to abci app
    60  	BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error)
    61  	BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)
    62  	BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)
    63  }
    64  
    65  // SignClient groups together the functionality needed to get valid signatures
    66  // and prove anything about the chain.
    67  type SignClient interface {
    68  	Block(height *int64) (*ctypes.ResultBlock, error)
    69  	BlockInfo(height *int64) (*types.BlockMeta, error)
    70  	BlockResults(height *int64) (*ctypes.ResultBlockResults, error)
    71  	Commit(height *int64) (*ctypes.ResultCommit, error)
    72  	Validators(height *int64, page, perPage int) (*ctypes.ResultValidators, error)
    73  	Tx(hash []byte, prove bool) (*ctypes.ResultTx, error)
    74  	TxSearch(query string, prove bool, page, perPage int, orderBy string) (*ctypes.ResultTxSearch, error)
    75  }
    76  
    77  // HistoryClient provides access to data from genesis to now in large chunks.
    78  type HistoryClient interface {
    79  	Genesis() (*ctypes.ResultGenesis, error)
    80  	BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error)
    81  	LatestBlockNumber() (int64, error)
    82  }
    83  
    84  // StatusClient provides access to general chain info.
    85  type StatusClient interface {
    86  	Status() (*ctypes.ResultStatus, error)
    87  }
    88  
    89  // NetworkClient is general info about the network state. May not be needed
    90  // usually.
    91  type NetworkClient interface {
    92  	NetInfo() (*ctypes.ResultNetInfo, error)
    93  	DumpConsensusState() (*ctypes.ResultDumpConsensusState, error)
    94  	ConsensusState() (*ctypes.ResultConsensusState, error)
    95  	ConsensusParams(height *int64) (*ctypes.ResultConsensusParams, error)
    96  	Health() (*ctypes.ResultHealth, error)
    97  }
    98  
    99  // EventsClient is reactive, you can subscribe to any message, given the proper
   100  // string. see tendermint/types/events.go
   101  type EventsClient interface {
   102  	// Subscribe subscribes given subscriber to query. Returns a channel with
   103  	// cap=1 onto which events are published. An error is returned if it fails to
   104  	// subscribe. outCapacity can be used optionally to set capacity for the
   105  	// channel. Channel is never closed to prevent accidental reads.
   106  	//
   107  	// ctx cannot be used to unsubscribe. To unsubscribe, use either Unsubscribe
   108  	// or UnsubscribeAll.
   109  	Subscribe(ctx context.Context, subscriber, query string, outCapacity ...int) (out <-chan ctypes.ResultEvent, err error)
   110  	// Unsubscribe unsubscribes given subscriber from query.
   111  	Unsubscribe(ctx context.Context, subscriber, query string) error
   112  	// UnsubscribeAll unsubscribes given subscriber from all the queries.
   113  	UnsubscribeAll(ctx context.Context, subscriber string) error
   114  }
   115  
   116  // MempoolClient shows us data about current mempool state.
   117  type MempoolClient interface {
   118  	UnconfirmedTxs(limit int) (*ctypes.ResultUnconfirmedTxs, error)
   119  	NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error)
   120  	UserUnconfirmedTxs(address string, limit int) (*ctypes.ResultUserUnconfirmedTxs, error)
   121  	UserNumUnconfirmedTxs(address string) (*ctypes.ResultUserUnconfirmedTxs, error)
   122  	GetUnconfirmedTxByHash(hash [sha256.Size]byte) (types.Tx, error)
   123  	GetAddressList() (*ctypes.ResultUnconfirmedAddresses, error)
   124  	GetPendingNonce(address string) (*ctypes.ResultPendingNonce, bool)
   125  }
   126  
   127  // EvidenceClient is used for submitting an evidence of the malicious
   128  // behaviour.
   129  type EvidenceClient interface {
   130  	BroadcastEvidence(ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error)
   131  }