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 Jul 24, 2019
1 parent 6384443 commit 9bb754a
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 105 deletions.
38 changes: 19 additions & 19 deletions rpcclient/chain.go
Original file line number Diff line number Diff line change
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 @@ -258,7 +258,7 @@ type FutureGetBlockChainInfoResult chan *Response
// 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)
res, err := ReceiveFuture(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -294,7 +294,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 @@ -331,7 +331,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 @@ -388,7 +388,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 @@ -434,7 +434,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 @@ -472,7 +472,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 @@ -523,7 +523,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 @@ -564,7 +564,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 @@ -603,7 +603,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 @@ -690,7 +690,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 @@ -745,7 +745,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 @@ -794,7 +794,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 @@ -826,7 +826,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 @@ -881,7 +881,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -788,11 +788,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 @@ -898,7 +898,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
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit 9bb754a

Please sign in to comment.