github.com/pokt-network/tendermint@v0.32.11-0.20230426215212-59310158d3e9/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() (*ctypes.ResultABCIInfo, error) 54 ABCIQuery(path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) 55 ABCIQueryWithOptions(path string, data bytes.HexBytes, 56 opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) 57 58 // Writing to abci app 59 BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) 60 BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) 61 BroadcastTxSync(tx 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(height *int64) (*ctypes.ResultBlock, error) 68 BlockResults(height *int64) (*ctypes.ResultBlockResults, error) 69 Commit(height *int64) (*ctypes.ResultCommit, error) 70 Validators(height *int64, page, perPage int) (*ctypes.ResultValidators, error) 71 Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) 72 TxSearch(query string, prove bool, page, perPage int, orderBy string) (*ctypes.ResultTxSearch, error) 73 } 74 75 // HistoryClient provides access to data from genesis to now in large chunks. 76 type HistoryClient interface { 77 Genesis() (*ctypes.ResultGenesis, error) 78 BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) 79 } 80 81 // StatusClient provides access to general chain info. 82 type StatusClient interface { 83 Status() (*ctypes.ResultStatus, error) 84 ConsensusReactorStatus() (*ctypes.ResultConsensusReactorStatus, error) 85 } 86 87 // NetworkClient is general info about the network state. May not be needed 88 // usually. 89 type NetworkClient interface { 90 NetInfo() (*ctypes.ResultNetInfo, error) 91 DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) 92 ConsensusState() (*ctypes.ResultConsensusState, error) 93 ConsensusParams(height *int64) (*ctypes.ResultConsensusParams, error) 94 Health() (*ctypes.ResultHealth, error) 95 } 96 97 // EventsClient is reactive, you can subscribe to any message, given the proper 98 // string. see tendermint/types/events.go 99 type EventsClient interface { 100 // Subscribe subscribes given subscriber to query. Returns a channel with 101 // cap=1 onto which events are published. An error is returned if it fails to 102 // subscribe. outCapacity can be used optionally to set capacity for the 103 // channel. Channel is never closed to prevent accidental reads. 104 // 105 // ctx cannot be used to unsubscribe. To unsubscribe, use either Unsubscribe 106 // or UnsubscribeAll. 107 Subscribe(ctx context.Context, subscriber, query string, outCapacity ...int) (out <-chan ctypes.ResultEvent, err error) 108 // Unsubscribe unsubscribes given subscriber from query. 109 Unsubscribe(ctx context.Context, subscriber, query string) error 110 // UnsubscribeAll unsubscribes given subscriber from all the queries. 111 UnsubscribeAll(ctx context.Context, subscriber string) error 112 } 113 114 // MempoolClient shows us data about current mempool state. 115 type MempoolClient interface { 116 UnconfirmedTxs(limit int) (*ctypes.ResultUnconfirmedTxs, error) 117 NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error) 118 } 119 120 // EvidenceClient is used for submitting an evidence of the malicious 121 // behaviour. 122 type EvidenceClient interface { 123 BroadcastEvidence(ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error) 124 }