Skip to content

Commit

Permalink
rpcclient: Export receiveFuture
Browse files Browse the repository at this point in the history
This facilitates using custom commands with rpcclient.

See #1083
  • Loading branch information
JeremyRand committed Jan 5, 2020
1 parent 7ff174b commit 13cd083
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 106 deletions.
38 changes: 19 additions & 19 deletions rpcclient/chain.go
Expand Up @@ -22,7 +22,7 @@ type FutureGetBestBlockHashResult chan *Response
// Receive waits for the Response promised by the future and returns the hash of
// the best block in the longest block chain.
func (r FutureGetBestBlockHashResult) Receive() (*chainhash.Hash, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -59,7 +59,7 @@ type FutureGetBlockResult chan *Response
// Receive waits for the Response promised by the future and returns the raw
// block requested from the server given its hash.
func (r FutureGetBlockResult) Receive() (*wire.MsgBlock, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -116,7 +116,7 @@ type FutureGetBlockVerboseResult chan *Response
// Receive waits for the Response promised by the future and returns the data
// structure from the server with information about the requested block.
func (r FutureGetBlockVerboseResult) Receive() (*btcjson.GetBlockVerboseResult, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -185,7 +185,7 @@ type FutureGetBlockCountResult chan *Response
// Receive waits for the Response promised by the future and returns the number
// of blocks in the longest block chain.
func (r FutureGetBlockCountResult) Receive() (int64, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -221,7 +221,7 @@ type FutureGetDifficultyResult chan *Response
// Receive waits for the Response promised by the future and returns the
// proof-of-work difficulty as a multiple of the minimum difficulty.
func (r FutureGetDifficultyResult) Receive() (float64, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -298,7 +298,7 @@ func unmarshalGetBlockChainInfoResultSoftForks(chainInfo *btcjson.GetBlockChainI
// Receive waits for the Response promised by the future and returns chain info
// result provided by the server.
func (r FutureGetBlockChainInfoResult) Receive() (*btcjson.GetBlockChainInfoResult, error) {
res, err := receiveFuture(r.Response)
res, err := ReceiveFuture(r.Response)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -349,7 +349,7 @@ type FutureGetBlockHashResult chan *Response
// Receive waits for the Response promised by the future and returns the hash of
// the block in the best block chain at the given height.
func (r FutureGetBlockHashResult) Receive() (*chainhash.Hash, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -386,7 +386,7 @@ type FutureGetBlockHeaderResult chan *Response
// Receive waits for the Response promised by the future and returns the
// blockheader requested from the server given its hash.
func (r FutureGetBlockHeaderResult) Receive() (*wire.BlockHeader, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -443,7 +443,7 @@ type FutureGetBlockHeaderVerboseResult chan *Response
// Receive waits for the Response promised by the future and returns the
// data structure of the blockheader requested from the server given its hash.
func (r FutureGetBlockHeaderVerboseResult) Receive() (*btcjson.GetBlockHeaderVerboseResult, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -489,7 +489,7 @@ type FutureGetMempoolEntryResult chan *Response
// structure with information about the transaction in the memory pool given
// its hash.
func (r FutureGetMempoolEntryResult) Receive() (*btcjson.GetMempoolEntryResult, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -527,7 +527,7 @@ type FutureGetRawMempoolResult chan *Response
// Receive waits for the Response promised by the future and returns the hashes
// of all transactions in the memory pool.
func (r FutureGetRawMempoolResult) Receive() ([]*chainhash.Hash, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -578,7 +578,7 @@ type FutureGetRawMempoolVerboseResult chan *Response
// transaction hashes to an associated data structure with information about the
// transaction for all transactions in the memory pool.
func (r FutureGetRawMempoolVerboseResult) Receive() (map[string]btcjson.GetRawMempoolVerboseResult, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -619,7 +619,7 @@ type FutureEstimateFeeResult chan *Response
// Receive waits for the Response promised by the future and returns the info
// provided by the server.
func (r FutureEstimateFeeResult) Receive() (float64, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return -1, err
}
Expand Down Expand Up @@ -658,7 +658,7 @@ type FutureVerifyChainResult chan *Response
// or not the chain verified based on the check level and number of blocks
// to verify specified in the original call.
func (r FutureVerifyChainResult) Receive() (bool, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -745,7 +745,7 @@ type FutureGetTxOutResult chan *Response
// Receive waits for the Response promised by the future and returns a
// transaction given its hash.
func (r FutureGetTxOutResult) Receive() (*btcjson.GetTxOutResult, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -800,7 +800,7 @@ type FutureRescanBlocksResult chan *Response
// NOTE: This is a btcsuite extension ported from
// github.com/decred/dcrrpcclient.
func (r FutureRescanBlocksResult) Receive() ([]btcjson.RescannedBlock, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -849,7 +849,7 @@ type FutureInvalidateBlockResult chan *Response
// Receive waits for the Response promised by the future and returns the raw
// block requested from the server given its hash.
func (r FutureInvalidateBlockResult) Receive() error {
_, err := receiveFuture(r)
_, err := ReceiveFuture(r)

return err
}
Expand Down Expand Up @@ -881,7 +881,7 @@ type FutureGetCFilterResult chan *Response
// Receive waits for the Response promised by the future and returns the raw
// filter requested from the server given its block hash.
func (r FutureGetCFilterResult) Receive() (*wire.MsgCFilter, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -936,7 +936,7 @@ type FutureGetCFilterHeaderResult chan *Response
// Receive waits for the Response promised by the future and returns the raw
// filter header requested from the server given its block hash.
func (r FutureGetCFilterHeaderResult) Receive() (*wire.MsgCFHeaders, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return nil, err
}
Expand Down
18 changes: 9 additions & 9 deletions rpcclient/extensions.go
Expand Up @@ -26,7 +26,7 @@ type FutureDebugLevelResult chan *Response
// of setting the debug logging level to the passed level specification or the
// list of of the available subsystems for the special keyword 'show'.
func (r FutureDebugLevelResult) Receive() (string, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -72,7 +72,7 @@ type FutureCreateEncryptedWalletResult chan *Response

// Receive waits for and returns the error Response promised by the future.
func (r FutureCreateEncryptedWalletResult) Receive() error {
_, err := receiveFuture(r)
_, err := ReceiveFuture(r)
return err
}

Expand Down Expand Up @@ -107,7 +107,7 @@ type FutureListAddressTransactionsResult chan *Response
// Receive waits for the Response promised by the future and returns information
// about all transactions associated with the provided addresses.
func (r FutureListAddressTransactionsResult) Receive() ([]btcjson.ListTransactionsResult, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -153,7 +153,7 @@ type FutureGetBestBlockResult chan *Response
// Receive waits for the Response promised by the future and returns the hash
// and height of the block in the longest (best) chain.
func (r FutureGetBestBlockResult) Receive() (*chainhash.Hash, int32, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return nil, 0, err
}
Expand Down Expand Up @@ -201,7 +201,7 @@ type FutureGetCurrentNetResult chan *Response
// Receive waits for the Response promised by the future and returns the network
// the server is running on.
func (r FutureGetCurrentNetResult) Receive() (wire.BitcoinNet, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -248,7 +248,7 @@ type FutureGetHeadersResult chan *Response
// NOTE: This is a btcsuite extension ported from
// github.com/decred/dcrrpcclient.
func (r FutureGetHeadersResult) Receive() ([]wire.BlockHeader, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -312,7 +312,7 @@ type FutureExportWatchingWalletResult chan *Response
// Receive waits for the Response promised by the future and returns the
// exported wallet.
func (r FutureExportWatchingWalletResult) Receive() ([]byte, []byte, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -381,7 +381,7 @@ type FutureSessionResult chan *Response
// Receive waits for the Response promised by the future and returns the
// session result.
func (r FutureSessionResult) Receive() (*btcjson.SessionResult, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -436,7 +436,7 @@ type FutureVersionResult chan *Response
// github.com/decred/dcrrpcclient.
func (r FutureVersionResult) Receive() (map[string]btcjson.VersionResult,
error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions rpcclient/infrastructure.go
Expand Up @@ -816,11 +816,11 @@ func newFutureError(err error) chan *Response {
return responseChan
}

// receiveFuture receives from the passed futureResult channel to extract a
// ReceiveFuture receives from the passed futureResult channel to extract a
// reply or any errors. The examined errors include an error in the
// futureResult and the error in the reply from the server. This will block
// until the result is available on the passed channel.
func receiveFuture(f chan *Response) ([]byte, error) {
func ReceiveFuture(f chan *Response) ([]byte, error) {
// Wait for a response on the returned channel.
r := <-f
return r.result, r.err
Expand Down Expand Up @@ -926,7 +926,7 @@ func (c *Client) SendCmd(cmd interface{}) chan *Response {
func (c *Client) SendCmdAndWait(cmd interface{}) (interface{}, error) {
// Marshal the command to JSON-RPC, send it to the connected server, and
// wait for a response on the returned channel.
return receiveFuture(c.SendCmd(cmd))
return ReceiveFuture(c.SendCmd(cmd))
}

// Disconnected returns whether or not the server is disconnected. If a
Expand Down
18 changes: 9 additions & 9 deletions rpcclient/mining.go
Expand Up @@ -21,7 +21,7 @@ type FutureGenerateResult chan *Response
// Receive waits for the Response promised by the future and returns a list of
// block hashes generated by the call.
func (r FutureGenerateResult) Receive() ([]*chainhash.Hash, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -68,7 +68,7 @@ type FutureGetGenerateResult chan *Response
// Receive waits for the Response promised by the future and returns true if the
// server is set to mine, otherwise false.
func (r FutureGetGenerateResult) Receive() (bool, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -105,7 +105,7 @@ type FutureSetGenerateResult chan *Response
// Receive waits for the Response promised by the future and returns an error if
// any occurred when setting the server to generate coins (mine) or not.
func (r FutureSetGenerateResult) Receive() error {
_, err := receiveFuture(r)
_, err := ReceiveFuture(r)
return err
}

Expand All @@ -132,7 +132,7 @@ type FutureGetHashesPerSecResult chan *Response
// hashes per second performance measurement while generating coins (mining).
// Zero is returned if the server is not mining.
func (r FutureGetHashesPerSecResult) Receive() (int64, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return -1, err
}
Expand Down Expand Up @@ -171,7 +171,7 @@ type FutureGetMiningInfoResult chan *Response
// Receive waits for the Response promised by the future and returns the mining
// information.
func (r FutureGetMiningInfoResult) Receive() (*btcjson.GetMiningInfoResult, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -209,7 +209,7 @@ type FutureGetNetworkHashPS chan *Response
// estimated network hashes per second for the block heights provided by the
// parameters.
func (r FutureGetNetworkHashPS) Receive() (int64, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return -1, err
}
Expand Down Expand Up @@ -291,7 +291,7 @@ type FutureGetWork chan *Response
// Receive waits for the Response promised by the future and returns the hash
// data to work on.
func (r FutureGetWork) Receive() (*btcjson.GetWorkResult, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -330,7 +330,7 @@ type FutureGetWorkSubmit chan *Response
// Receive waits for the Response promised by the future and returns whether
// or not the submitted block header was accepted.
func (r FutureGetWorkSubmit) Receive() (bool, error) {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -370,7 +370,7 @@ type FutureSubmitBlockResult chan *Response
// Receive waits for the Response promised by the future and returns an error if
// any occurred when submitting the block.
func (r FutureSubmitBlockResult) Receive() error {
res, err := receiveFuture(r)
res, err := ReceiveFuture(r)
if err != nil {
return err
}
Expand Down

0 comments on commit 13cd083

Please sign in to comment.