From c39e35318d5dc8d7e5e4171a34a17bc03dce06b4 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Mon, 8 Aug 2016 14:16:04 -0500 Subject: [PATCH] Update for recent chainhash-related API changes. (#81) This updates all code to make use of the new chainhash package since the old wire.ShaHash type and related functions have been removed in favor of the abstracted package. Also, while here, rename all variables that included sha in their name to include hash instead. --- chain.go | 35 ++++++++------- examples/btcdwebsockets/main.go | 6 +-- extensions.go | 7 +-- mining.go | 15 ++++--- notify.go | 79 +++++++++++++++++---------------- rawtransactions.go | 17 +++---- wallet.go | 45 ++++++++++--------- 7 files changed, 105 insertions(+), 99 deletions(-) diff --git a/chain.go b/chain.go index 184b71cc..9d6144e3 100644 --- a/chain.go +++ b/chain.go @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2015 The btcsuite developers +// Copyright (c) 2014-2016 The btcsuite developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -10,6 +10,7 @@ import ( "encoding/json" "github.com/btcsuite/btcd/btcjson" + "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" ) @@ -20,7 +21,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() (*wire.ShaHash, error) { +func (r FutureGetBestBlockHashResult) Receive() (*chainhash.Hash, error) { res, err := receiveFuture(r) if err != nil { return nil, err @@ -32,7 +33,7 @@ func (r FutureGetBestBlockHashResult) Receive() (*wire.ShaHash, error) { if err != nil { return nil, err } - return wire.NewShaHashFromStr(txHashStr) + return chainhash.NewHashFromStr(txHashStr) } // GetBestBlockHashAsync returns an instance of a type that can be used to get @@ -47,7 +48,7 @@ func (c *Client) GetBestBlockHashAsync() FutureGetBestBlockHashResult { // GetBestBlockHash returns the hash of the best block in the longest block // chain. -func (c *Client) GetBestBlockHash() (*wire.ShaHash, error) { +func (c *Client) GetBestBlockHash() (*chainhash.Hash, error) { return c.GetBestBlockHashAsync().Receive() } @@ -90,7 +91,7 @@ func (r FutureGetBlockResult) Receive() (*btcutil.Block, error) { // returned instance. // // See GetBlock for the blocking version and more details. -func (c *Client) GetBlockAsync(blockHash *wire.ShaHash) FutureGetBlockResult { +func (c *Client) GetBlockAsync(blockHash *chainhash.Hash) FutureGetBlockResult { hash := "" if blockHash != nil { hash = blockHash.String() @@ -104,7 +105,7 @@ func (c *Client) GetBlockAsync(blockHash *wire.ShaHash) FutureGetBlockResult { // // See GetBlockVerbose to retrieve a data structure with information about the // block instead. -func (c *Client) GetBlock(blockHash *wire.ShaHash) (*btcutil.Block, error) { +func (c *Client) GetBlock(blockHash *chainhash.Hash) (*btcutil.Block, error) { return c.GetBlockAsync(blockHash).Receive() } @@ -134,7 +135,7 @@ func (r FutureGetBlockVerboseResult) Receive() (*btcjson.GetBlockVerboseResult, // the returned instance. // // See GetBlockVerbose for the blocking version and more details. -func (c *Client) GetBlockVerboseAsync(blockHash *wire.ShaHash, verboseTx bool) FutureGetBlockVerboseResult { +func (c *Client) GetBlockVerboseAsync(blockHash *chainhash.Hash, verboseTx bool) FutureGetBlockVerboseResult { hash := "" if blockHash != nil { hash = blockHash.String() @@ -148,7 +149,7 @@ func (c *Client) GetBlockVerboseAsync(blockHash *wire.ShaHash, verboseTx bool) F // about a block given its hash. // // See GetBlock to retrieve a raw block instead. -func (c *Client) GetBlockVerbose(blockHash *wire.ShaHash, verboseTx bool) (*btcjson.GetBlockVerboseResult, error) { +func (c *Client) GetBlockVerbose(blockHash *chainhash.Hash, verboseTx bool) (*btcjson.GetBlockVerboseResult, error) { return c.GetBlockVerboseAsync(blockHash, verboseTx).Receive() } @@ -231,7 +232,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() (*wire.ShaHash, error) { +func (r FutureGetBlockHashResult) Receive() (*chainhash.Hash, error) { res, err := receiveFuture(r) if err != nil { return nil, err @@ -243,7 +244,7 @@ func (r FutureGetBlockHashResult) Receive() (*wire.ShaHash, error) { if err != nil { return nil, err } - return wire.NewShaHashFromStr(txHashStr) + return chainhash.NewHashFromStr(txHashStr) } // GetBlockHashAsync returns an instance of a type that can be used to get the @@ -258,7 +259,7 @@ func (c *Client) GetBlockHashAsync(blockHeight int64) FutureGetBlockHashResult { // GetBlockHash returns the hash of the block in the best block chain at the // given height. -func (c *Client) GetBlockHash(blockHeight int64) (*wire.ShaHash, error) { +func (c *Client) GetBlockHash(blockHeight int64) (*chainhash.Hash, error) { return c.GetBlockHashAsync(blockHeight).Receive() } @@ -268,7 +269,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() ([]*wire.ShaHash, error) { +func (r FutureGetRawMempoolResult) Receive() ([]*chainhash.Hash, error) { res, err := receiveFuture(r) if err != nil { return nil, err @@ -282,9 +283,9 @@ func (r FutureGetRawMempoolResult) Receive() ([]*wire.ShaHash, error) { } // Create a slice of ShaHash arrays from the string slice. - txHashes := make([]*wire.ShaHash, 0, len(txHashStrs)) + txHashes := make([]*chainhash.Hash, 0, len(txHashStrs)) for _, hashStr := range txHashStrs { - txHash, err := wire.NewShaHashFromStr(hashStr) + txHash, err := chainhash.NewHashFromStr(hashStr) if err != nil { return nil, err } @@ -308,7 +309,7 @@ func (c *Client) GetRawMempoolAsync() FutureGetRawMempoolResult { // // See GetRawMempoolVerbose to retrieve data structures with information about // the transactions instead. -func (c *Client) GetRawMempool() ([]*wire.ShaHash, error) { +func (c *Client) GetRawMempool() ([]*chainhash.Hash, error) { return c.GetRawMempoolAsync().Receive() } @@ -476,7 +477,7 @@ func (r FutureGetTxOutResult) Receive() (*btcjson.GetTxOutResult, error) { // the returned instance. // // See GetTxOut for the blocking version and more details. -func (c *Client) GetTxOutAsync(txHash *wire.ShaHash, index uint32, mempool bool) FutureGetTxOutResult { +func (c *Client) GetTxOutAsync(txHash *chainhash.Hash, index uint32, mempool bool) FutureGetTxOutResult { hash := "" if txHash != nil { hash = txHash.String() @@ -488,6 +489,6 @@ func (c *Client) GetTxOutAsync(txHash *wire.ShaHash, index uint32, mempool bool) // GetTxOut returns the transaction output info if it's unspent and // nil, otherwise. -func (c *Client) GetTxOut(txHash *wire.ShaHash, index uint32, mempool bool) (*btcjson.GetTxOutResult, error) { +func (c *Client) GetTxOut(txHash *chainhash.Hash, index uint32, mempool bool) (*btcjson.GetTxOutResult, error) { return c.GetTxOutAsync(txHash, index, mempool).Receive() } diff --git a/examples/btcdwebsockets/main.go b/examples/btcdwebsockets/main.go index 7e4e765f..93809953 100644 --- a/examples/btcdwebsockets/main.go +++ b/examples/btcdwebsockets/main.go @@ -10,7 +10,7 @@ import ( "path/filepath" "time" - "github.com/btcsuite/btcd/wire" + "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcrpcclient" "github.com/btcsuite/btcutil" ) @@ -21,10 +21,10 @@ func main() { // for notifications. See the documentation of the btcrpcclient // NotificationHandlers type for more details about each handler. ntfnHandlers := btcrpcclient.NotificationHandlers{ - OnBlockConnected: func(hash *wire.ShaHash, height int32, time time.Time) { + OnBlockConnected: func(hash *chainhash.Hash, height int32, time time.Time) { log.Printf("Block connected: %v (%d) %v", hash, height, time) }, - OnBlockDisconnected: func(hash *wire.ShaHash, height int32, time time.Time) { + OnBlockDisconnected: func(hash *chainhash.Hash, height int32, time time.Time) { log.Printf("Block disconnected: %v (%d) %v", hash, height, time) }, } diff --git a/extensions.go b/extensions.go index d13a136a..05e8e70a 100644 --- a/extensions.go +++ b/extensions.go @@ -10,6 +10,7 @@ import ( "fmt" "github.com/btcsuite/btcd/btcjson" + "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" ) @@ -148,7 +149,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() (*wire.ShaHash, int32, error) { +func (r FutureGetBestBlockResult) Receive() (*chainhash.Hash, int32, error) { res, err := receiveFuture(r) if err != nil { return nil, 0, err @@ -162,7 +163,7 @@ func (r FutureGetBestBlockResult) Receive() (*wire.ShaHash, int32, error) { } // Convert to hash from string. - hash, err := wire.NewShaHashFromStr(bestBlock.Hash) + hash, err := chainhash.NewHashFromStr(bestBlock.Hash) if err != nil { return nil, 0, err } @@ -186,7 +187,7 @@ func (c *Client) GetBestBlockAsync() FutureGetBestBlockResult { // chain. // // NOTE: This is a btcd extension. -func (c *Client) GetBestBlock() (*wire.ShaHash, int32, error) { +func (c *Client) GetBestBlock() (*chainhash.Hash, int32, error) { return c.GetBestBlockAsync().Receive() } diff --git a/mining.go b/mining.go index 0e9f415d..4ac94f14 100644 --- a/mining.go +++ b/mining.go @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2015 The btcsuite developers +// Copyright (c) 2014-2016 The btcsuite developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -10,7 +10,7 @@ import ( "errors" "github.com/btcsuite/btcd/btcjson" - "github.com/btcsuite/btcd/wire" + "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcutil" ) @@ -20,7 +20,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() ([]*wire.ShaHash, error) { +func (r FutureGenerateResult) Receive() ([]*chainhash.Hash, error) { res, err := receiveFuture(r) if err != nil { return nil, err @@ -33,10 +33,11 @@ func (r FutureGenerateResult) Receive() ([]*wire.ShaHash, error) { return nil, err } - // Convert each block hash to a wire.ShaHash and store a pointer to each. - convertedResult := make([]*wire.ShaHash, len(result)) + // Convert each block hash to a chainhash.Hash and store a pointer to + // each. + convertedResult := make([]*chainhash.Hash, len(result)) for i, hashString := range result { - convertedResult[i], err = wire.NewShaHashFromStr(hashString) + convertedResult[i], err = chainhash.NewHashFromStr(hashString) if err != nil { return nil, err } @@ -56,7 +57,7 @@ func (c *Client) GenerateAsync(numBlocks uint32) FutureGenerateResult { } // Generate generates numBlocks blocks and returns their hashes. -func (c *Client) Generate(numBlocks uint32) ([]*wire.ShaHash, error) { +func (c *Client) Generate(numBlocks uint32) ([]*chainhash.Hash, error) { return c.GenerateAsync(numBlocks).Receive() } diff --git a/notify.go b/notify.go index 488b36f4..908ec9d1 100644 --- a/notify.go +++ b/notify.go @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2015 The btcsuite developers +// Copyright (c) 2014-2016 The btcsuite developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -14,6 +14,7 @@ import ( "time" "github.com/btcsuite/btcd/btcjson" + "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" ) @@ -96,13 +97,13 @@ type NotificationHandlers struct { // (best) chain. It will only be invoked if a preceding call to // NotifyBlocks has been made to register for the notification and the // function is non-nil. - OnBlockConnected func(hash *wire.ShaHash, height int32, t time.Time) + OnBlockConnected func(hash *chainhash.Hash, height int32, t time.Time) // OnBlockDisconnected is invoked when a block is disconnected from the // longest (best) chain. It will only be invoked if a preceding call to // NotifyBlocks has been made to register for the notification and the // function is non-nil. - OnBlockDisconnected func(hash *wire.ShaHash, height int32, t time.Time) + OnBlockDisconnected func(hash *chainhash.Hash, height int32, t time.Time) // OnRecvTx is invoked when a transaction that receives funds to a // registered address is received into the memory pool and also @@ -128,18 +129,18 @@ type NotificationHandlers struct { // signaled on this notification, rather than relying on the return // result of a rescan request, due to how btcd may send various rescan // notifications after the rescan request has already returned. - OnRescanFinished func(hash *wire.ShaHash, height int32, blkTime time.Time) + OnRescanFinished func(hash *chainhash.Hash, height int32, blkTime time.Time) // OnRescanProgress is invoked periodically when a rescan is underway. // It will only be invoked if a preceding call to Rescan or // RescanEndHeight has been made and the function is non-nil. - OnRescanProgress func(hash *wire.ShaHash, height int32, blkTime time.Time) + OnRescanProgress func(hash *chainhash.Hash, height int32, blkTime time.Time) // OnTxAccepted is invoked when a transaction is accepted into the // memory pool. It will only be invoked if a preceding call to // NotifyNewTransactions with the verbose flag set to false has been // made to register for the notification and the function is non-nil. - OnTxAccepted func(hash *wire.ShaHash, amount btcutil.Amount) + OnTxAccepted func(hash *chainhash.Hash, amount btcutil.Amount) // OnTxAccepted is invoked when a transaction is accepted into the // memory pool. It will only be invoked if a preceding call to @@ -194,14 +195,14 @@ func (c *Client) handleNotification(ntfn *rawNotification) { return } - blockSha, blockHeight, blockTime, err := parseChainNtfnParams(ntfn.Params) + blockHash, blockHeight, blockTime, err := parseChainNtfnParams(ntfn.Params) if err != nil { log.Warnf("Received invalid block connected "+ "notification: %v", err) return } - c.ntfnHandlers.OnBlockConnected(blockSha, blockHeight, blockTime) + c.ntfnHandlers.OnBlockConnected(blockHash, blockHeight, blockTime) // OnBlockDisconnected case btcjson.BlockDisconnectedNtfnMethod: @@ -211,14 +212,14 @@ func (c *Client) handleNotification(ntfn *rawNotification) { return } - blockSha, blockHeight, blockTime, err := parseChainNtfnParams(ntfn.Params) + blockHash, blockHeight, blockTime, err := parseChainNtfnParams(ntfn.Params) if err != nil { log.Warnf("Received invalid block connected "+ "notification: %v", err) return } - c.ntfnHandlers.OnBlockDisconnected(blockSha, blockHeight, blockTime) + c.ntfnHandlers.OnBlockDisconnected(blockHash, blockHeight, blockTime) // OnRecvTx case btcjson.RecvTxNtfnMethod: @@ -398,7 +399,7 @@ func (e wrongNumParams) Error() string { // parseChainNtfnParams parses out the block hash and height from the parameters // of blockconnected and blockdisconnected notifications. -func parseChainNtfnParams(params []json.RawMessage) (*wire.ShaHash, +func parseChainNtfnParams(params []json.RawMessage) (*chainhash.Hash, int32, time.Time, error) { if len(params) != 3 { @@ -406,8 +407,8 @@ func parseChainNtfnParams(params []json.RawMessage) (*wire.ShaHash, } // Unmarshal first parameter as a string. - var blockShaStr string - err := json.Unmarshal(params[0], &blockShaStr) + var blockHashStr string + err := json.Unmarshal(params[0], &blockHashStr) if err != nil { return nil, 0, time.Time{}, err } @@ -426,8 +427,8 @@ func parseChainNtfnParams(params []json.RawMessage) (*wire.ShaHash, return nil, 0, time.Time{}, err } - // Create ShaHash from block sha string. - blockSha, err := wire.NewShaHashFromStr(blockShaStr) + // Create hash from block hash string. + blockHash, err := chainhash.NewHashFromStr(blockHashStr) if err != nil { return nil, 0, time.Time{}, err } @@ -435,7 +436,7 @@ func parseChainNtfnParams(params []json.RawMessage) (*wire.ShaHash, // Create time.Time from unix time. blockTime := time.Unix(blockTimeUnix, 0) - return blockSha, blockHeight, blockTime, nil + return blockHash, blockHeight, blockTime, nil } // parseChainTxNtfnParams parses out the transaction and optional details about @@ -477,14 +478,14 @@ func parseChainTxNtfnParams(params []json.RawMessage) (*btcutil.Tx, } // TODO: Change recvtx and redeemingtx callback signatures to use - // nicer types for details about the block (block sha as a - // wire.ShaHash, block time as a time.Time, etc.). + // nicer types for details about the block (block hash as a + // chainhash.Hash, block time as a time.Time, etc.). return btcutil.NewTx(&msgTx), block, nil } // parseRescanProgressParams parses out the height of the last rescanned block // from the parameters of rescanfinished and rescanprogress notifications. -func parseRescanProgressParams(params []json.RawMessage) (*wire.ShaHash, int32, time.Time, error) { +func parseRescanProgressParams(params []json.RawMessage) (*chainhash.Hash, int32, time.Time, error) { if len(params) != 3 { return nil, 0, time.Time{}, wrongNumParams(len(params)) } @@ -511,7 +512,7 @@ func parseRescanProgressParams(params []json.RawMessage) (*wire.ShaHash, int32, } // Decode string encoding of block hash. - hash, err := wire.NewShaHashFromStr(hashStr) + hash, err := chainhash.NewHashFromStr(hashStr) if err != nil { return nil, 0, time.Time{}, err } @@ -521,7 +522,7 @@ func parseRescanProgressParams(params []json.RawMessage) (*wire.ShaHash, int32, // parseTxAcceptedNtfnParams parses out the transaction hash and total amount // from the parameters of a txaccepted notification. -func parseTxAcceptedNtfnParams(params []json.RawMessage) (*wire.ShaHash, +func parseTxAcceptedNtfnParams(params []json.RawMessage) (*chainhash.Hash, btcutil.Amount, error) { if len(params) != 2 { @@ -529,8 +530,8 @@ func parseTxAcceptedNtfnParams(params []json.RawMessage) (*wire.ShaHash, } // Unmarshal first parameter as a string. - var txShaStr string - err := json.Unmarshal(params[0], &txShaStr) + var txHashStr string + err := json.Unmarshal(params[0], &txHashStr) if err != nil { return nil, 0, err } @@ -549,12 +550,12 @@ func parseTxAcceptedNtfnParams(params []json.RawMessage) (*wire.ShaHash, } // Decode string encoding of transaction sha. - txSha, err := wire.NewShaHashFromStr(txShaStr) + txHash, err := chainhash.NewHashFromStr(txHashStr) if err != nil { return nil, 0, err } - return txSha, btcutil.Amount(amt), nil + return txHash, btcutil.Amount(amt), nil } // parseTxAcceptedVerboseNtfnParams parses out details about a raw transaction @@ -959,7 +960,7 @@ func (r FutureRescanResult) Receive() error { // reconnect. // // NOTE: This is a btcd extension and requires a websocket connection. -func (c *Client) RescanAsync(startBlock *wire.ShaHash, +func (c *Client) RescanAsync(startBlock *chainhash.Hash, addresses []btcutil.Address, outpoints []*wire.OutPoint) FutureRescanResult { @@ -975,9 +976,9 @@ func (c *Client) RescanAsync(startBlock *wire.ShaHash, } // Convert block hashes to strings. - var startBlockShaStr string + var startBlockHashStr string if startBlock != nil { - startBlockShaStr = startBlock.String() + startBlockHashStr = startBlock.String() } // Convert addresses to strings. @@ -992,7 +993,7 @@ func (c *Client) RescanAsync(startBlock *wire.ShaHash, ops = append(ops, newOutPointFromWire(op)) } - cmd := btcjson.NewRescanCmd(startBlockShaStr, addrs, ops, nil) + cmd := btcjson.NewRescanCmd(startBlockHashStr, addrs, ops, nil) return c.sendCmd(cmd) } @@ -1022,7 +1023,7 @@ func (c *Client) RescanAsync(startBlock *wire.ShaHash, // reconnect. // // NOTE: This is a btcd extension and requires a websocket connection. -func (c *Client) Rescan(startBlock *wire.ShaHash, +func (c *Client) Rescan(startBlock *chainhash.Hash, addresses []btcutil.Address, outpoints []*wire.OutPoint) error { @@ -1036,9 +1037,9 @@ func (c *Client) Rescan(startBlock *wire.ShaHash, // See RescanEndBlock for the blocking version and more details. // // NOTE: This is a btcd extension and requires a websocket connection. -func (c *Client) RescanEndBlockAsync(startBlock *wire.ShaHash, +func (c *Client) RescanEndBlockAsync(startBlock *chainhash.Hash, addresses []btcutil.Address, outpoints []*wire.OutPoint, - endBlock *wire.ShaHash) FutureRescanResult { + endBlock *chainhash.Hash) FutureRescanResult { // Not supported in HTTP POST mode. if c.config.HTTPPostMode { @@ -1052,12 +1053,12 @@ func (c *Client) RescanEndBlockAsync(startBlock *wire.ShaHash, } // Convert block hashes to strings. - var startBlockShaStr, endBlockShaStr string + var startBlockHashStr, endBlockHashStr string if startBlock != nil { - startBlockShaStr = startBlock.String() + startBlockHashStr = startBlock.String() } if endBlock != nil { - endBlockShaStr = endBlock.String() + endBlockHashStr = endBlock.String() } // Convert addresses to strings. @@ -1072,8 +1073,8 @@ func (c *Client) RescanEndBlockAsync(startBlock *wire.ShaHash, ops = append(ops, newOutPointFromWire(op)) } - cmd := btcjson.NewRescanCmd(startBlockShaStr, addrs, ops, - &endBlockShaStr) + cmd := btcjson.NewRescanCmd(startBlockHashStr, addrs, ops, + &endBlockHashStr) return c.sendCmd(cmd) } @@ -1096,9 +1097,9 @@ func (c *Client) RescanEndBlockAsync(startBlock *wire.ShaHash, // See Rescan to also perform a rescan through current end of the longest chain. // // NOTE: This is a btcd extension and requires a websocket connection. -func (c *Client) RescanEndHeight(startBlock *wire.ShaHash, +func (c *Client) RescanEndHeight(startBlock *chainhash.Hash, addresses []btcutil.Address, outpoints []*wire.OutPoint, - endBlock *wire.ShaHash) error { + endBlock *chainhash.Hash) error { return c.RescanEndBlockAsync(startBlock, addresses, outpoints, endBlock).Receive() diff --git a/rawtransactions.go b/rawtransactions.go index 5e4fdac1..0c934554 100644 --- a/rawtransactions.go +++ b/rawtransactions.go @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2015 The btcsuite developers +// Copyright (c) 2014-2016 The btcsuite developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -10,6 +10,7 @@ import ( "encoding/json" "github.com/btcsuite/btcd/btcjson" + "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" ) @@ -95,7 +96,7 @@ func (r FutureGetRawTransactionResult) Receive() (*btcutil.Tx, error) { // the returned instance. // // See GetRawTransaction for the blocking version and more details. -func (c *Client) GetRawTransactionAsync(txHash *wire.ShaHash) FutureGetRawTransactionResult { +func (c *Client) GetRawTransactionAsync(txHash *chainhash.Hash) FutureGetRawTransactionResult { hash := "" if txHash != nil { hash = txHash.String() @@ -109,7 +110,7 @@ func (c *Client) GetRawTransactionAsync(txHash *wire.ShaHash) FutureGetRawTransa // // See GetRawTransactionVerbose to obtain additional information about the // transaction. -func (c *Client) GetRawTransaction(txHash *wire.ShaHash) (*btcutil.Tx, error) { +func (c *Client) GetRawTransaction(txHash *chainhash.Hash) (*btcutil.Tx, error) { return c.GetRawTransactionAsync(txHash).Receive() } @@ -141,7 +142,7 @@ func (r FutureGetRawTransactionVerboseResult) Receive() (*btcjson.TxRawResult, e // function on the returned instance. // // See GetRawTransactionVerbose for the blocking version and more details. -func (c *Client) GetRawTransactionVerboseAsync(txHash *wire.ShaHash) FutureGetRawTransactionVerboseResult { +func (c *Client) GetRawTransactionVerboseAsync(txHash *chainhash.Hash) FutureGetRawTransactionVerboseResult { hash := "" if txHash != nil { hash = txHash.String() @@ -155,7 +156,7 @@ func (c *Client) GetRawTransactionVerboseAsync(txHash *wire.ShaHash) FutureGetRa // its hash. // // See GetRawTransaction to obtain only the transaction already deserialized. -func (c *Client) GetRawTransactionVerbose(txHash *wire.ShaHash) (*btcjson.TxRawResult, error) { +func (c *Client) GetRawTransactionVerbose(txHash *chainhash.Hash) (*btcjson.TxRawResult, error) { return c.GetRawTransactionVerboseAsync(txHash).Receive() } @@ -263,7 +264,7 @@ 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() (*wire.ShaHash, error) { +func (r FutureSendRawTransactionResult) Receive() (*chainhash.Hash, error) { res, err := receiveFuture(r) if err != nil { return nil, err @@ -276,7 +277,7 @@ func (r FutureSendRawTransactionResult) Receive() (*wire.ShaHash, error) { return nil, err } - return wire.NewShaHashFromStr(txHashStr) + return chainhash.NewHashFromStr(txHashStr) } // SendRawTransactionAsync returns an instance of a type that can be used to get @@ -301,7 +302,7 @@ func (c *Client) SendRawTransactionAsync(tx *wire.MsgTx, allowHighFees bool) Fut // SendRawTransaction submits the encoded transaction to the server which will // then relay it to the network. -func (c *Client) SendRawTransaction(tx *wire.MsgTx, allowHighFees bool) (*wire.ShaHash, error) { +func (c *Client) SendRawTransaction(tx *wire.MsgTx, allowHighFees bool) (*chainhash.Hash, error) { return c.SendRawTransactionAsync(tx, allowHighFees).Receive() } diff --git a/wallet.go b/wallet.go index c5e378b6..0eb58061 100644 --- a/wallet.go +++ b/wallet.go @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2015 The btcsuite developers +// Copyright (c) 2014-2016 The btcsuite developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -10,6 +10,7 @@ import ( "github.com/btcsuite/btcd/btcjson" "github.com/btcsuite/btcd/chaincfg" + "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" ) @@ -45,7 +46,7 @@ func (r FutureGetTransactionResult) Receive() (*btcjson.GetTransactionResult, er // the returned instance. // // See GetTransaction for the blocking version and more details. -func (c *Client) GetTransactionAsync(txHash *wire.ShaHash) FutureGetTransactionResult { +func (c *Client) GetTransactionAsync(txHash *chainhash.Hash) FutureGetTransactionResult { hash := "" if txHash != nil { hash = txHash.String() @@ -58,7 +59,7 @@ func (c *Client) GetTransactionAsync(txHash *wire.ShaHash) FutureGetTransactionR // GetTransaction returns detailed information about a wallet transaction. // // See GetRawTransaction to return the raw transaction instead. -func (c *Client) GetTransaction(txHash *wire.ShaHash) (*btcjson.GetTransactionResult, error) { +func (c *Client) GetTransaction(txHash *chainhash.Hash) (*btcjson.GetTransactionResult, error) { return c.GetTransactionAsync(txHash).Receive() } @@ -268,7 +269,7 @@ func (r FutureListSinceBlockResult) Receive() (*btcjson.ListSinceBlockResult, er // the returned instance. // // See ListSinceBlock for the blocking version and more details. -func (c *Client) ListSinceBlockAsync(blockHash *wire.ShaHash) FutureListSinceBlockResult { +func (c *Client) ListSinceBlockAsync(blockHash *chainhash.Hash) FutureListSinceBlockResult { var hash *string if blockHash != nil { hash = btcjson.String(blockHash.String()) @@ -283,7 +284,7 @@ func (c *Client) ListSinceBlockAsync(blockHash *wire.ShaHash) FutureListSinceBlo // minimum confirmations as a filter. // // See ListSinceBlockMinConf to override the minimum number of confirmations. -func (c *Client) ListSinceBlock(blockHash *wire.ShaHash) (*btcjson.ListSinceBlockResult, error) { +func (c *Client) ListSinceBlock(blockHash *chainhash.Hash) (*btcjson.ListSinceBlockResult, error) { return c.ListSinceBlockAsync(blockHash).Receive() } @@ -292,7 +293,7 @@ func (c *Client) ListSinceBlock(blockHash *wire.ShaHash) (*btcjson.ListSinceBloc // function on the returned instance. // // See ListSinceBlockMinConf for the blocking version and more details. -func (c *Client) ListSinceBlockMinConfAsync(blockHash *wire.ShaHash, minConfirms int) FutureListSinceBlockResult { +func (c *Client) ListSinceBlockMinConfAsync(blockHash *chainhash.Hash, minConfirms int) FutureListSinceBlockResult { var hash *string if blockHash != nil { hash = btcjson.String(blockHash.String()) @@ -307,7 +308,7 @@ func (c *Client) ListSinceBlockMinConfAsync(blockHash *wire.ShaHash, minConfirms // number of minimum confirmations as a filter. // // See ListSinceBlock to use the default minimum number of confirmations. -func (c *Client) ListSinceBlockMinConf(blockHash *wire.ShaHash, minConfirms int) (*btcjson.ListSinceBlockResult, error) { +func (c *Client) ListSinceBlockMinConf(blockHash *chainhash.Hash, minConfirms int) (*btcjson.ListSinceBlockResult, error) { return c.ListSinceBlockMinConfAsync(blockHash, minConfirms).Receive() } @@ -386,7 +387,7 @@ func (r FutureListLockUnspentResult) Receive() ([]*wire.OutPoint, error) { // Create a slice of outpoints from the transaction input structs. ops := make([]*wire.OutPoint, len(inputs)) for i, input := range inputs { - sha, err := wire.NewShaHashFromStr(input.Txid) + sha, err := chainhash.NewHashFromStr(input.Txid) if err != nil { return nil, err } @@ -451,7 +452,7 @@ type FutureSendToAddressResult chan *response // Receive waits for the response promised by the future and returns the hash // of the transaction sending the passed amount to the given address. -func (r FutureSendToAddressResult) Receive() (*wire.ShaHash, error) { +func (r FutureSendToAddressResult) Receive() (*chainhash.Hash, error) { res, err := receiveFuture(r) if err != nil { return nil, err @@ -464,7 +465,7 @@ func (r FutureSendToAddressResult) Receive() (*wire.ShaHash, error) { return nil, err } - return wire.NewShaHashFromStr(txHash) + return chainhash.NewHashFromStr(txHash) } // SendToAddressAsync returns an instance of a type that can be used to get the @@ -486,7 +487,7 @@ func (c *Client) SendToAddressAsync(address btcutil.Address, amount btcutil.Amou // // NOTE: This function requires to the wallet to be unlocked. See the // WalletPassphrase function for more details. -func (c *Client) SendToAddress(address btcutil.Address, amount btcutil.Amount) (*wire.ShaHash, error) { +func (c *Client) SendToAddress(address btcutil.Address, amount btcutil.Amount) (*chainhash.Hash, error) { return c.SendToAddressAsync(address, amount).Receive() } @@ -517,7 +518,7 @@ func (c *Client) SendToAddressCommentAsync(address btcutil.Address, // // NOTE: This function requires to the wallet to be unlocked. See the // WalletPassphrase function for more details. -func (c *Client) SendToAddressComment(address btcutil.Address, amount btcutil.Amount, comment, commentTo string) (*wire.ShaHash, error) { +func (c *Client) SendToAddressComment(address btcutil.Address, amount btcutil.Amount, comment, commentTo string) (*chainhash.Hash, error) { return c.SendToAddressCommentAsync(address, amount, comment, commentTo).Receive() } @@ -530,7 +531,7 @@ type FutureSendFromResult chan *response // Receive waits for the response promised by the future and returns the hash // of the transaction sending amount to the given address using the provided // account as a source of funds. -func (r FutureSendFromResult) Receive() (*wire.ShaHash, error) { +func (r FutureSendFromResult) Receive() (*chainhash.Hash, error) { res, err := receiveFuture(r) if err != nil { return nil, err @@ -543,7 +544,7 @@ func (r FutureSendFromResult) Receive() (*wire.ShaHash, error) { return nil, err } - return wire.NewShaHashFromStr(txHash) + return chainhash.NewHashFromStr(txHash) } // SendFromAsync returns an instance of a type that can be used to get the @@ -566,7 +567,7 @@ func (c *Client) SendFromAsync(fromAccount string, toAddress btcutil.Address, am // // NOTE: This function requires to the wallet to be unlocked. See the // WalletPassphrase function for more details. -func (c *Client) SendFrom(fromAccount string, toAddress btcutil.Address, amount btcutil.Amount) (*wire.ShaHash, error) { +func (c *Client) SendFrom(fromAccount string, toAddress btcutil.Address, amount btcutil.Amount) (*chainhash.Hash, error) { return c.SendFromAsync(fromAccount, toAddress, amount).Receive() } @@ -591,7 +592,7 @@ func (c *Client) SendFromMinConfAsync(fromAccount string, toAddress btcutil.Addr // // NOTE: This function requires to the wallet to be unlocked. See the // WalletPassphrase function for more details. -func (c *Client) SendFromMinConf(fromAccount string, toAddress btcutil.Address, amount btcutil.Amount, minConfirms int) (*wire.ShaHash, error) { +func (c *Client) SendFromMinConf(fromAccount string, toAddress btcutil.Address, amount btcutil.Amount, minConfirms int) (*chainhash.Hash, error) { return c.SendFromMinConfAsync(fromAccount, toAddress, amount, minConfirms).Receive() } @@ -624,7 +625,7 @@ func (c *Client) SendFromCommentAsync(fromAccount string, // WalletPassphrase function for more details. func (c *Client) SendFromComment(fromAccount string, toAddress btcutil.Address, amount btcutil.Amount, minConfirms int, - comment, commentTo string) (*wire.ShaHash, error) { + comment, commentTo string) (*chainhash.Hash, error) { return c.SendFromCommentAsync(fromAccount, toAddress, amount, minConfirms, comment, commentTo).Receive() @@ -638,7 +639,7 @@ type FutureSendManyResult chan *response // Receive waits for the response promised by the future and returns the hash // of the transaction sending multiple amounts to multiple addresses using the // provided account as a source of funds. -func (r FutureSendManyResult) Receive() (*wire.ShaHash, error) { +func (r FutureSendManyResult) Receive() (*chainhash.Hash, error) { res, err := receiveFuture(r) if err != nil { return nil, err @@ -651,7 +652,7 @@ func (r FutureSendManyResult) Receive() (*wire.ShaHash, error) { return nil, err } - return wire.NewShaHashFromStr(txHash) + return chainhash.NewHashFromStr(txHash) } // SendManyAsync returns an instance of a type that can be used to get the @@ -676,7 +677,7 @@ func (c *Client) SendManyAsync(fromAccount string, amounts map[btcutil.Address]b // // NOTE: This function requires to the wallet to be unlocked. See the // WalletPassphrase function for more details. -func (c *Client) SendMany(fromAccount string, amounts map[btcutil.Address]btcutil.Amount) (*wire.ShaHash, error) { +func (c *Client) SendMany(fromAccount string, amounts map[btcutil.Address]btcutil.Amount) (*chainhash.Hash, error) { return c.SendManyAsync(fromAccount, amounts).Receive() } @@ -709,7 +710,7 @@ func (c *Client) SendManyMinConfAsync(fromAccount string, // WalletPassphrase function for more details. func (c *Client) SendManyMinConf(fromAccount string, amounts map[btcutil.Address]btcutil.Amount, - minConfirms int) (*wire.ShaHash, error) { + minConfirms int) (*chainhash.Hash, error) { return c.SendManyMinConfAsync(fromAccount, amounts, minConfirms).Receive() } @@ -744,7 +745,7 @@ func (c *Client) SendManyCommentAsync(fromAccount string, // WalletPassphrase function for more details. func (c *Client) SendManyComment(fromAccount string, amounts map[btcutil.Address]btcutil.Amount, minConfirms int, - comment string) (*wire.ShaHash, error) { + comment string) (*chainhash.Hash, error) { return c.SendManyCommentAsync(fromAccount, amounts, minConfirms, comment).Receive()