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