diff --git a/rpcclient/chain.go b/rpcclient/chain.go index 636a5d52a0..382a63961a 100644 --- a/rpcclient/chain.go +++ b/rpcclient/chain.go @@ -28,8 +28,8 @@ 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) +func (r FutureGetBestBlockHashResult) Receive(ctx context.Context) (*chainhash.Hash, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -56,7 +56,7 @@ func (c *Client) GetBestBlockHashAsync(ctx context.Context) FutureGetBestBlockHa // GetBestBlockHash returns the hash of the best block in the longest block // chain. func (c *Client) GetBestBlockHash(ctx context.Context) (*chainhash.Hash, error) { - return c.GetBestBlockHashAsync(ctx).Receive() + return c.GetBestBlockHashAsync(ctx).Receive(ctx) } // FutureGetBlockResult is a future promise to deliver the result of a @@ -65,8 +65,8 @@ 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) +func (r FutureGetBlockResult) Receive(ctx context.Context) (*wire.MsgBlock, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -113,7 +113,7 @@ func (c *Client) GetBlockAsync(ctx context.Context, blockHash *chainhash.Hash) F // See GetBlockVerbose to retrieve a data structure with information about the // block instead. func (c *Client) GetBlock(ctx context.Context, blockHash *chainhash.Hash) (*wire.MsgBlock, error) { - return c.GetBlockAsync(ctx, blockHash).Receive() + return c.GetBlockAsync(ctx, blockHash).Receive(ctx) } // FutureGetBlockVerboseResult is a future promise to deliver the result of a @@ -122,8 +122,8 @@ 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() (*chainjson.GetBlockVerboseResult, error) { - res, err := receiveFuture(r) +func (r FutureGetBlockVerboseResult) Receive(ctx context.Context) (*chainjson.GetBlockVerboseResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -157,7 +157,7 @@ func (c *Client) GetBlockVerboseAsync(ctx context.Context, blockHash *chainhash. // // See GetBlock to retrieve a raw block instead. func (c *Client) GetBlockVerbose(ctx context.Context, blockHash *chainhash.Hash, verboseTx bool) (*chainjson.GetBlockVerboseResult, error) { - return c.GetBlockVerboseAsync(ctx, blockHash, verboseTx).Receive() + return c.GetBlockVerboseAsync(ctx, blockHash, verboseTx).Receive(ctx) } // FutureGetBlockCountResult is a future promise to deliver the result of a @@ -166,8 +166,8 @@ 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) +func (r FutureGetBlockCountResult) Receive(ctx context.Context) (int64, error) { + res, err := receiveFuture(ctx, r) if err != nil { return 0, err } @@ -193,7 +193,7 @@ func (c *Client) GetBlockCountAsync(ctx context.Context) FutureGetBlockCountResu // GetBlockCount returns the number of blocks in the longest block chain. func (c *Client) GetBlockCount(ctx context.Context) (int64, error) { - return c.GetBlockCountAsync(ctx).Receive() + return c.GetBlockCountAsync(ctx).Receive(ctx) } // FutureGetDifficultyResult is a future promise to deliver the result of a @@ -202,8 +202,8 @@ 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) +func (r FutureGetDifficultyResult) Receive(ctx context.Context) (float64, error) { + res, err := receiveFuture(ctx, r) if err != nil { return 0, err } @@ -230,7 +230,7 @@ func (c *Client) GetDifficultyAsync(ctx context.Context) FutureGetDifficultyResu // GetDifficulty returns the proof-of-work difficulty as a multiple of the // minimum difficulty. func (c *Client) GetDifficulty(ctx context.Context) (float64, error) { - return c.GetDifficultyAsync(ctx).Receive() + return c.GetDifficultyAsync(ctx).Receive(ctx) } // FutureGetBlockChainInfoResult is a future promise to deliver the result of a @@ -239,8 +239,8 @@ type FutureGetBlockChainInfoResult chan *response // Receive waits for the response promised by the future and returns the info // provided by the server. -func (r FutureGetBlockChainInfoResult) Receive() (*chainjson.GetBlockChainInfoResult, error) { - res, err := receiveFuture(r) +func (r FutureGetBlockChainInfoResult) Receive(ctx context.Context) (*chainjson.GetBlockChainInfoResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -268,7 +268,7 @@ func (c *Client) GetBlockChainInfoAsync(ctx context.Context) FutureGetBlockChain // GetBlockChainInfo returns information about the current state of the block // chain. func (c *Client) GetBlockChainInfo(ctx context.Context) (*chainjson.GetBlockChainInfoResult, error) { - return c.GetBlockChainInfoAsync(ctx).Receive() + return c.GetBlockChainInfoAsync(ctx).Receive(ctx) } // FutureGetInfoResult is a future promise to deliver the result of a @@ -277,8 +277,8 @@ type FutureGetInfoResult chan *response // Receive waits for the response promised by the future and returns the info // provided by the server. -func (r FutureGetInfoResult) Receive() (*chainjson.InfoChainResult, error) { - res, err := receiveFuture(r) +func (r FutureGetInfoResult) Receive(ctx context.Context) (*chainjson.InfoChainResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -305,7 +305,7 @@ func (c *Client) GetInfoAsync(ctx context.Context) FutureGetInfoResult { // GetInfo returns information about the current state of the full node process. func (c *Client) GetInfo(ctx context.Context) (*chainjson.InfoChainResult, error) { - return c.GetInfoAsync(ctx).Receive() + return c.GetInfoAsync(ctx).Receive(ctx) } // FutureGetBlockHashResult is a future promise to deliver the result of a @@ -314,8 +314,8 @@ 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) +func (r FutureGetBlockHashResult) Receive(ctx context.Context) (*chainhash.Hash, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -342,7 +342,7 @@ func (c *Client) GetBlockHashAsync(ctx context.Context, blockHeight int64) Futur // GetBlockHash returns the hash of the block in the best block chain at the // given height. func (c *Client) GetBlockHash(ctx context.Context, blockHeight int64) (*chainhash.Hash, error) { - return c.GetBlockHashAsync(ctx, blockHeight).Receive() + return c.GetBlockHashAsync(ctx, blockHeight).Receive(ctx) } // FutureGetBlockHeaderResult is a future promise to deliver the result of a @@ -351,8 +351,8 @@ 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) +func (r FutureGetBlockHeaderResult) Receive(ctx context.Context) (*wire.BlockHeader, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -392,7 +392,7 @@ func (c *Client) GetBlockHeaderAsync(ctx context.Context, hash *chainhash.Hash) // GetBlockHeader returns the hash of the block in the best block chain at the // given height. func (c *Client) GetBlockHeader(ctx context.Context, hash *chainhash.Hash) (*wire.BlockHeader, error) { - return c.GetBlockHeaderAsync(ctx, hash).Receive() + return c.GetBlockHeaderAsync(ctx, hash).Receive(ctx) } // FutureGetBlockHeaderVerboseResult is a future promise to deliver the result of a @@ -401,8 +401,8 @@ type FutureGetBlockHeaderVerboseResult chan *response // Receive waits for the response promised by the future and returns a data // structure of the block header requested from the server given its hash. -func (r FutureGetBlockHeaderVerboseResult) Receive() (*chainjson.GetBlockHeaderVerboseResult, error) { - res, err := receiveFuture(r) +func (r FutureGetBlockHeaderVerboseResult) Receive(ctx context.Context) (*chainjson.GetBlockHeaderVerboseResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -431,7 +431,7 @@ func (c *Client) GetBlockHeaderVerboseAsync(ctx context.Context, hash *chainhash // // See GetBlockHeader to retrieve a raw block header instead. func (c *Client) GetBlockHeaderVerbose(ctx context.Context, hash *chainhash.Hash) (*chainjson.GetBlockHeaderVerboseResult, error) { - return c.GetBlockHeaderVerboseAsync(ctx, hash).Receive() + return c.GetBlockHeaderVerboseAsync(ctx, hash).Receive(ctx) } // FutureGetBlockSubsidyResult is a future promise to deliver the result of a @@ -441,8 +441,8 @@ type FutureGetBlockSubsidyResult chan *response // Receive waits for the response promised by the future and returns a data // structure of the block subsidy requested from the server given its height // and number of voters. -func (r FutureGetBlockSubsidyResult) Receive() (*chainjson.GetBlockSubsidyResult, error) { - res, err := receiveFuture(r) +func (r FutureGetBlockSubsidyResult) Receive(ctx context.Context) (*chainjson.GetBlockSubsidyResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -469,7 +469,7 @@ func (c *Client) GetBlockSubsidyAsync(ctx context.Context, height int64, voters // GetBlockSubsidy returns a data structure of the block subsidy // from the server given its height and number of voters. func (c *Client) GetBlockSubsidy(ctx context.Context, height int64, voters uint16) (*chainjson.GetBlockSubsidyResult, error) { - return c.GetBlockSubsidyAsync(ctx, height, voters).Receive() + return c.GetBlockSubsidyAsync(ctx, height, voters).Receive(ctx) } // FutureGetCoinSupplyResult is a future promise to deliver the result of a @@ -478,8 +478,8 @@ type FutureGetCoinSupplyResult chan *response // Receive waits for the response promised by the future and returns the // current coin supply -func (r FutureGetCoinSupplyResult) Receive() (dcrutil.Amount, error) { - res, err := receiveFuture(r) +func (r FutureGetCoinSupplyResult) Receive(ctx context.Context) (dcrutil.Amount, error) { + res, err := receiveFuture(ctx, r) if err != nil { return 0, err } @@ -505,7 +505,7 @@ func (c *Client) GetCoinSupplyAsync(ctx context.Context) FutureGetCoinSupplyResu // GetCoinSupply returns the current coin supply func (c *Client) GetCoinSupply(ctx context.Context) (dcrutil.Amount, error) { - return c.GetCoinSupplyAsync(ctx).Receive() + return c.GetCoinSupplyAsync(ctx).Receive(ctx) } // FutureGetRawMempoolResult is a future promise to deliver the result of a @@ -514,8 +514,8 @@ 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) +func (r FutureGetRawMempoolResult) Receive(ctx context.Context) ([]*chainhash.Hash, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -557,7 +557,7 @@ func (c *Client) GetRawMempoolAsync(ctx context.Context, txType chainjson.GetRaw // See GetRawMempoolVerbose to retrieve data structures with information about // the transactions instead. func (c *Client) GetRawMempool(ctx context.Context, txType chainjson.GetRawMempoolTxTypeCmd) ([]*chainhash.Hash, error) { - return c.GetRawMempoolAsync(ctx, txType).Receive() + return c.GetRawMempoolAsync(ctx, txType).Receive(ctx) } // FutureGetRawMempoolVerboseResult is a future promise to deliver the result of @@ -567,8 +567,8 @@ type FutureGetRawMempoolVerboseResult chan *response // Receive waits for the response promised by the future and returns a map of // 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]chainjson.GetRawMempoolVerboseResult, error) { - res, err := receiveFuture(r) +func (r FutureGetRawMempoolVerboseResult) Receive(ctx context.Context) (map[string]chainjson.GetRawMempoolVerboseResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -600,7 +600,7 @@ func (c *Client) GetRawMempoolVerboseAsync(ctx context.Context, txType chainjson // // See GetRawMempool to retrieve only the transaction hashes instead. func (c *Client) GetRawMempoolVerbose(ctx context.Context, txType chainjson.GetRawMempoolTxTypeCmd) (map[string]chainjson.GetRawMempoolVerboseResult, error) { - return c.GetRawMempoolVerboseAsync(ctx, txType).Receive() + return c.GetRawMempoolVerboseAsync(ctx, txType).Receive(ctx) } // FutureVerifyChainResult is a future promise to deliver the result of a @@ -611,8 +611,8 @@ type FutureVerifyChainResult chan *response // Receive waits for the response promised by the future and returns whether // 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) +func (r FutureVerifyChainResult) Receive(ctx context.Context) (bool, error) { + res, err := receiveFuture(ctx, r) if err != nil { return false, err } @@ -632,8 +632,8 @@ type FutureGetChainTipsResult chan *response // Receive waits for the response promised by the future and returns slice of // all known tips in the block tree. -func (r FutureGetChainTipsResult) Receive() ([]chainjson.GetChainTipsResult, error) { - res, err := receiveFuture(r) +func (r FutureGetChainTipsResult) Receive(ctx context.Context) ([]chainjson.GetChainTipsResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -659,7 +659,7 @@ func (c *Client) GetChainTipsAsync(ctx context.Context) FutureGetChainTipsResult // GetChainTips returns all known tips in the block tree. func (c *Client) GetChainTips(ctx context.Context) ([]chainjson.GetChainTipsResult, error) { - return c.GetChainTipsAsync(ctx).Receive() + return c.GetChainTipsAsync(ctx).Receive(ctx) } // VerifyChainAsync returns an instance of a type that can be used to get the @@ -677,7 +677,7 @@ func (c *Client) VerifyChainAsync(ctx context.Context) FutureVerifyChainResult { // // See VerifyChainLevel and VerifyChainBlocks to override the defaults. func (c *Client) VerifyChain(ctx context.Context) (bool, error) { - return c.VerifyChainAsync(ctx).Receive() + return c.VerifyChainAsync(ctx).Receive(ctx) } // VerifyChainLevelAsync returns an instance of a type that can be used to get @@ -700,7 +700,7 @@ func (c *Client) VerifyChainLevelAsync(ctx context.Context, checkLevel int64) Fu // See VerifyChain to use the default check level and VerifyChainBlocks to // override the number of blocks to verify. func (c *Client) VerifyChainLevel(ctx context.Context, checkLevel int64) (bool, error) { - return c.VerifyChainLevelAsync(ctx, checkLevel).Receive() + return c.VerifyChainLevelAsync(ctx, checkLevel).Receive(ctx) } // VerifyChainBlocksAsync returns an instance of a type that can be used to get @@ -725,7 +725,7 @@ func (c *Client) VerifyChainBlocksAsync(ctx context.Context, checkLevel, numBloc // // See VerifyChain and VerifyChainLevel to use defaults. func (c *Client) VerifyChainBlocks(ctx context.Context, checkLevel, numBlocks int64) (bool, error) { - return c.VerifyChainBlocksAsync(ctx, checkLevel, numBlocks).Receive() + return c.VerifyChainBlocksAsync(ctx, checkLevel, numBlocks).Receive(ctx) } // FutureGetTxOutResult is a future promise to deliver the result of a @@ -734,8 +734,8 @@ type FutureGetTxOutResult chan *response // Receive waits for the response promised by the future and returns a // transaction given its hash. -func (r FutureGetTxOutResult) Receive() (*chainjson.GetTxOutResult, error) { - res, err := receiveFuture(r) +func (r FutureGetTxOutResult) Receive(ctx context.Context) (*chainjson.GetTxOutResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -774,7 +774,7 @@ func (c *Client) GetTxOutAsync(ctx context.Context, txHash *chainhash.Hash, inde // GetTxOut returns the transaction output info if it's unspent and // nil, otherwise. func (c *Client) GetTxOut(ctx context.Context, txHash *chainhash.Hash, index uint32, mempool bool) (*chainjson.GetTxOutResult, error) { - return c.GetTxOutAsync(ctx, txHash, index, mempool).Receive() + return c.GetTxOutAsync(ctx, txHash, index, mempool).Receive(ctx) } // FutureRescanResult is a future promise to deliver the result of a @@ -783,8 +783,8 @@ type FutureRescanResult chan *response // Receive waits for the response promised by the future and returns the // discovered rescan data. -func (r FutureRescanResult) Receive() (*chainjson.RescanResult, error) { - res, err := receiveFuture(r) +func (r FutureRescanResult) Receive(ctx context.Context) (*chainjson.RescanResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -817,7 +817,7 @@ func (c *Client) RescanAsync(ctx context.Context, blockHashes []chainhash.Hash) // client's loaded transaction filter. The blocks do not need to be on the main // chain, but they do need to be adjacent to each other. func (c *Client) Rescan(ctx context.Context, blockHashes []chainhash.Hash) (*chainjson.RescanResult, error) { - return c.RescanAsync(ctx, blockHashes).Receive() + return c.RescanAsync(ctx, blockHashes).Receive(ctx) } // FutureGetCFilterResult is a future promise to deliver the result of a @@ -826,8 +826,8 @@ type FutureGetCFilterResult chan *response // Receive waits for the response promised by the future and returns the // discovered rescan data. -func (r FutureGetCFilterResult) Receive() (*gcs.FilterV1, error) { - res, err := receiveFuture(r) +func (r FutureGetCFilterResult) Receive(ctx context.Context) (*gcs.FilterV1, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -867,7 +867,7 @@ func (c *Client) GetCFilterAsync(ctx context.Context, blockHash *chainhash.Hash, // GetCFilter returns the committed filter of type filterType for a block. func (c *Client) GetCFilter(ctx context.Context, blockHash *chainhash.Hash, filterType wire.FilterType) (*gcs.FilterV1, error) { - return c.GetCFilterAsync(ctx, blockHash, filterType).Receive() + return c.GetCFilterAsync(ctx, blockHash, filterType).Receive(ctx) } // FutureGetCFilterHeaderResult is a future promise to deliver the result of a @@ -876,8 +876,8 @@ type FutureGetCFilterHeaderResult chan *response // Receive waits for the response promised by the future and returns the // discovered rescan data. -func (r FutureGetCFilterHeaderResult) Receive() (*chainhash.Hash, error) { - res, err := receiveFuture(r) +func (r FutureGetCFilterHeaderResult) Receive(ctx context.Context) (*chainhash.Hash, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -914,7 +914,7 @@ func (c *Client) GetCFilterHeaderAsync(ctx context.Context, blockHash *chainhash // GetCFilterHeader returns the committed filter header hash of type filterType // for a block. func (c *Client) GetCFilterHeader(ctx context.Context, blockHash *chainhash.Hash, filterType wire.FilterType) (*chainhash.Hash, error) { - return c.GetCFilterHeaderAsync(ctx, blockHash, filterType).Receive() + return c.GetCFilterHeaderAsync(ctx, blockHash, filterType).Receive(ctx) } // CFilterV2Result is the result of calling the GetCFilterV2 and @@ -932,8 +932,8 @@ type FutureGetCFilterV2Result chan *response // Receive waits for the response promised by the future and returns the // discovered rescan data. -func (r FutureGetCFilterV2Result) Receive() (*CFilterV2Result, error) { - res, err := receiveFuture(r) +func (r FutureGetCFilterV2Result) Receive(ctx context.Context) (*CFilterV2Result, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -989,7 +989,7 @@ func (c *Client) GetCFilterV2Async(ctx context.Context, blockHash *chainhash.Has // with a proof that can be used to prove the filter is committed to by the // block header. func (c *Client) GetCFilterV2(ctx context.Context, blockHash *chainhash.Hash) (*CFilterV2Result, error) { - return c.GetCFilterV2Async(ctx, blockHash).Receive() + return c.GetCFilterV2Async(ctx, blockHash).Receive(ctx) } // FutureEstimateSmartFeeResult is a future promise to deliver the result of a @@ -998,8 +998,8 @@ type FutureEstimateSmartFeeResult chan *response // Receive waits for the response promised by the future and returns a fee // estimation for the given target confirmation window and mode. -func (r FutureEstimateSmartFeeResult) Receive() (float64, error) { - res, err := receiveFuture(r) +func (r FutureEstimateSmartFeeResult) Receive(ctx context.Context) (float64, error) { + res, err := receiveFuture(ctx, r) if err != nil { return 0, err } @@ -1034,5 +1034,5 @@ func (c *Client) EstimateSmartFeeAsync(ctx context.Context, confirmations int64, // // As of 2019-01, only the default conservative mode is supported by dcrd. func (c *Client) EstimateSmartFee(ctx context.Context, confirmations int64, mode chainjson.EstimateSmartFeeMode) (float64, error) { - return c.EstimateSmartFeeAsync(ctx, confirmations, mode).Receive() + return c.EstimateSmartFeeAsync(ctx, confirmations, mode).Receive(ctx) } diff --git a/rpcclient/extensions.go b/rpcclient/extensions.go index 7eca0878ad..3f5fe15f90 100644 --- a/rpcclient/extensions.go +++ b/rpcclient/extensions.go @@ -27,8 +27,8 @@ type FutureDebugLevelResult chan *response // Receive waits for the response promised by the future and returns the result // of setting the debug logging level to the passed level specification or the // list of the available subsystems for the special keyword 'show'. -func (r FutureDebugLevelResult) Receive() (string, error) { - res, err := receiveFuture(r) +func (r FutureDebugLevelResult) Receive(ctx context.Context) (string, error) { + res, err := receiveFuture(ctx, r) if err != nil { return "", err } @@ -65,7 +65,7 @@ func (c *Client) DebugLevelAsync(ctx context.Context, levelSpec string) FutureDe // // NOTE: This is a dcrd extension. func (c *Client) DebugLevel(ctx context.Context, levelSpec string) (string, error) { - return c.DebugLevelAsync(ctx, levelSpec).Receive() + return c.DebugLevelAsync(ctx, levelSpec).Receive(ctx) } // FutureEstimateStakeDiffResult is a future promise to deliver the result of a @@ -74,8 +74,8 @@ type FutureEstimateStakeDiffResult 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 FutureEstimateStakeDiffResult) Receive() (*chainjson.EstimateStakeDiffResult, error) { - res, err := receiveFuture(r) +func (r FutureEstimateStakeDiffResult) Receive(ctx context.Context) (*chainjson.EstimateStakeDiffResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -107,7 +107,7 @@ func (c *Client) EstimateStakeDiffAsync(ctx context.Context, tickets *uint32) Fu // // NOTE: This is a dcrd extension. func (c *Client) EstimateStakeDiff(ctx context.Context, tickets *uint32) (*chainjson.EstimateStakeDiffResult, error) { - return c.EstimateStakeDiffAsync(ctx, tickets).Receive() + return c.EstimateStakeDiffAsync(ctx, tickets).Receive(ctx) } // FutureExistsAddressResult is a future promise to deliver the result @@ -116,8 +116,8 @@ type FutureExistsAddressResult chan *response // Receive waits for the response promised by the future and returns whether or // not an address exists in the blockchain or mempool. -func (r FutureExistsAddressResult) Receive() (bool, error) { - res, err := receiveFuture(r) +func (r FutureExistsAddressResult) Receive(ctx context.Context) (bool, error) { + res, err := receiveFuture(ctx, r) if err != nil { return false, err } @@ -144,7 +144,7 @@ func (c *Client) ExistsAddressAsync(ctx context.Context, address dcrutil.Address // // NOTE: This is a dcrd extension. func (c *Client) ExistsAddress(ctx context.Context, address dcrutil.Address) (bool, error) { - return c.ExistsAddressAsync(ctx, address).Receive() + return c.ExistsAddressAsync(ctx, address).Receive(ctx) } // FutureExistsAddressesResult is a future promise to deliver the result @@ -154,8 +154,8 @@ type FutureExistsAddressesResult chan *response // Receive waits for the response promised by the future and returns whether // or not the addresses exist. -func (r FutureExistsAddressesResult) Receive() (string, error) { - res, err := receiveFuture(r) +func (r FutureExistsAddressesResult) Receive(ctx context.Context) (string, error) { + res, err := receiveFuture(ctx, r) if err != nil { return "", err } @@ -187,7 +187,7 @@ func (c *Client) ExistsAddressesAsync(ctx context.Context, addresses []dcrutil.A // // NOTE: This is a dcrd extension. func (c *Client) ExistsAddresses(ctx context.Context, addresses []dcrutil.Address) (string, error) { - return c.ExistsAddressesAsync(ctx, addresses).Receive() + return c.ExistsAddressesAsync(ctx, addresses).Receive(ctx) } // FutureExistsMissedTicketsResult is a future promise to deliver the result of @@ -196,8 +196,8 @@ type FutureExistsMissedTicketsResult chan *response // Receive waits for the response promised by the future and returns whether // or not the ticket exists in the missed ticket database. -func (r FutureExistsMissedTicketsResult) Receive() (string, error) { - res, err := receiveFuture(r) +func (r FutureExistsMissedTicketsResult) Receive(ctx context.Context) (string, error) { + res, err := receiveFuture(ctx, r) if err != nil { return "", err } @@ -226,7 +226,7 @@ func (c *Client) ExistsMissedTicketsAsync(ctx context.Context, hashes []*chainha // ExistsMissedTickets returns a hex-encoded bitset describing whether or not // ticket hashes exists in the missed ticket database. func (c *Client) ExistsMissedTickets(ctx context.Context, hashes []*chainhash.Hash) (string, error) { - return c.ExistsMissedTicketsAsync(ctx, hashes).Receive() + return c.ExistsMissedTicketsAsync(ctx, hashes).Receive(ctx) } // FutureExistsExpiredTicketsResult is a future promise to deliver the result @@ -236,8 +236,8 @@ type FutureExistsExpiredTicketsResult chan *response // Receive waits for the response promised by the future and returns whether // or not the ticket exists in the live ticket database. -func (r FutureExistsExpiredTicketsResult) Receive() (string, error) { - res, err := receiveFuture(r) +func (r FutureExistsExpiredTicketsResult) Receive(ctx context.Context) (string, error) { + res, err := receiveFuture(ctx, r) if err != nil { return "", err } @@ -268,7 +268,7 @@ func (c *Client) ExistsExpiredTicketsAsync(ctx context.Context, hashes []*chainh // // NOTE: This is a dcrd extension. func (c *Client) ExistsExpiredTickets(ctx context.Context, hashes []*chainhash.Hash) (string, error) { - return c.ExistsExpiredTicketsAsync(ctx, hashes).Receive() + return c.ExistsExpiredTicketsAsync(ctx, hashes).Receive(ctx) } // FutureExistsLiveTicketResult is a future promise to deliver the result @@ -278,8 +278,8 @@ type FutureExistsLiveTicketResult chan *response // Receive waits for the response promised by the future and returns whether // or not the ticket exists in the live ticket database. -func (r FutureExistsLiveTicketResult) Receive() (bool, error) { - res, err := receiveFuture(r) +func (r FutureExistsLiveTicketResult) Receive(ctx context.Context) (bool, error) { + res, err := receiveFuture(ctx, r) if err != nil { return false, err } @@ -306,7 +306,7 @@ func (c *Client) ExistsLiveTicketAsync(ctx context.Context, hash *chainhash.Hash // // NOTE: This is a dcrd extension. func (c *Client) ExistsLiveTicket(ctx context.Context, hash *chainhash.Hash) (bool, error) { - return c.ExistsLiveTicketAsync(ctx, hash).Receive() + return c.ExistsLiveTicketAsync(ctx, hash).Receive(ctx) } // FutureExistsLiveTicketsResult is a future promise to deliver the result @@ -316,8 +316,8 @@ type FutureExistsLiveTicketsResult chan *response // Receive waits for the response promised by the future and returns whether // or not the ticket exists in the live ticket database. -func (r FutureExistsLiveTicketsResult) Receive() (string, error) { - res, err := receiveFuture(r) +func (r FutureExistsLiveTicketsResult) Receive(ctx context.Context) (string, error) { + res, err := receiveFuture(ctx, r) if err != nil { return "", err } @@ -348,7 +348,7 @@ func (c *Client) ExistsLiveTicketsAsync(ctx context.Context, hashes []*chainhash // // NOTE: This is a dcrd extension. func (c *Client) ExistsLiveTickets(ctx context.Context, hashes []*chainhash.Hash) (string, error) { - return c.ExistsLiveTicketsAsync(ctx, hashes).Receive() + return c.ExistsLiveTicketsAsync(ctx, hashes).Receive(ctx) } // FutureExistsMempoolTxsResult is a future promise to deliver the result @@ -358,8 +358,8 @@ type FutureExistsMempoolTxsResult chan *response // Receive waits for the response promised by the future and returns whether // or not the ticket exists in the mempool. -func (r FutureExistsMempoolTxsResult) Receive() (string, error) { - res, err := receiveFuture(r) +func (r FutureExistsMempoolTxsResult) Receive(ctx context.Context) (string, error) { + res, err := receiveFuture(ctx, r) if err != nil { return "", err } @@ -390,7 +390,7 @@ func (c *Client) ExistsMempoolTxsAsync(ctx context.Context, hashes []*chainhash. // // NOTE: This is a dcrd extension. func (c *Client) ExistsMempoolTxs(ctx context.Context, hashes []*chainhash.Hash) (string, error) { - return c.ExistsMempoolTxsAsync(ctx, hashes).Receive() + return c.ExistsMempoolTxsAsync(ctx, hashes).Receive(ctx) } // FutureGetBestBlockResult is a future promise to deliver the result of a @@ -399,8 +399,8 @@ 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, int64, error) { - res, err := receiveFuture(r) +func (r FutureGetBestBlockResult) Receive(ctx context.Context) (*chainhash.Hash, int64, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, 0, err } @@ -438,7 +438,7 @@ func (c *Client) GetBestBlockAsync(ctx context.Context) FutureGetBestBlockResult // // NOTE: This is a dcrd extension. func (c *Client) GetBestBlock(ctx context.Context) (*chainhash.Hash, int64, error) { - return c.GetBestBlockAsync(ctx).Receive() + return c.GetBestBlockAsync(ctx).Receive(ctx) } // FutureGetCurrentNetResult is a future promise to deliver the result of a @@ -447,8 +447,8 @@ 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.CurrencyNet, error) { - res, err := receiveFuture(r) +func (r FutureGetCurrentNetResult) Receive(ctx context.Context) (wire.CurrencyNet, error) { + res, err := receiveFuture(ctx, r) if err != nil { return 0, err } @@ -479,7 +479,7 @@ func (c *Client) GetCurrentNetAsync(ctx context.Context) FutureGetCurrentNetResu // // NOTE: This is a dcrd extension. func (c *Client) GetCurrentNet(ctx context.Context) (wire.CurrencyNet, error) { - return c.GetCurrentNetAsync(ctx).Receive() + return c.GetCurrentNetAsync(ctx).Receive(ctx) } // FutureGetHeadersResult is a future promise to deliver the result of a @@ -488,8 +488,8 @@ type FutureGetHeadersResult chan *response // Receive waits for the response promised by the future and returns the // getheaders result. -func (r FutureGetHeadersResult) Receive() (*chainjson.GetHeadersResult, error) { - res, err := receiveFuture(r) +func (r FutureGetHeadersResult) Receive(ctx context.Context) (*chainjson.GetHeadersResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -527,7 +527,7 @@ func (c *Client) GetHeadersAsync(ctx context.Context, blockLocators []*chainhash // returning all headers on the main chain after the first known block in the // locators, up until a block hash matches hashStop. func (c *Client) GetHeaders(ctx context.Context, blockLocators []*chainhash.Hash, hashStop *chainhash.Hash) (*chainjson.GetHeadersResult, error) { - return c.GetHeadersAsync(ctx, blockLocators, hashStop).Receive() + return c.GetHeadersAsync(ctx, blockLocators, hashStop).Receive(ctx) } // FutureGetStakeDifficultyResult is a future promise to deliver the result of a @@ -536,8 +536,8 @@ type FutureGetStakeDifficultyResult chan *response // Receive waits for the response promised by the future and returns the network // the server is running on. -func (r FutureGetStakeDifficultyResult) Receive() (*chainjson.GetStakeDifficultyResult, error) { - res, err := receiveFuture(r) +func (r FutureGetStakeDifficultyResult) Receive(ctx context.Context) (*chainjson.GetStakeDifficultyResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -568,7 +568,7 @@ func (c *Client) GetStakeDifficultyAsync(ctx context.Context) FutureGetStakeDiff // // NOTE: This is a dcrd extension. func (c *Client) GetStakeDifficulty(ctx context.Context) (*chainjson.GetStakeDifficultyResult, error) { - return c.GetStakeDifficultyAsync(ctx).Receive() + return c.GetStakeDifficultyAsync(ctx).Receive(ctx) } // FutureGetStakeVersionsResult is a future promise to deliver the result of a @@ -577,8 +577,8 @@ type FutureGetStakeVersionsResult chan *response // Receive waits for the response promised by the future and returns the network // the server is running on. -func (r FutureGetStakeVersionsResult) Receive() (*chainjson.GetStakeVersionsResult, error) { - res, err := receiveFuture(r) +func (r FutureGetStakeVersionsResult) Receive(ctx context.Context) (*chainjson.GetStakeVersionsResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -609,7 +609,7 @@ func (c *Client) GetStakeVersionInfoAsync(ctx context.Context, count int32) Futu // // NOTE: This is a dcrd extension. func (c *Client) GetStakeVersionInfo(ctx context.Context, count int32) (*chainjson.GetStakeVersionInfoResult, error) { - return c.GetStakeVersionInfoAsync(ctx, count).Receive() + return c.GetStakeVersionInfoAsync(ctx, count).Receive(ctx) } // FutureGetStakeVersionInfoResult is a future promise to deliver the result of a @@ -618,8 +618,8 @@ type FutureGetStakeVersionInfoResult chan *response // Receive waits for the response promised by the future and returns the network // the server is running on. -func (r FutureGetStakeVersionInfoResult) Receive() (*chainjson.GetStakeVersionInfoResult, error) { - res, err := receiveFuture(r) +func (r FutureGetStakeVersionInfoResult) Receive(ctx context.Context) (*chainjson.GetStakeVersionInfoResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -650,7 +650,7 @@ func (c *Client) GetStakeVersionsAsync(ctx context.Context, hash string, count i // // NOTE: This is a dcrd extension. func (c *Client) GetStakeVersions(ctx context.Context, hash string, count int32) (*chainjson.GetStakeVersionsResult, error) { - return c.GetStakeVersionsAsync(ctx, hash, count).Receive() + return c.GetStakeVersionsAsync(ctx, hash, count).Receive(ctx) } // FutureGetTicketPoolValueResult is a future promise to deliver the result of a @@ -659,8 +659,8 @@ type FutureGetTicketPoolValueResult chan *response // Receive waits for the response promised by the future and returns the network // the server is running on. -func (r FutureGetTicketPoolValueResult) Receive() (dcrutil.Amount, error) { - res, err := receiveFuture(r) +func (r FutureGetTicketPoolValueResult) Receive(ctx context.Context) (dcrutil.Amount, error) { + res, err := receiveFuture(ctx, r) if err != nil { return 0, err } @@ -697,7 +697,7 @@ func (c *Client) GetTicketPoolValueAsync(ctx context.Context) FutureGetTicketPoo // // NOTE: This is a dcrd extension. func (c *Client) GetTicketPoolValue(ctx context.Context) (dcrutil.Amount, error) { - return c.GetTicketPoolValueAsync(ctx).Receive() + return c.GetTicketPoolValueAsync(ctx).Receive(ctx) } // FutureGetVoteInfoResult is a future promise to deliver the result of a @@ -706,8 +706,8 @@ type FutureGetVoteInfoResult chan *response // Receive waits for the response promised by the future and returns the network // the server is running on. -func (r FutureGetVoteInfoResult) Receive() (*chainjson.GetVoteInfoResult, error) { - res, err := receiveFuture(r) +func (r FutureGetVoteInfoResult) Receive(ctx context.Context) (*chainjson.GetVoteInfoResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -739,7 +739,7 @@ func (c *Client) GetVoteInfoAsync(ctx context.Context, version uint32) FutureGet // // NOTE: This is a dcrd extension. func (c *Client) GetVoteInfo(ctx context.Context, version uint32) (*chainjson.GetVoteInfoResult, error) { - return c.GetVoteInfoAsync(ctx, version).Receive() + return c.GetVoteInfoAsync(ctx, version).Receive(ctx) } // FutureLiveTicketsResult is a future promise to deliver the result @@ -748,8 +748,8 @@ type FutureLiveTicketsResult chan *response // Receive waits for the response promised by the future and returns all // currently missed tickets from the missed ticket database. -func (r FutureLiveTicketsResult) Receive() ([]*chainhash.Hash, error) { - res, err := receiveFuture(r) +func (r FutureLiveTicketsResult) Receive(ctx context.Context) ([]*chainhash.Hash, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -786,7 +786,7 @@ func (c *Client) LiveTicketsAsync(ctx context.Context) FutureLiveTicketsResult { // // NOTE: This is a dcrd extension. func (c *Client) LiveTickets(ctx context.Context) ([]*chainhash.Hash, error) { - return c.LiveTicketsAsync(ctx).Receive() + return c.LiveTicketsAsync(ctx).Receive(ctx) } // FutureMissedTicketsResult is a future promise to deliver the result @@ -795,8 +795,8 @@ type FutureMissedTicketsResult chan *response // Receive waits for the response promised by the future and returns all // currently missed tickets from the missed ticket database. -func (r FutureMissedTicketsResult) Receive() ([]*chainhash.Hash, error) { - res, err := receiveFuture(r) +func (r FutureMissedTicketsResult) Receive(ctx context.Context) ([]*chainhash.Hash, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -833,7 +833,7 @@ func (c *Client) MissedTicketsAsync(ctx context.Context) FutureMissedTicketsResu // // NOTE: This is a dcrd extension. func (c *Client) MissedTickets(ctx context.Context) ([]*chainhash.Hash, error) { - return c.MissedTicketsAsync(ctx).Receive() + return c.MissedTicketsAsync(ctx).Receive(ctx) } // FutureSessionResult is a future promise to deliver the result of a @@ -842,8 +842,8 @@ type FutureSessionResult chan *response // Receive waits for the response promised by the future and returns the // session result. -func (r FutureSessionResult) Receive() (*chainjson.SessionResult, error) { - res, err := receiveFuture(r) +func (r FutureSessionResult) Receive(ctx context.Context) (*chainjson.SessionResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -881,7 +881,7 @@ func (c *Client) SessionAsync(ctx context.Context) FutureSessionResult { // // NOTE: This is a Decred extension. func (c *Client) Session(ctx context.Context) (*chainjson.SessionResult, error) { - return c.SessionAsync(ctx).Receive() + return c.SessionAsync(ctx).Receive(ctx) } // FutureTicketFeeInfoResult is a future promise to deliver the result of a @@ -890,8 +890,8 @@ type FutureTicketFeeInfoResult chan *response // Receive waits for the response promised by the future and returns the // ticketfeeinfo result. -func (r FutureTicketFeeInfoResult) Receive() (*chainjson.TicketFeeInfoResult, error) { - res, err := receiveFuture(r) +func (r FutureTicketFeeInfoResult) Receive(ctx context.Context) (*chainjson.TicketFeeInfoResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -938,7 +938,7 @@ func (c *Client) TicketFeeInfoAsync(ctx context.Context, blocks *uint32, windows // // NOTE: This is a Decred extension. func (c *Client) TicketFeeInfo(ctx context.Context, blocks *uint32, windows *uint32) (*chainjson.TicketFeeInfoResult, error) { - return c.TicketFeeInfoAsync(ctx, blocks, windows).Receive() + return c.TicketFeeInfoAsync(ctx, blocks, windows).Receive(ctx) } // FutureTicketVWAPResult is a future promise to deliver the result of a @@ -947,8 +947,8 @@ type FutureTicketVWAPResult chan *response // Receive waits for the response promised by the future and returns the // ticketvwap result. -func (r FutureTicketVWAPResult) Receive() (dcrutil.Amount, error) { - res, err := receiveFuture(r) +func (r FutureTicketVWAPResult) Receive(ctx context.Context) (dcrutil.Amount, error) { + res, err := receiveFuture(ctx, r) if err != nil { return 0, err } @@ -991,7 +991,7 @@ func (c *Client) TicketVWAPAsync(ctx context.Context, start *uint32, end *uint32 // // NOTE: This is a Decred extension. func (c *Client) TicketVWAP(ctx context.Context, start *uint32, end *uint32) (dcrutil.Amount, error) { - return c.TicketVWAPAsync(ctx, start, end).Receive() + return c.TicketVWAPAsync(ctx, start, end).Receive(ctx) } // FutureTxFeeInfoResult is a future promise to deliver the result of a @@ -1000,8 +1000,8 @@ type FutureTxFeeInfoResult chan *response // Receive waits for the response promised by the future and returns the // txfeeinfo result. -func (r FutureTxFeeInfoResult) Receive() (*chainjson.TxFeeInfoResult, error) { - res, err := receiveFuture(r) +func (r FutureTxFeeInfoResult) Receive(ctx context.Context) (*chainjson.TxFeeInfoResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -1039,7 +1039,7 @@ func (c *Client) TxFeeInfoAsync(ctx context.Context, blocks *uint32, start *uint // // NOTE: This is a Decred extension. func (c *Client) TxFeeInfo(ctx context.Context, blocks *uint32, start *uint32, end *uint32) (*chainjson.TxFeeInfoResult, error) { - return c.TxFeeInfoAsync(ctx, blocks, start, end).Receive() + return c.TxFeeInfoAsync(ctx, blocks, start, end).Receive(ctx) } // FutureVersionResult is a future promise to deliver the result of a version @@ -1048,8 +1048,8 @@ type FutureVersionResult chan *response // Receive waits for the response promised by the future and returns the version // result. -func (r FutureVersionResult) Receive() (map[string]chainjson.VersionResult, error) { - res, err := receiveFuture(r) +func (r FutureVersionResult) Receive(ctx context.Context) (map[string]chainjson.VersionResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -1075,5 +1075,5 @@ func (c *Client) VersionAsync(ctx context.Context) FutureVersionResult { // Version returns information about the server's JSON-RPC API versions. func (c *Client) Version(ctx context.Context) (map[string]chainjson.VersionResult, error) { - return c.VersionAsync(ctx).Receive() + return c.VersionAsync(ctx).Receive(ctx) } diff --git a/rpcclient/infrastructure.go b/rpcclient/infrastructure.go index 477068831b..91b5d90f3a 100644 --- a/rpcclient/infrastructure.go +++ b/rpcclient/infrastructure.go @@ -845,10 +845,16 @@ func newFutureError(err error) chan *response { // 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) { - // Wait for a response on the returned channel. - r := <-f +// until the result is available on the passed channel or the passed context +// is done. +func receiveFuture(ctx context.Context, f chan *response) ([]byte, error) { + // Wait for a response on the returned channel or context done. + r := new(response) + select { + case r = <-f: + case <-ctx.Done(): + r.err = ErrRequestCanceled + } return r.result, r.err } @@ -917,9 +923,7 @@ func (c *Client) sendRequest(ctx context.Context, jReq *jsonRequest) { // sendCmd sends the passed command to the associated server and returns a // response channel on which the reply will be delivered at some point in the // future. It handles both websocket and HTTP POST mode depending on the -// configuration of the client. If the passed context is done before receiving -// a response ErrRequestCanceled is sent over the response channel and the -// request is removed from the request map. +// configuration of the client. func (c *Client) sendCmd(ctx context.Context, cmd interface{}) chan *response { // Get the method associated with the command. method, err := dcrjson.CmdMethod(cmd) @@ -935,36 +939,13 @@ func (c *Client) sendCmd(ctx context.Context, cmd interface{}) chan *response { } responseChan := make(chan *response, 1) - relayChan := make(chan *response, 1) - // Pass results along for as long as ctx is not done. - go func() { - select { - case res := <-relayChan: - responseChan <- res - case <-ctx.Done(): - responseChan <- &response{err: ErrRequestCanceled} - // Remove the request from the resend queue. - var nextElem *list.Element - c.requestLock.Lock() - for e := c.requestList.Front(); e != nil; e = nextElem { - nextElem = e.Next() - jReq := e.Value.(*jsonRequest) - if jReq.id == id { - delete(c.requestMap, id) - c.requestList.Remove(e) - break - } - } - c.requestLock.Unlock() - } - }() // Generate the request and send it along with a channel to respond on. jReq := &jsonRequest{ id: id, method: method, cmd: cmd, marshalledJSON: marshalledJSON, - responseChan: relayChan, + responseChan: responseChan, } c.sendRequest(ctx, jReq) @@ -977,7 +958,7 @@ func (c *Client) sendCmd(ctx context.Context, cmd interface{}) chan *response { func (c *Client) sendCmdAndWait(ctx context.Context, 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(ctx, cmd)) + return receiveFuture(ctx, c.sendCmd(ctx, cmd)) } // Disconnected returns whether or not the server is disconnected. If a diff --git a/rpcclient/mining.go b/rpcclient/mining.go index 7dcf077a14..99cf1c7c65 100644 --- a/rpcclient/mining.go +++ b/rpcclient/mining.go @@ -22,8 +22,8 @@ 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) +func (r FutureGenerateResult) Receive(ctx context.Context) ([]*chainhash.Hash, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -60,7 +60,7 @@ func (c *Client) GenerateAsync(ctx context.Context, numBlocks uint32) FutureGene // Generate generates numBlocks blocks and returns their hashes. func (c *Client) Generate(ctx context.Context, numBlocks uint32) ([]*chainhash.Hash, error) { - return c.GenerateAsync(ctx, numBlocks).Receive() + return c.GenerateAsync(ctx, numBlocks).Receive(ctx) } // FutureGetGenerateResult is a future promise to deliver the result of a @@ -69,8 +69,8 @@ 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) +func (r FutureGetGenerateResult) Receive(ctx context.Context) (bool, error) { + res, err := receiveFuture(ctx, r) if err != nil { return false, err } @@ -97,7 +97,7 @@ func (c *Client) GetGenerateAsync(ctx context.Context) FutureGetGenerateResult { // GetGenerate returns true if the server is set to mine, otherwise false. func (c *Client) GetGenerate(ctx context.Context) (bool, error) { - return c.GetGenerateAsync(ctx).Receive() + return c.GetGenerateAsync(ctx).Receive(ctx) } // FutureSetGenerateResult is a future promise to deliver the result of a @@ -106,8 +106,8 @@ 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) +func (r FutureSetGenerateResult) Receive(ctx context.Context) error { + _, err := receiveFuture(ctx, r) return err } @@ -123,7 +123,7 @@ func (c *Client) SetGenerateAsync(ctx context.Context, enable bool, numCPUs int) // SetGenerate sets the server to generate coins (mine) or not. func (c *Client) SetGenerate(ctx context.Context, enable bool, numCPUs int) error { - return c.SetGenerateAsync(ctx, enable, numCPUs).Receive() + return c.SetGenerateAsync(ctx, enable, numCPUs).Receive(ctx) } // FutureGetHashesPerSecResult is a future promise to deliver the result of a @@ -133,8 +133,8 @@ type FutureGetHashesPerSecResult chan *response // Receive waits for the response promised by the future and returns a recent // 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) +func (r FutureGetHashesPerSecResult) Receive(ctx context.Context) (int64, error) { + res, err := receiveFuture(ctx, r) if err != nil { return -1, err } @@ -163,7 +163,7 @@ func (c *Client) GetHashesPerSecAsync(ctx context.Context) FutureGetHashesPerSec // while generating coins (mining). Zero is returned if the server is not // mining. func (c *Client) GetHashesPerSec(ctx context.Context) (int64, error) { - return c.GetHashesPerSecAsync(ctx).Receive() + return c.GetHashesPerSecAsync(ctx).Receive(ctx) } // FutureGetMiningInfoResult is a future promise to deliver the result of a @@ -172,8 +172,8 @@ type FutureGetMiningInfoResult chan *response // Receive waits for the response promised by the future and returns the mining // information. -func (r FutureGetMiningInfoResult) Receive() (*chainjson.GetMiningInfoResult, error) { - res, err := receiveFuture(r) +func (r FutureGetMiningInfoResult) Receive(ctx context.Context) (*chainjson.GetMiningInfoResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -200,7 +200,7 @@ func (c *Client) GetMiningInfoAsync(ctx context.Context) FutureGetMiningInfoResu // GetMiningInfo returns mining information. func (c *Client) GetMiningInfo(ctx context.Context) (*chainjson.GetMiningInfoResult, error) { - return c.GetMiningInfoAsync(ctx).Receive() + return c.GetMiningInfoAsync(ctx).Receive(ctx) } // FutureGetNetworkHashPS is a future promise to deliver the result of a @@ -210,8 +210,8 @@ type FutureGetNetworkHashPS chan *response // Receive waits for the response promised by the future and returns the // estimated network hashes per second for the block heights provided by the // parameters. -func (r FutureGetNetworkHashPS) Receive() (int64, error) { - res, err := receiveFuture(r) +func (r FutureGetNetworkHashPS) Receive(ctx context.Context) (int64, error) { + res, err := receiveFuture(ctx, r) if err != nil { return -1, err } @@ -242,7 +242,7 @@ func (c *Client) GetNetworkHashPSAsync(ctx context.Context) FutureGetNetworkHash // See GetNetworkHashPS2 to override the number of blocks to use and // GetNetworkHashPS3 to override the height at which to calculate the estimate. func (c *Client) GetNetworkHashPS(ctx context.Context) (int64, error) { - return c.GetNetworkHashPSAsync(ctx).Receive() + return c.GetNetworkHashPSAsync(ctx).Receive(ctx) } // GetNetworkHashPS2Async returns an instance of a type that can be used to get @@ -263,7 +263,7 @@ func (c *Client) GetNetworkHashPS2Async(ctx context.Context, blocks int) FutureG // See GetNetworkHashPS to use defaults and GetNetworkHashPS3 to override the // height at which to calculate the estimate. func (c *Client) GetNetworkHashPS2(ctx context.Context, blocks int) (int64, error) { - return c.GetNetworkHashPS2Async(ctx, blocks).Receive() + return c.GetNetworkHashPS2Async(ctx, blocks).Receive(ctx) } // GetNetworkHashPS3Async returns an instance of a type that can be used to get @@ -283,7 +283,7 @@ func (c *Client) GetNetworkHashPS3Async(ctx context.Context, blocks, height int) // // See GetNetworkHashPS and GetNetworkHashPS2 to use defaults. func (c *Client) GetNetworkHashPS3(ctx context.Context, blocks, height int) (int64, error) { - return c.GetNetworkHashPS3Async(ctx, blocks, height).Receive() + return c.GetNetworkHashPS3Async(ctx, blocks, height).Receive(ctx) } // FutureGetWork is a future promise to deliver the result of a @@ -292,8 +292,8 @@ 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() (*chainjson.GetWorkResult, error) { - res, err := receiveFuture(r) +func (r FutureGetWork) Receive(ctx context.Context) (*chainjson.GetWorkResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -322,7 +322,7 @@ func (c *Client) GetWorkAsync(ctx context.Context) FutureGetWork { // // See GetWorkSubmit to submit the found solution. func (c *Client) GetWork(ctx context.Context) (*chainjson.GetWorkResult, error) { - return c.GetWorkAsync(ctx).Receive() + return c.GetWorkAsync(ctx).Receive(ctx) } // FutureGetWorkSubmit is a future promise to deliver the result of a @@ -331,8 +331,8 @@ 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) +func (r FutureGetWorkSubmit) Receive(ctx context.Context) (bool, error) { + res, err := receiveFuture(ctx, r) if err != nil { return false, err } @@ -362,7 +362,7 @@ func (c *Client) GetWorkSubmitAsync(ctx context.Context, data string) FutureGetW // // See GetWork to request data to work on. func (c *Client) GetWorkSubmit(ctx context.Context, data string) (bool, error) { - return c.GetWorkSubmitAsync(ctx, data).Receive() + return c.GetWorkSubmitAsync(ctx, data).Receive(ctx) } // FutureSubmitBlockResult is a future promise to deliver the result of a @@ -371,8 +371,8 @@ 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) +func (r FutureSubmitBlockResult) Receive(ctx context.Context) error { + res, err := receiveFuture(ctx, r) if err != nil { return err } @@ -413,7 +413,7 @@ func (c *Client) SubmitBlockAsync(ctx context.Context, block *dcrutil.Block, opt // SubmitBlock attempts to submit a new block into the Decred network. func (c *Client) SubmitBlock(ctx context.Context, block *dcrutil.Block, options *chainjson.SubmitBlockOptions) error { - return c.SubmitBlockAsync(ctx, block, options).Receive() + return c.SubmitBlockAsync(ctx, block, options).Receive(ctx) } // FutureRegenTemplateResult is a future promise to deliver the result of a @@ -421,8 +421,8 @@ func (c *Client) SubmitBlock(ctx context.Context, block *dcrutil.Block, options type FutureRegenTemplateResult chan *response // Receive waits for the response and returns an error if any has occurred. -func (r FutureRegenTemplateResult) Receive() error { - _, err := receiveFuture(r) +func (r FutureRegenTemplateResult) Receive(ctx context.Context) error { + _, err := receiveFuture(ctx, r) return err } @@ -440,5 +440,5 @@ func (c *Client) RegenTemplateAsync(ctx context.Context) FutureRegenTemplateResu // that template generation is currently asynchronous, therefore no guarantees // are made for when or whether a new template will actually be available. func (c *Client) RegenTemplate(ctx context.Context) error { - return c.RegenTemplateAsync(ctx).Receive() + return c.RegenTemplateAsync(ctx).Receive(ctx) } diff --git a/rpcclient/net.go b/rpcclient/net.go index ed8e8c82f6..84d165beba 100644 --- a/rpcclient/net.go +++ b/rpcclient/net.go @@ -41,8 +41,8 @@ type FutureAddNodeResult chan *response // Receive waits for the response promised by the future and returns an error if // any occurred when performing the specified command. -func (r FutureAddNodeResult) Receive() error { - _, err := receiveFuture(r) +func (r FutureAddNodeResult) Receive(ctx context.Context) error { + _, err := receiveFuture(ctx, r) return err } @@ -62,7 +62,7 @@ func (c *Client) AddNodeAsync(ctx context.Context, host string, command AddNodeC // // It may not be used to remove non-persistent peers. func (c *Client) AddNode(ctx context.Context, host string, command AddNodeCommand) error { - return c.AddNodeAsync(ctx, host, command).Receive() + return c.AddNodeAsync(ctx, host, command).Receive(ctx) } // FutureGetAddedNodeInfoResult is a future promise to deliver the result of a @@ -71,8 +71,8 @@ type FutureGetAddedNodeInfoResult chan *response // Receive waits for the response promised by the future and returns information // about manually added (persistent) peers. -func (r FutureGetAddedNodeInfoResult) Receive() ([]chainjson.GetAddedNodeInfoResult, error) { - res, err := receiveFuture(r) +func (r FutureGetAddedNodeInfoResult) Receive(ctx context.Context) ([]chainjson.GetAddedNodeInfoResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -102,7 +102,7 @@ func (c *Client) GetAddedNodeInfoAsync(ctx context.Context, peer string) FutureG // See GetAddedNodeInfoNoDNS to retrieve only a list of the added (persistent) // peers. func (c *Client) GetAddedNodeInfo(ctx context.Context, peer string) ([]chainjson.GetAddedNodeInfoResult, error) { - return c.GetAddedNodeInfoAsync(ctx, peer).Receive() + return c.GetAddedNodeInfoAsync(ctx, peer).Receive(ctx) } // FutureGetAddedNodeInfoNoDNSResult is a future promise to deliver the result @@ -111,8 +111,8 @@ type FutureGetAddedNodeInfoNoDNSResult chan *response // Receive waits for the response promised by the future and returns a list of // manually added (persistent) peers. -func (r FutureGetAddedNodeInfoNoDNSResult) Receive() ([]string, error) { - res, err := receiveFuture(r) +func (r FutureGetAddedNodeInfoNoDNSResult) Receive(ctx context.Context) ([]string, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -143,7 +143,7 @@ func (c *Client) GetAddedNodeInfoNoDNSAsync(ctx context.Context, peer string) Fu // See GetAddedNodeInfo to obtain more information about each added (persistent) // peer. func (c *Client) GetAddedNodeInfoNoDNS(ctx context.Context, peer string) ([]string, error) { - return c.GetAddedNodeInfoNoDNSAsync(ctx, peer).Receive() + return c.GetAddedNodeInfoNoDNSAsync(ctx, peer).Receive(ctx) } // FutureGetConnectionCountResult is a future promise to deliver the result @@ -152,8 +152,8 @@ type FutureGetConnectionCountResult chan *response // Receive waits for the response promised by the future and returns the number // of active connections to other peers. -func (r FutureGetConnectionCountResult) Receive() (int64, error) { - res, err := receiveFuture(r) +func (r FutureGetConnectionCountResult) Receive(ctx context.Context) (int64, error) { + res, err := receiveFuture(ctx, r) if err != nil { return 0, err } @@ -180,7 +180,7 @@ func (c *Client) GetConnectionCountAsync(ctx context.Context) FutureGetConnectio // GetConnectionCount returns the number of active connections to other peers. func (c *Client) GetConnectionCount(ctx context.Context) (int64, error) { - return c.GetConnectionCountAsync(ctx).Receive() + return c.GetConnectionCountAsync(ctx).Receive(ctx) } // FuturePingResult is a future promise to deliver the result of a PingAsync RPC @@ -189,8 +189,8 @@ type FuturePingResult chan *response // Receive waits for the response promised by the future and returns the result // of queueing a ping to be sent to each connected peer. -func (r FuturePingResult) Receive() error { - _, err := receiveFuture(r) +func (r FuturePingResult) Receive(ctx context.Context) error { + _, err := receiveFuture(ctx, r) return err } @@ -209,7 +209,7 @@ func (c *Client) PingAsync(ctx context.Context) FuturePingResult { // Use the GetPeerInfo function and examine the PingTime and PingWait fields to // access the ping times. func (c *Client) Ping(ctx context.Context) error { - return c.PingAsync(ctx).Receive() + return c.PingAsync(ctx).Receive(ctx) } // FutureGetPeerInfoResult is a future promise to deliver the result of a @@ -218,8 +218,8 @@ type FutureGetPeerInfoResult chan *response // Receive waits for the response promised by the future and returns data about // each connected network peer. -func (r FutureGetPeerInfoResult) Receive() ([]chainjson.GetPeerInfoResult, error) { - res, err := receiveFuture(r) +func (r FutureGetPeerInfoResult) Receive(ctx context.Context) ([]chainjson.GetPeerInfoResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -246,7 +246,7 @@ func (c *Client) GetPeerInfoAsync(ctx context.Context) FutureGetPeerInfoResult { // GetPeerInfo returns data about each connected network peer. func (c *Client) GetPeerInfo(ctx context.Context) ([]chainjson.GetPeerInfoResult, error) { - return c.GetPeerInfoAsync(ctx).Receive() + return c.GetPeerInfoAsync(ctx).Receive(ctx) } // FutureGetNetTotalsResult is a future promise to deliver the result of a @@ -255,8 +255,8 @@ type FutureGetNetTotalsResult chan *response // Receive waits for the response promised by the future and returns network // traffic statistics. -func (r FutureGetNetTotalsResult) Receive() (*chainjson.GetNetTotalsResult, error) { - res, err := receiveFuture(r) +func (r FutureGetNetTotalsResult) Receive(ctx context.Context) (*chainjson.GetNetTotalsResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -283,5 +283,5 @@ func (c *Client) GetNetTotalsAsync(ctx context.Context) FutureGetNetTotalsResult // GetNetTotals returns network traffic statistics. func (c *Client) GetNetTotals(ctx context.Context) (*chainjson.GetNetTotalsResult, error) { - return c.GetNetTotalsAsync(ctx).Receive() + return c.GetNetTotalsAsync(ctx).Receive(ctx) } diff --git a/rpcclient/notify.go b/rpcclient/notify.go index eef92afaac..db733875c9 100644 --- a/rpcclient/notify.go +++ b/rpcclient/notify.go @@ -827,8 +827,8 @@ type FutureNotifyBlocksResult chan *response // Receive waits for the response promised by the future and returns an error // if the registration was not successful. -func (r FutureNotifyBlocksResult) Receive() error { - _, err := receiveFuture(r) +func (r FutureNotifyBlocksResult) Receive(ctx context.Context) error { + _, err := receiveFuture(ctx, r) return err } @@ -838,8 +838,8 @@ type FutureNotifyWorkResult chan *response // Receive waits for the response promised by the future and returns an error // if the registration was not successful. -func (r FutureNotifyWorkResult) Receive() error { - _, err := receiveFuture(r) +func (r FutureNotifyWorkResult) Receive(ctx context.Context) error { + _, err := receiveFuture(ctx, r) return err } @@ -900,7 +900,7 @@ func (c *Client) NotifyWorkAsync(ctx context.Context) FutureNotifyWorkResult { // // NOTE: This is a dcrd extension and requires a websocket connection. func (c *Client) NotifyBlocks(ctx context.Context) error { - return c.NotifyBlocksAsync(ctx).Receive() + return c.NotifyBlocksAsync(ctx).Receive(ctx) } // NotifyWork registers the client to receive notifications when a new block @@ -911,7 +911,7 @@ func (c *Client) NotifyBlocks(ctx context.Context) error { // // NOTE: This is a dcrd extension and requires a websocket connection. func (c *Client) NotifyWork(ctx context.Context) error { - return c.NotifyWorkAsync(ctx).Receive() + return c.NotifyWorkAsync(ctx).Receive(ctx) } // FutureNotifyWinningTicketsResult is a future promise to deliver the result of a @@ -920,8 +920,8 @@ type FutureNotifyWinningTicketsResult chan *response // Receive waits for the response promised by the future and returns an error // if the registration was not successful. -func (r FutureNotifyWinningTicketsResult) Receive() error { - _, err := receiveFuture(r) +func (r FutureNotifyWinningTicketsResult) Receive(ctx context.Context) error { + _, err := receiveFuture(ctx, r) return err } @@ -961,7 +961,7 @@ func (c *Client) NotifyWinningTicketsAsync(ctx context.Context) FutureNotifyWinn // // NOTE: This is a dcrd extension and requires a websocket connection. func (c *Client) NotifyWinningTickets(ctx context.Context) error { - return c.NotifyWinningTicketsAsync(ctx).Receive() + return c.NotifyWinningTicketsAsync(ctx).Receive(ctx) } // FutureNotifySpentAndMissedTicketsResult is a future promise to deliver the result of a @@ -970,8 +970,8 @@ type FutureNotifySpentAndMissedTicketsResult chan *response // Receive waits for the response promised by the future and returns an error // if the registration was not successful. -func (r FutureNotifySpentAndMissedTicketsResult) Receive() error { - _, err := receiveFuture(r) +func (r FutureNotifySpentAndMissedTicketsResult) Receive(ctx context.Context) error { + _, err := receiveFuture(ctx, r) return err } @@ -1011,7 +1011,7 @@ func (c *Client) NotifySpentAndMissedTicketsAsync(ctx context.Context) FutureNot // // NOTE: This is a dcrd extension and requires a websocket connection. func (c *Client) NotifySpentAndMissedTickets(ctx context.Context) error { - return c.NotifySpentAndMissedTicketsAsync(ctx).Receive() + return c.NotifySpentAndMissedTicketsAsync(ctx).Receive(ctx) } // FutureNotifyNewTicketsResult is a future promise to deliver the result of a @@ -1020,8 +1020,8 @@ type FutureNotifyNewTicketsResult chan *response // Receive waits for the response promised by the future and returns an error // if the registration was not successful. -func (r FutureNotifyNewTicketsResult) Receive() error { - _, err := receiveFuture(r) +func (r FutureNotifyNewTicketsResult) Receive(ctx context.Context) error { + _, err := receiveFuture(ctx, r) return err } @@ -1059,7 +1059,7 @@ func (c *Client) NotifyNewTicketsAsync(ctx context.Context) FutureNotifyNewTicke // // NOTE: This is a dcrd extension and requires a websocket connection. func (c *Client) NotifyNewTickets(ctx context.Context) error { - return c.NotifyNewTicketsAsync(ctx).Receive() + return c.NotifyNewTicketsAsync(ctx).Receive(ctx) } // FutureNotifyStakeDifficultyResult is a future promise to deliver the result of a @@ -1068,8 +1068,8 @@ type FutureNotifyStakeDifficultyResult chan *response // Receive waits for the response promised by the future and returns an error // if the registration was not successful. -func (r FutureNotifyStakeDifficultyResult) Receive() error { - _, err := receiveFuture(r) +func (r FutureNotifyStakeDifficultyResult) Receive(ctx context.Context) error { + _, err := receiveFuture(ctx, r) return err } @@ -1109,7 +1109,7 @@ func (c *Client) NotifyStakeDifficultyAsync(ctx context.Context) FutureNotifySta // // NOTE: This is a dcrd extension and requires a websocket connection. func (c *Client) NotifyStakeDifficulty(ctx context.Context) error { - return c.NotifyStakeDifficultyAsync(ctx).Receive() + return c.NotifyStakeDifficultyAsync(ctx).Receive(ctx) } // FutureNotifyNewTransactionsResult is a future promise to deliver the result @@ -1118,8 +1118,8 @@ type FutureNotifyNewTransactionsResult chan *response // Receive waits for the response promised by the future and returns an error // if the registration was not successful. -func (r FutureNotifyNewTransactionsResult) Receive() error { - _, err := receiveFuture(r) +func (r FutureNotifyNewTransactionsResult) Receive(ctx context.Context) error { + _, err := receiveFuture(ctx, r) return err } @@ -1158,7 +1158,7 @@ func (c *Client) NotifyNewTransactionsAsync(ctx context.Context, verbose bool) F // // NOTE: This is a dcrd extension and requires a websocket connection. func (c *Client) NotifyNewTransactions(ctx context.Context, verbose bool) error { - return c.NotifyNewTransactionsAsync(ctx, verbose).Receive() + return c.NotifyNewTransactionsAsync(ctx, verbose).Receive(ctx) } // FutureLoadTxFilterResult is a future promise to deliver the result @@ -1167,8 +1167,8 @@ type FutureLoadTxFilterResult chan *response // Receive waits for the response promised by the future and returns an error // if the registration was not successful. -func (r FutureLoadTxFilterResult) Receive() error { - _, err := receiveFuture(r) +func (r FutureLoadTxFilterResult) Receive(ctx context.Context) error { + _, err := receiveFuture(ctx, r) return err } @@ -1205,5 +1205,5 @@ func (c *Client) LoadTxFilterAsync(ctx context.Context, reload bool, addresses [ // // NOTE: This is a dcrd extension and requires a websocket connection. func (c *Client) LoadTxFilter(ctx context.Context, reload bool, addresses []dcrutil.Address, outPoints []wire.OutPoint) error { - return c.LoadTxFilterAsync(ctx, reload, addresses, outPoints).Receive() + return c.LoadTxFilterAsync(ctx, reload, addresses, outPoints).Receive(ctx) } diff --git a/rpcclient/rawrequest.go b/rpcclient/rawrequest.go index c05d4acfeb..028042c4cd 100644 --- a/rpcclient/rawrequest.go +++ b/rpcclient/rawrequest.go @@ -19,8 +19,8 @@ type FutureRawResult chan *response // Receive waits for the response promised by the future and returns the raw // response, or an error if the request was unsuccessful. -func (r FutureRawResult) Receive() (json.RawMessage, error) { - return receiveFuture(r) +func (r FutureRawResult) Receive(ctx context.Context) (json.RawMessage, error) { + return receiveFuture(ctx, r) } // RawRequestAsync returns an instance of a type that can be used to get the @@ -76,5 +76,5 @@ func (c *Client) RawRequestAsync(ctx context.Context, method string, params []js // unmarshaled requests to another JSON-RPC server if a request cannot be // handled directly. func (c *Client) RawRequest(ctx context.Context, method string, params []json.RawMessage) (json.RawMessage, error) { - return c.RawRequestAsync(ctx, method, params).Receive() + return c.RawRequestAsync(ctx, method, params).Receive(ctx) } diff --git a/rpcclient/rawtransactions.go b/rpcclient/rawtransactions.go index 5ebf17b3a5..7e45232139 100644 --- a/rpcclient/rawtransactions.go +++ b/rpcclient/rawtransactions.go @@ -24,8 +24,8 @@ type FutureGetRawTransactionResult chan *response // Receive waits for the response promised by the future and returns a // transaction given its hash. -func (r FutureGetRawTransactionResult) Receive() (*dcrutil.Tx, error) { - res, err := receiveFuture(r) +func (r FutureGetRawTransactionResult) Receive(ctx context.Context) (*dcrutil.Tx, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -71,7 +71,7 @@ func (c *Client) GetRawTransactionAsync(ctx context.Context, txHash *chainhash.H // See GetRawTransactionVerbose to obtain additional information about the // transaction. func (c *Client) GetRawTransaction(ctx context.Context, txHash *chainhash.Hash) (*dcrutil.Tx, error) { - return c.GetRawTransactionAsync(ctx, txHash).Receive() + return c.GetRawTransactionAsync(ctx, txHash).Receive(ctx) } // FutureGetRawTransactionVerboseResult is a future promise to deliver the @@ -81,8 +81,8 @@ type FutureGetRawTransactionVerboseResult chan *response // Receive waits for the response promised by the future and returns information // about a transaction given its hash. -func (r FutureGetRawTransactionVerboseResult) Receive() (*chainjson.TxRawResult, error) { - res, err := receiveFuture(r) +func (r FutureGetRawTransactionVerboseResult) Receive(ctx context.Context) (*chainjson.TxRawResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -117,7 +117,7 @@ func (c *Client) GetRawTransactionVerboseAsync(ctx context.Context, txHash *chai // // See GetRawTransaction to obtain only the transaction already deserialized. func (c *Client) GetRawTransactionVerbose(ctx context.Context, txHash *chainhash.Hash) (*chainjson.TxRawResult, error) { - return c.GetRawTransactionVerboseAsync(ctx, txHash).Receive() + return c.GetRawTransactionVerboseAsync(ctx, txHash).Receive(ctx) } // FutureDecodeRawTransactionResult is a future promise to deliver the result @@ -126,8 +126,8 @@ type FutureDecodeRawTransactionResult chan *response // Receive waits for the response promised by the future and returns information // about a transaction given its serialized bytes. -func (r FutureDecodeRawTransactionResult) Receive() (*chainjson.TxRawResult, error) { - res, err := receiveFuture(r) +func (r FutureDecodeRawTransactionResult) Receive(ctx context.Context) (*chainjson.TxRawResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -156,7 +156,7 @@ func (c *Client) DecodeRawTransactionAsync(ctx context.Context, serializedTx []b // DecodeRawTransaction returns information about a transaction given its // serialized bytes. func (c *Client) DecodeRawTransaction(ctx context.Context, serializedTx []byte) (*chainjson.TxRawResult, error) { - return c.DecodeRawTransactionAsync(ctx, serializedTx).Receive() + return c.DecodeRawTransactionAsync(ctx, serializedTx).Receive(ctx) } // FutureCreateRawTransactionResult is a future promise to deliver the result @@ -166,8 +166,8 @@ type FutureCreateRawTransactionResult chan *response // Receive waits for the response promised by the future and returns a new // transaction spending the provided inputs and sending to the provided // addresses. -func (r FutureCreateRawTransactionResult) Receive() (*wire.MsgTx, error) { - res, err := receiveFuture(r) +func (r FutureCreateRawTransactionResult) Receive(ctx context.Context) (*wire.MsgTx, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -214,7 +214,7 @@ func (c *Client) CreateRawTransactionAsync(ctx context.Context, inputs []chainjs func (c *Client) CreateRawTransaction(ctx context.Context, inputs []chainjson.TransactionInput, amounts map[dcrutil.Address]dcrutil.Amount, lockTime *int64, expiry *int64) (*wire.MsgTx, error) { - return c.CreateRawTransactionAsync(ctx, inputs, amounts, lockTime, expiry).Receive() + return c.CreateRawTransactionAsync(ctx, inputs, amounts, lockTime, expiry).Receive(ctx) } // FutureCreateRawSStxResult is a future promise to deliver the result @@ -224,8 +224,8 @@ type FutureCreateRawSStxResult chan *response // Receive waits for the response promised by the future and returns a new // transaction spending the provided inputs and sending to the provided // addresses. -func (r FutureCreateRawSStxResult) Receive() (*wire.MsgTx, error) { - res, err := receiveFuture(r) +func (r FutureCreateRawSStxResult) Receive(ctx context.Context) (*wire.MsgTx, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -292,7 +292,7 @@ func (c *Client) CreateRawSStx(ctx context.Context, inputs []chainjson.SStxInput amount map[dcrutil.Address]dcrutil.Amount, couts []SStxCommitOut) (*wire.MsgTx, error) { - return c.CreateRawSStxAsync(ctx, inputs, amount, couts).Receive() + return c.CreateRawSStxAsync(ctx, inputs, amount, couts).Receive(ctx) } // FutureCreateRawSSRtxResult is a future promise to deliver the result @@ -302,8 +302,8 @@ type FutureCreateRawSSRtxResult chan *response // Receive waits for the response promised by the future and returns a new // transaction spending the provided inputs and sending to the provided // addresses. -func (r FutureCreateRawSSRtxResult) Receive() (*wire.MsgTx, error) { - res, err := receiveFuture(r) +func (r FutureCreateRawSSRtxResult) Receive(ctx context.Context) (*wire.MsgTx, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -342,7 +342,7 @@ func (c *Client) CreateRawSSRtxAsync(ctx context.Context, inputs []chainjson.Tra // CreateRawSSRtx returns a new SSR transaction (revoking an sstx). func (c *Client) CreateRawSSRtx(ctx context.Context, inputs []chainjson.TransactionInput, fee dcrutil.Amount) (*wire.MsgTx, error) { - return c.CreateRawSSRtxAsync(ctx, inputs, fee).Receive() + return c.CreateRawSSRtxAsync(ctx, inputs, fee).Receive(ctx) } // FutureSendRawTransactionResult is a future promise to deliver the result @@ -352,8 +352,8 @@ type FutureSendRawTransactionResult chan *response // Receive waits for the response promised by the future and returns the result // of submitting the encoded transaction to the server which then relays it to // the network. -func (r FutureSendRawTransactionResult) Receive() (*chainhash.Hash, error) { - res, err := receiveFuture(r) +func (r FutureSendRawTransactionResult) Receive(ctx context.Context) (*chainhash.Hash, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -391,7 +391,7 @@ func (c *Client) SendRawTransactionAsync(ctx context.Context, tx *wire.MsgTx, al // SendRawTransaction submits the encoded transaction to the server which will // then relay it to the network. func (c *Client) SendRawTransaction(ctx context.Context, tx *wire.MsgTx, allowHighFees bool) (*chainhash.Hash, error) { - return c.SendRawTransactionAsync(ctx, tx, allowHighFees).Receive() + return c.SendRawTransactionAsync(ctx, tx, allowHighFees).Receive(ctx) } // FutureSearchRawTransactionsResult is a future promise to deliver the result @@ -400,8 +400,8 @@ type FutureSearchRawTransactionsResult chan *response // Receive waits for the response promised by the future and returns the // found raw transactions. -func (r FutureSearchRawTransactionsResult) Receive() ([]*wire.MsgTx, error) { - res, err := receiveFuture(r) +func (r FutureSearchRawTransactionsResult) Receive(ctx context.Context) ([]*wire.MsgTx, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -463,7 +463,7 @@ func (c *Client) SearchRawTransactions(ctx context.Context, reverse bool, filterAddrs []string) ([]*wire.MsgTx, error) { return c.SearchRawTransactionsAsync(ctx, address, skip, count, reverse, - filterAddrs).Receive() + filterAddrs).Receive(ctx) } // FutureSearchRawTransactionsVerboseResult is a future promise to deliver the @@ -473,8 +473,8 @@ type FutureSearchRawTransactionsVerboseResult chan *response // Receive waits for the response promised by the future and returns the // found raw transactions. -func (r FutureSearchRawTransactionsVerboseResult) Receive() ([]*chainjson.SearchRawTransactionsResult, error) { - res, err := receiveFuture(r) +func (r FutureSearchRawTransactionsVerboseResult) Receive(ctx context.Context) ([]*chainjson.SearchRawTransactionsResult, error) { + res, err := receiveFuture(ctx, r) if err != nil { return nil, err } @@ -521,5 +521,5 @@ func (c *Client) SearchRawTransactionsVerbose(ctx context.Context, filterAddrs []string) ([]*chainjson.SearchRawTransactionsResult, error) { return c.SearchRawTransactionsVerboseAsync(ctx, address, skip, count, - includePrevOut, reverse, &filterAddrs).Receive() + includePrevOut, reverse, &filterAddrs).Receive(ctx) }