From 34db20393074ee3d7b8f7a8900f577574e2fe53d Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Sun, 23 Aug 2015 13:30:13 -0500 Subject: [PATCH] Update SearchRawTransaction calls for latest API. This commit modifies the SearchRawTransactions and SearchRawTransactionsVerbose functions to work properly with the latest searchrawtransactions API in btcd. In particular, this involves changing the return value from []*btcjson.TxRawResult to []*btcjson.SearchRawTransactionResult and adding the additional optional parameter which specifies whether or not to include information about the previous outputs. --- rawtransactions.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/rawtransactions.go b/rawtransactions.go index ba43efde..50b86e34 100644 --- a/rawtransactions.go +++ b/rawtransactions.go @@ -552,7 +552,8 @@ func (r FutureSearchRawTransactionsResult) Receive() ([]*wire.MsgTx, error) { func (c *Client) SearchRawTransactionsAsync(address btcutil.Address, skip, count int) FutureSearchRawTransactionsResult { addr := address.EncodeAddress() verbose := btcjson.Int(0) - cmd := btcjson.NewSearchRawTransactionsCmd(addr, verbose, &skip, &count) + cmd := btcjson.NewSearchRawTransactionsCmd(addr, verbose, &skip, &count, + nil) return c.sendCmd(cmd) } @@ -574,14 +575,14 @@ type FutureSearchRawTransactionsVerboseResult chan *response // Receive waits for the response promised by the future and returns the // found raw transactions. -func (r FutureSearchRawTransactionsVerboseResult) Receive() ([]*btcjson.TxRawResult, error) { +func (r FutureSearchRawTransactionsVerboseResult) Receive() ([]*btcjson.SearchRawTransactionsResult, error) { res, err := receiveFuture(r) if err != nil { return nil, err } // Unmarshal as an array of raw transaction results. - var result []*btcjson.TxRawResult + var result []*btcjson.SearchRawTransactionsResult err = json.Unmarshal(res, &result) if err != nil { return nil, err @@ -595,10 +596,17 @@ func (r FutureSearchRawTransactionsVerboseResult) Receive() ([]*btcjson.TxRawRes // function on the returned instance. // // See SearchRawTransactionsVerbose for the blocking version and more details. -func (c *Client) SearchRawTransactionsVerboseAsync(address btcutil.Address, skip, count int) FutureSearchRawTransactionsVerboseResult { +func (c *Client) SearchRawTransactionsVerboseAsync(address btcutil.Address, skip, + count int, includePrevOut bool) FutureSearchRawTransactionsVerboseResult { + addr := address.EncodeAddress() verbose := btcjson.Int(1) - cmd := btcjson.NewSearchRawTransactionsCmd(addr, verbose, &skip, &count) + var prevOut *int + if includePrevOut { + prevOut = btcjson.Int(1) + } + cmd := btcjson.NewSearchRawTransactionsCmd(addr, verbose, &skip, &count, + prevOut) return c.sendCmd(cmd) } @@ -609,6 +617,9 @@ func (c *Client) SearchRawTransactionsVerboseAsync(address btcutil.Address, skip // specifically been enabled. // // See SearchRawTransactions to retrieve a list of raw transactions instead. -func (c *Client) SearchRawTransactionsVerbose(address btcutil.Address, skip, count int) ([]*btcjson.TxRawResult, error) { - return c.SearchRawTransactionsVerboseAsync(address, skip, count).Receive() +func (c *Client) SearchRawTransactionsVerbose(address btcutil.Address, skip, + count int, includePrevOut bool) ([]*btcjson.SearchRawTransactionsResult, error) { + + return c.SearchRawTransactionsVerboseAsync(address, skip, count, + includePrevOut).Receive() }