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