Documentation ¶
Index ¶
- Constants
- Variables
- func FormatTxResults(cdc *amino.Codec, res []*ctypes.ResultTx) ([]tx.Info, error)
- func OnReconnect(cb func()) func(*WSClient)
- func ParseTx(cdc *amino.Codec, txBytes []byte) (tx.Tx, error)
- func ValidateABCIData(data common.HexBytes) error
- func ValidateABCIPath(path string) error
- func ValidateABCIQueryStr(query string) error
- func ValidateDepthLevel(level int) error
- func ValidateHash(hash []byte) error
- func ValidateHeight(height *int64) error
- func ValidateHeightRange(from int64, to int64) error
- func ValidateLimit(limit int) error
- func ValidateOffset(offset int) error
- func ValidatePair(pair string) error
- func ValidateSymbol(symbol string) error
- func ValidateTx(tx types.Tx) error
- func ValidateTxSearchQueryStr(query string) error
- func ValidateUnConfirmedTxsLimit(limit int) error
- type Client
- type DexClient
- type EventsClient
- type HTTP
- func (c *HTTP) ABCIInfo() (*ctypes.ResultABCIInfo, error)
- func (c *HTTP) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error)
- func (c *HTTP) ABCIQueryWithOptions(path string, data cmn.HexBytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error)
- func (c *HTTP) Block(height *int64) (*ctypes.ResultBlock, error)
- func (c *HTTP) BlockResults(height *int64) (*ctypes.ResultBlockResults, error)
- func (c *HTTP) BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error)
- func (c *HTTP) BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)
- func (c *HTTP) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error)
- func (c *HTTP) BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)
- func (c *HTTP) Commit(height *int64) (*ctypes.ResultCommit, error)
- func (c *HTTP) ConsensusState() (*ctypes.ResultConsensusState, error)
- func (c *HTTP) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error)
- func (c *HTTP) Genesis() (*ctypes.ResultGenesis, error)
- func (c *HTTP) GetAccount(addr types.AccAddress) (acc types.Account, err error)
- func (c *HTTP) GetBalance(addr types.AccAddress, symbol string) (*types.TokenBalance, error)
- func (c *HTTP) GetBalances(addr types.AccAddress) ([]types.TokenBalance, error)
- func (c *HTTP) GetCommitAccount(addr types.AccAddress) (acc types.Account, err error)
- func (c *HTTP) GetDelegatorUnbondingDelegations(delegatorAddr types.AccAddress) ([]types.UnbondingDelegation, error)
- func (c *HTTP) GetDepth(tradePair string, level int) (*types.OrderBook, error)
- func (c *HTTP) GetFee() ([]types.FeeParam, error)
- func (c *HTTP) GetOpenOrders(addr types.AccAddress, pair string) ([]types.OpenOrder, error)
- func (c *HTTP) GetProposal(proposalId int64) (types.Proposal, error)
- func (c *HTTP) GetProposals(status types.ProposalStatus, numLatest int64) ([]types.Proposal, error)
- func (c *HTTP) GetStakeValidators() ([]types.Validator, error)
- func (c *HTTP) GetTimelock(address string, recordID int64) (types.TimeLockRecord, error)
- func (c *HTTP) GetTimelocks(address string) ([]types.TimeLockRecord, error)
- func (c *HTTP) GetTokenInfo(symbol string) (*types.Token, error)
- func (c *HTTP) GetTradingPairs(offset int, limit int) ([]types.TradingPair, error)
- func (c *HTTP) Health() (*ctypes.ResultHealth, error)
- func (c *HTTP) IsActive() bool
- func (c *HTTP) ListAllTokens(offset int, limit int) ([]types.Token, error)
- func (c *HTTP) NetInfo() (*ctypes.ResultNetInfo, error)
- func (c *HTTP) NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error)
- func (c *HTTP) QueryStore(key cmn.HexBytes, storeName string) ([]byte, error)
- func (c *HTTP) Status() (*ctypes.ResultStatus, error)
- func (c *HTTP) Tx(hash []byte, prove bool) (*ctypes.ResultTx, error)
- func (c *HTTP) TxInfoSearch(query string, prove bool, page, perPage int) ([]tx.Info, error)
- func (c *HTTP) TxSearch(query string, prove bool, page, perPage int) (*ctypes.ResultTxSearch, error)
- func (c *HTTP) UnconfirmedTxs(limit int) (*ctypes.ResultUnconfirmedTxs, error)
- func (c *HTTP) Validators(height *int64) (*ctypes.ResultValidators, error)
- type OpsClient
- type WSClient
- func (c *WSClient) ABCIInfo(ctx context.Context, id rpctypes.JSONRPCStringID) error
- func (c *WSClient) ABCIQueryWithOptions(ctx context.Context, id rpctypes.JSONRPCStringID, path string, ...) error
- func (c *WSClient) Block(ctx context.Context, id rpctypes.JSONRPCStringID, height *int64) error
- func (c *WSClient) BlockResults(ctx context.Context, id rpctypes.JSONRPCStringID, height *int64) error
- func (c *WSClient) BlockchainInfo(ctx context.Context, id rpctypes.JSONRPCStringID, minHeight, maxHeight int64) error
- func (c *WSClient) BroadcastTx(ctx context.Context, id rpctypes.JSONRPCStringID, route string, tx types.Tx) error
- func (c *WSClient) BroadcastTxCommit(ctx context.Context, id rpctypes.JSONRPCStringID, tx types.Tx) error
- func (c *WSClient) Call(ctx context.Context, method string, id rpctypes.JSONRPCStringID, ...) error
- func (c *WSClient) CallWithArrayParams(ctx context.Context, method string, params []interface{}) error
- func (c *WSClient) Codec() *amino.Codec
- func (c *WSClient) Commit(ctx context.Context, id rpctypes.JSONRPCStringID, height *int64) error
- func (c *WSClient) ConsensusState(ctx context.Context, id rpctypes.JSONRPCStringID) error
- func (c *WSClient) DumpConsensusState(ctx context.Context, id rpctypes.JSONRPCStringID) error
- func (c *WSClient) EmptyRequest() rpctypes.JSONRPCStringID
- func (c *WSClient) GenRequestId() (rpctypes.JSONRPCStringID, error)
- func (c *WSClient) Genesis(ctx context.Context, id rpctypes.JSONRPCStringID) error
- func (c *WSClient) GetConnection() *websocket.Conn
- func (c *WSClient) Health(ctx context.Context, id rpctypes.JSONRPCStringID) error
- func (c *WSClient) IsActive() bool
- func (c *WSClient) IsDialing() bool
- func (c *WSClient) NetInfo(ctx context.Context, id rpctypes.JSONRPCStringID) error
- func (c *WSClient) NumUnconfirmedTxs(ctx context.Context, id rpctypes.JSONRPCStringID) error
- func (c *WSClient) OnStart() error
- func (c *WSClient) Send(ctx context.Context, request rpctypes.RPCRequest) error
- func (c *WSClient) SetCodec(cdc *amino.Codec)
- func (c *WSClient) SetConnection(conn *websocket.Conn)
- func (c *WSClient) Status(ctx context.Context, id rpctypes.JSONRPCStringID) error
- func (c *WSClient) Stop() error
- func (c *WSClient) String() string
- func (c *WSClient) Subscribe(ctx context.Context, id rpctypes.JSONRPCStringID, query string) error
- func (c *WSClient) Tx(ctx context.Context, id rpctypes.JSONRPCStringID, hash []byte, prove bool) error
- func (c *WSClient) TxSearch(ctx context.Context, id rpctypes.JSONRPCStringID, query string, prove bool, ...) error
- func (c *WSClient) UnconfirmedTxs(ctx context.Context, id rpctypes.JSONRPCStringID, limit int) error
- func (c *WSClient) Unsubscribe(ctx context.Context, id rpctypes.JSONRPCStringID, query string) error
- func (c *WSClient) UnsubscribeAll(ctx context.Context, id rpctypes.JSONRPCStringID) error
- func (c *WSClient) Validators(ctx context.Context, id rpctypes.JSONRPCStringID, height *int64) error
- type WSEvents
- func (w *WSEvents) ABCIInfo() (*ctypes.ResultABCIInfo, error)
- func (w *WSEvents) ABCIQueryWithOptions(path string, data cmn.HexBytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error)
- func (w *WSEvents) Block(height *int64) (*ctypes.ResultBlock, error)
- func (w *WSEvents) BlockResults(height *int64) (*ctypes.ResultBlockResults, error)
- func (w *WSEvents) BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error)
- func (w *WSEvents) BroadcastTx(route string, tx types.Tx) (*ctypes.ResultBroadcastTx, error)
- func (w *WSEvents) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error)
- func (w *WSEvents) Commit(height *int64) (*ctypes.ResultCommit, error)
- func (w *WSEvents) ConsensusState() (*ctypes.ResultConsensusState, error)
- func (w *WSEvents) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error)
- func (w *WSEvents) Genesis() (*ctypes.ResultGenesis, error)
- func (w *WSEvents) Health() (*ctypes.ResultHealth, error)
- func (c *WSEvents) IsActive() bool
- func (w *WSEvents) NetInfo() (*ctypes.ResultNetInfo, error)
- func (w *WSEvents) NewContext() (context.Context, context.CancelFunc)
- func (w *WSEvents) NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error)
- func (w *WSEvents) OnStart() error
- func (w *WSEvents) OnStop()
- func (w *WSEvents) PendingRequest() int
- func (w *WSEvents) SetTimeOut(timeout time.Duration)
- func (w *WSEvents) SimpleCall(doRpc func(ctx context.Context, id rpctypes.JSONRPCStringID) error, ...) error
- func (w *WSEvents) Status() (*ctypes.ResultStatus, error)
- func (w *WSEvents) Subscribe(query string, outCapacity ...int) (out chan ctypes.ResultEvent, err error)
- func (w *WSEvents) Tx(hash []byte, prove bool) (*ctypes.ResultTx, error)
- func (w *WSEvents) TxInfoSearch(query string, prove bool, page, perPage int) ([]tx.Info, error)
- func (w *WSEvents) TxSearch(query string, prove bool, page, perPage int) (*ctypes.ResultTxSearch, error)
- func (w *WSEvents) UnconfirmedTxs(limit int) (*ctypes.ResultUnconfirmedTxs, error)
- func (w *WSEvents) Unsubscribe(query string) error
- func (w *WSEvents) UnsubscribeAll() error
- func (w *WSEvents) Validators(height *int64) (*ctypes.ResultValidators, error)
- func (w *WSEvents) WaitForEventResponse(requestId interface{}, in chan rpctypes.RPCResponse, ...)
- func (w *WSEvents) WaitForResponse(ctx context.Context, outChan chan rpctypes.RPCResponse, result interface{}) error
Constants ¶
const ( AccountStoreName = "acc" TokenStoreName = "tokens" ParamABCIPrefix = "param" TimeLockMsgRoute = "timelock" )
Variables ¶
var ( ExceedABCIPathLengthError = fmt.Errorf("the abci path exceed max length %d ", maxABCIPathLength) ExceedABCIDataLengthError = fmt.Errorf("the abci data exceed max length %d ", maxABCIDataLength) ExceedTxLengthError = fmt.Errorf("the tx data exceed max length %d ", maxTxLength) LimitNegativeError = fmt.Errorf("the limit can't be negative") ExceedMaxUnConfirmedTxsNumError = fmt.Errorf("the limit of unConfirmed tx exceed max limit %d ", maxUnConfirmedTxs) HeightNegativeError = fmt.Errorf("the height can't be negative") MaxMinHeightConflictError = fmt.Errorf("the min height can't be larger than max height") HashLengthError = fmt.Errorf("the length of hash is not 32") ExceedABCIQueryStrLengthError = fmt.Errorf("the query string exceed max length %d ", maxABCIPathLength) ExceedTxSearchQueryStrLengthError = fmt.Errorf("the query string exceed max length %d ", maxTxSearchStrLength) OffsetNegativeError = fmt.Errorf("offset can't be less than 0") SymbolLengthExceedRangeError = fmt.Errorf("length of symbol should be in range [%d,%d]", tokenSymbolMinLen, tokenSymbolMaxLen) PairFormatError = fmt.Errorf("the pair should in format 'symbol1_symbol2'") DepthLevelExceedRangeError = fmt.Errorf("the level is out of range [%d, %d]", 0, maxDepthLevel) )
Functions ¶
func FormatTxResults ¶
parse the indexed txs into an array of Info
func OnReconnect ¶
func OnReconnect(cb func()) func(*WSClient)
OnReconnect sets the callback, which will be called every time after successful reconnect.
func ValidateABCIData ¶
func ValidateABCIPath ¶
func ValidateABCIQueryStr ¶
func ValidateDepthLevel ¶
func ValidateHash ¶
func ValidateHeight ¶
func ValidateHeightRange ¶
func ValidateLimit ¶
func ValidateOffset ¶
func ValidatePair ¶
func ValidateSymbol ¶
func ValidateTx ¶
Types ¶
type Client ¶
type Client interface { cmn.Service client.ABCIClient client.SignClient client.HistoryClient client.StatusClient EventsClient DexClient OpsClient }
type DexClient ¶
type DexClient interface { TxInfoSearch(query string, prove bool, page, perPage int) ([]tx.Info, error) ListAllTokens(offset int, limit int) ([]types.Token, error) GetTokenInfo(symbol string) (*types.Token, error) GetAccount(addr types.AccAddress) (acc types.Account, err error) GetCommitAccount(addr types.AccAddress) (acc types.Account, err error) GetBalances(addr types.AccAddress) ([]types.TokenBalance, error) GetBalance(addr types.AccAddress, symbol string) (*types.TokenBalance, error) GetFee() ([]types.FeeParam, error) GetOpenOrders(addr types.AccAddress, pair string) ([]types.OpenOrder, error) GetTradingPairs(offset int, limit int) ([]types.TradingPair, error) GetDepth(tradePair string, level int) (*types.OrderBook, error) GetProposals(status types.ProposalStatus, numLatest int64) ([]types.Proposal, error) GetProposal(proposalId int64) (types.Proposal, error) GetTimelocks(address string) ([]types.TimeLockRecord, error) GetTimelock(address string, recordID int64) (types.TimeLockRecord, error) }
type EventsClient ¶
type HTTP ¶
type HTTP struct {
*WSEvents
}
func NewHTTP ¶
NewHTTP takes a remote endpoint in the form tcp://<host>:<port> and the websocket path (which always seems to be "/websocket")
func NewRPCClient ¶
func NewRPCClient(nodeURI string, network ntypes.ChainNetwork) *HTTP
func (*HTTP) ABCIQueryWithOptions ¶
func (c *HTTP) ABCIQueryWithOptions(path string, data cmn.HexBytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error)
func (*HTTP) BlockResults ¶
func (c *HTTP) BlockResults(height *int64) (*ctypes.ResultBlockResults, error)
func (*HTTP) BlockchainInfo ¶
func (c *HTTP) BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error)
func (*HTTP) BroadcastTxAsync ¶
func (*HTTP) BroadcastTxCommit ¶
func (*HTTP) BroadcastTxSync ¶
func (*HTTP) ConsensusState ¶
func (c *HTTP) ConsensusState() (*ctypes.ResultConsensusState, error)
func (*HTTP) DumpConsensusState ¶
func (c *HTTP) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error)
func (*HTTP) GetAccount ¶
Always fetch the latest account from the cache in node even the previous transaction from this account is not included in block yet. example: 1. AccountA(Balance: 10BNB, sequence: 1), AccountB(Balance: 5BNB, sequence: 1) 2. Node receive Tx(AccountA --> AccountB 2BNB) and check have passed, but not included in block yet. 3. GetAccount will return AccountA(Balance: 8BNB, sequence: 2), AccountB(Balance: 7BNB, sequence: 1)
func (*HTTP) GetBalance ¶
func (c *HTTP) GetBalance(addr types.AccAddress, symbol string) (*types.TokenBalance, error)
func (*HTTP) GetBalances ¶
func (c *HTTP) GetBalances(addr types.AccAddress) ([]types.TokenBalance, error)
func (*HTTP) GetCommitAccount ¶
Always fetch the account from the commit store at (currentHeight-1) in node. example: 1. currentCommitHeight: 1000, accountA(balance: 10BNB, sequence: 10) 2. height: 999, accountA(balance: 11BNB, sequence: 9) 3. GetCommitAccount will return accountA(balance: 11BNB, sequence: 9). If the (currentHeight-1) do not exist, will return account at currentHeight. 1. currentCommitHeight: 1000, accountA(balance: 10BNB, sequence: 10) 2. height: 999. the state do not exist 3. GetCommitAccount will return accountA(balance: 10BNB, sequence: 10).
func (*HTTP) GetDelegatorUnbondingDelegations ¶
func (c *HTTP) GetDelegatorUnbondingDelegations(delegatorAddr types.AccAddress) ([]types.UnbondingDelegation, error)
func (*HTTP) GetOpenOrders ¶
func (*HTTP) GetProposals ¶
func (*HTTP) GetTimelock ¶
func (*HTTP) GetTimelocks ¶
func (c *HTTP) GetTimelocks(address string) ([]types.TimeLockRecord, error)
func (*HTTP) GetTradingPairs ¶
func (*HTTP) ListAllTokens ¶
func (*HTTP) NumUnconfirmedTxs ¶
func (c *HTTP) NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error)
func (*HTTP) QueryStore ¶
func (*HTTP) TxInfoSearch ¶
func (*HTTP) UnconfirmedTxs ¶
func (c *HTTP) UnconfirmedTxs(limit int) (*ctypes.ResultUnconfirmedTxs, error)
func (*HTTP) Validators ¶
func (c *HTTP) Validators(height *int64) (*ctypes.ResultValidators, error)
type OpsClient ¶
type OpsClient interface { IsActive() bool GetStakeValidators() ([]types.Validator, error) GetDelegatorUnbondingDelegations(delegatorAddr types.AccAddress) ([]types.UnbondingDelegation, error) }
type WSClient ¶
type WSClient struct { cmn.BaseService Address string // IP:PORT or /path/to/socket Endpoint string // /websocket/url/endpoint Dialer func(string, string) (net.Conn, error) // Single user facing channel to read RPCResponses from, closed only when the client is being stopped. ResponsesCh chan rpctypes.RPCResponse // contains filtered or unexported fields }
WSClient is a WebSocket client. The methods of WSClient are safe for use by multiple goroutines.
func NewWSClient ¶
NewWSClient returns a new client. See the commentary on the func(*WSClient) functions for a detailed description of how to configure ping period and pong wait time. The endpoint argument must begin with a `/`.
func (*WSClient) ABCIQueryWithOptions ¶
func (*WSClient) BlockResults ¶
func (*WSClient) BlockchainInfo ¶
func (*WSClient) BroadcastTx ¶
func (*WSClient) BroadcastTxCommit ¶
func (*WSClient) Call ¶
func (c *WSClient) Call(ctx context.Context, method string, id rpctypes.JSONRPCStringID, params map[string]interface{}) error
Call the given method. See Send description.
func (*WSClient) CallWithArrayParams ¶
func (c *WSClient) CallWithArrayParams(ctx context.Context, method string, params []interface{}) error
CallWithArrayParams the given method with params in a form of array. See Send description.
func (*WSClient) ConsensusState ¶
func (*WSClient) DumpConsensusState ¶
func (*WSClient) EmptyRequest ¶
func (c *WSClient) EmptyRequest() rpctypes.JSONRPCStringID
func (*WSClient) GenRequestId ¶
func (*WSClient) GetConnection ¶
func (*WSClient) NumUnconfirmedTxs ¶
func (*WSClient) OnStart ¶
OnStart implements cmn.Service by dialing a server and creating read and write routines.
func (*WSClient) Send ¶
Send the given RPC request to the server. Results will be available on ResponsesCh, errors, if any, on ErrorsCh. Will block until send succeeds or ctx.Done is closed.
func (*WSClient) SetConnection ¶
func (*WSClient) Stop ¶
Stop overrides cmn.Service#Stop. There is no other way to wait until Quit channel is closed.
func (*WSClient) Subscribe ¶
Subscribe to a query. Note the server must have a "subscribe" route defined.
func (*WSClient) UnconfirmedTxs ¶
func (*WSClient) Unsubscribe ¶
func (c *WSClient) Unsubscribe(ctx context.Context, id rpctypes.JSONRPCStringID, query string) error
Unsubscribe from a query. Note the server must have a "unsubscribe" route defined.
func (*WSClient) UnsubscribeAll ¶
UnsubscribeAll from all. Note the server must have a "unsubscribe_all" route defined.
type WSEvents ¶
type WSEvents struct { cmn.BaseService // contains filtered or unexported fields }
* websocket event stuff here... *
func (*WSEvents) ABCIQueryWithOptions ¶
func (w *WSEvents) ABCIQueryWithOptions(path string, data cmn.HexBytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error)
func (*WSEvents) BlockResults ¶
func (w *WSEvents) BlockResults(height *int64) (*ctypes.ResultBlockResults, error)
func (*WSEvents) BlockchainInfo ¶
func (w *WSEvents) BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error)
func (*WSEvents) BroadcastTx ¶
func (*WSEvents) BroadcastTxCommit ¶
func (*WSEvents) ConsensusState ¶
func (w *WSEvents) ConsensusState() (*ctypes.ResultConsensusState, error)
func (*WSEvents) DumpConsensusState ¶
func (w *WSEvents) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error)
func (*WSEvents) NewContext ¶
func (w *WSEvents) NewContext() (context.Context, context.CancelFunc)
func (*WSEvents) NumUnconfirmedTxs ¶
func (w *WSEvents) NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error)
func (*WSEvents) OnStop ¶
func (w *WSEvents) OnStop()
OnStop implements cmn.Service by stopping WSClient.
func (*WSEvents) PendingRequest ¶
OnStop implements cmn.Service by stopping WSClient.
func (*WSEvents) SetTimeOut ¶
func (*WSEvents) SimpleCall ¶
func (*WSEvents) Subscribe ¶
func (w *WSEvents) Subscribe(query string, outCapacity ...int) (out chan ctypes.ResultEvent, err error)
Subscribe implements EventsClient by using WSClient to subscribe given subscriber to query. By default, returns a channel with cap=1. Error is returned if it fails to subscribe. Channel is never closed to prevent clients from seeing an erroneus event.
func (*WSEvents) TxInfoSearch ¶
func (*WSEvents) UnconfirmedTxs ¶
func (w *WSEvents) UnconfirmedTxs(limit int) (*ctypes.ResultUnconfirmedTxs, error)
func (*WSEvents) Unsubscribe ¶
Unsubscribe implements EventsClient by using WSClient to unsubscribe given subscriber from query.
func (*WSEvents) UnsubscribeAll ¶
UnsubscribeAll implements EventsClient by using WSClient to unsubscribe given subscriber from all the queries.
func (*WSEvents) Validators ¶
func (w *WSEvents) Validators(height *int64) (*ctypes.ResultValidators, error)
func (*WSEvents) WaitForEventResponse ¶
func (w *WSEvents) WaitForEventResponse(requestId interface{}, in chan rpctypes.RPCResponse, eventOut chan ctypes.ResultEvent, quit chan struct{})