github.com/ari-anchor/sei-tendermint@v0.0.0-20230519144642-dc826b7b56bb/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/ari-anchor/sei-tendermint/libs/bytes" 27 "github.com/ari-anchor/sei-tendermint/rpc/coretypes" 28 "github.com/ari-anchor/sei-tendermint/types" 29 ) 30 31 //go:generate ../../scripts/mockery_generate.sh Client 32 33 // Client describes the interface of Tendermint RPC client implementations. 34 type Client interface { 35 // Start the client, which will run until the context terminates. 36 // An error from Start indicates the client could not start. 37 Start(context.Context) error 38 39 // These embedded interfaces define the callable methods of the service. 40 41 ABCIClient 42 EventsClient 43 EvidenceClient 44 HistoryClient 45 MempoolClient 46 NetworkClient 47 SignClient 48 StatusClient 49 SubscriptionClient 50 } 51 52 // ABCIClient groups together the functionality that principally affects the 53 // ABCI app. 54 // 55 // In many cases this will be all we want, so we can accept an interface which 56 // is easier to mock. 57 type ABCIClient interface { 58 // Reading from abci app 59 ABCIInfo(context.Context) (*coretypes.ResultABCIInfo, error) 60 ABCIQuery(ctx context.Context, path string, data bytes.HexBytes) (*coretypes.ResultABCIQuery, error) 61 ABCIQueryWithOptions(ctx context.Context, path string, data bytes.HexBytes, 62 opts ABCIQueryOptions) (*coretypes.ResultABCIQuery, error) 63 64 // Writing to abci app 65 BroadcastTx(context.Context, types.Tx) (*coretypes.ResultBroadcastTx, error) 66 // These methods are deprecated: 67 BroadcastTxCommit(context.Context, types.Tx) (*coretypes.ResultBroadcastTxCommit, error) 68 BroadcastTxAsync(context.Context, types.Tx) (*coretypes.ResultBroadcastTx, error) 69 BroadcastTxSync(context.Context, types.Tx) (*coretypes.ResultBroadcastTx, error) 70 } 71 72 // SignClient groups together the functionality needed to get valid signatures 73 // and prove anything about the chain. 74 type SignClient interface { 75 Block(ctx context.Context, height *int64) (*coretypes.ResultBlock, error) 76 BlockByHash(ctx context.Context, hash bytes.HexBytes) (*coretypes.ResultBlock, error) 77 BlockResults(ctx context.Context, height *int64) (*coretypes.ResultBlockResults, error) 78 Header(ctx context.Context, height *int64) (*coretypes.ResultHeader, error) 79 HeaderByHash(ctx context.Context, hash bytes.HexBytes) (*coretypes.ResultHeader, error) 80 Commit(ctx context.Context, height *int64) (*coretypes.ResultCommit, error) 81 Validators(ctx context.Context, height *int64, page, perPage *int) (*coretypes.ResultValidators, error) 82 Tx(ctx context.Context, hash bytes.HexBytes, prove bool) (*coretypes.ResultTx, error) 83 84 // TxSearch defines a method to search for a paginated set of transactions by 85 // DeliverTx event search criteria. 86 TxSearch( 87 ctx context.Context, 88 query string, 89 prove bool, 90 page, perPage *int, 91 orderBy string, 92 ) (*coretypes.ResultTxSearch, error) 93 94 // BlockSearch defines a method to search for a paginated set of blocks by 95 // FinalizeBlock event search criteria. 96 BlockSearch( 97 ctx context.Context, 98 query string, 99 page, perPage *int, 100 orderBy string, 101 ) (*coretypes.ResultBlockSearch, error) 102 } 103 104 // HistoryClient provides access to data from genesis to now in large chunks. 105 type HistoryClient interface { 106 Genesis(context.Context) (*coretypes.ResultGenesis, error) 107 GenesisChunked(context.Context, uint) (*coretypes.ResultGenesisChunk, error) 108 BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*coretypes.ResultBlockchainInfo, error) 109 } 110 111 // StatusClient provides access to general chain info. 112 type StatusClient interface { 113 Status(context.Context) (*coretypes.ResultStatus, error) 114 } 115 116 // NetworkClient is general info about the network state. May not be needed 117 // usually. 118 type NetworkClient interface { 119 NetInfo(context.Context) (*coretypes.ResultNetInfo, error) 120 DumpConsensusState(context.Context) (*coretypes.ResultDumpConsensusState, error) 121 ConsensusState(context.Context) (*coretypes.ResultConsensusState, error) 122 ConsensusParams(ctx context.Context, height *int64) (*coretypes.ResultConsensusParams, error) 123 Health(context.Context) (*coretypes.ResultHealth, error) 124 } 125 126 // EventsClient exposes the methods to retrieve events from the consensus engine. 127 type EventsClient interface { 128 // Events fetches a batch of events from the server matching the given query 129 // and time range. 130 Events(ctx context.Context, req *coretypes.RequestEvents) (*coretypes.ResultEvents, error) 131 } 132 133 // TODO(creachadair): This interface should be removed once the streaming event 134 // interface is removed in Tendermint v0.37. 135 type SubscriptionClient interface { 136 // Subscribe issues a subscription request for the given subscriber ID and 137 // query. This method does not block: If subscription fails, it reports an 138 // error, and if subscription succeeds it returns a channel that delivers 139 // matching events until the subscription is stopped. The channel is never 140 // closed; the client is responsible for knowing when no further data will 141 // be sent. 142 // 143 // The context only governs the initial subscription, it does not control 144 // the lifetime of the channel. To cancel a subscription call Unsubscribe or 145 // UnsubscribeAll. 146 // 147 // Deprecated: This method will be removed in Tendermint v0.37, use Events 148 // instead. 149 Subscribe(ctx context.Context, subscriber, query string, outCapacity ...int) (out <-chan coretypes.ResultEvent, err error) 150 151 // Unsubscribe unsubscribes given subscriber from query. 152 // 153 // Deprecated: This method will be removed in Tendermint v0.37, use Events 154 // instead. 155 Unsubscribe(ctx context.Context, subscriber, query string) error 156 157 // UnsubscribeAll unsubscribes given subscriber from all the queries. 158 // 159 // Deprecated: This method will be removed in Tendermint v0.37, use Events 160 // instead. 161 UnsubscribeAll(ctx context.Context, subscriber string) error 162 } 163 164 // MempoolClient shows us data about current mempool state. 165 type MempoolClient interface { 166 UnconfirmedTxs(ctx context.Context, page, perPage *int) (*coretypes.ResultUnconfirmedTxs, error) 167 NumUnconfirmedTxs(context.Context) (*coretypes.ResultUnconfirmedTxs, error) 168 CheckTx(context.Context, types.Tx) (*coretypes.ResultCheckTx, error) 169 RemoveTx(context.Context, types.TxKey) error 170 } 171 172 // EvidenceClient is used for submitting an evidence of the malicious 173 // behavior. 174 type EvidenceClient interface { 175 BroadcastEvidence(context.Context, types.Evidence) (*coretypes.ResultBroadcastEvidence, error) 176 } 177 178 // RemoteClient is a Client, which can also return the remote network address. 179 type RemoteClient interface { 180 Client 181 182 // Remote returns the remote network address in a string form. 183 Remote() string 184 }