diff --git a/chain/chain.go b/chain/chain.go index cf6e064..7502821 100644 --- a/chain/chain.go +++ b/chain/chain.go @@ -21,12 +21,12 @@ import ( "sync" "time" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcnet" "github.com/btcsuite/btcrpcclient" "github.com/btcsuite/btcutil" "github.com/btcsuite/btcwallet/keystore" "github.com/btcsuite/btcwallet/txstore" - "github.com/btcsuite/btcwire" "github.com/btcsuite/btcws" ) @@ -162,12 +162,12 @@ type ( Block *txstore.Block // nil if unmined } RescanProgress struct { - Hash *btcwire.ShaHash + Hash *wire.ShaHash Height int32 Time time.Time } RescanFinished struct { - Hash *btcwire.ShaHash + Hash *wire.ShaHash Height int32 Time time.Time } @@ -180,7 +180,7 @@ func parseBlock(block *btcws.BlockDetails) (blk *txstore.Block, idx int, err err if block == nil { return nil, btcutil.TxIndexUnknown, nil } - blksha, err := btcwire.NewShaHashFromStr(block.Hash) + blksha, err := wire.NewShaHashFromStr(block.Hash) if err != nil { return nil, btcutil.TxIndexUnknown, err } @@ -197,11 +197,11 @@ func (c *Client) onClientConnect() { c.notifyConnected(true) } -func (c *Client) onBlockConnected(hash *btcwire.ShaHash, height int32) { +func (c *Client) onBlockConnected(hash *wire.ShaHash, height int32) { c.enqueueNotification <- BlockConnected{Hash: hash, Height: height} } -func (c *Client) onBlockDisconnected(hash *btcwire.ShaHash, height int32) { +func (c *Client) onBlockDisconnected(hash *wire.ShaHash, height int32) { c.enqueueNotification <- BlockDisconnected{Hash: hash, Height: height} } @@ -237,11 +237,11 @@ func (c *Client) onRedeemingTx(tx *btcutil.Tx, block *btcws.BlockDetails) { c.enqueueNotification <- RedeemingTx{tx, blk} } -func (c *Client) onRescanProgress(hash *btcwire.ShaHash, height int32, blkTime time.Time) { +func (c *Client) onRescanProgress(hash *wire.ShaHash, height int32, blkTime time.Time) { c.enqueueNotification <- &RescanProgress{hash, height, blkTime} } -func (c *Client) onRescanFinished(hash *btcwire.ShaHash, height int32, blkTime time.Time) { +func (c *Client) onRescanFinished(hash *wire.ShaHash, height int32, blkTime time.Time) { c.enqueueNotification <- &RescanFinished{hash, height, blkTime} } diff --git a/config.go b/config.go index d71eee5..2f7912a 100644 --- a/config.go +++ b/config.go @@ -24,15 +24,15 @@ import ( "sort" "strings" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" - "github.com/btcsuite/btcwire" flags "github.com/btcsuite/go-flags" ) const ( defaultCAFilename = "btcd.cert" defaultConfigFilename = "btcwallet.conf" - defaultBtcNet = btcwire.TestNet3 + defaultBtcNet = wire.TestNet3 defaultLogLevel = "info" defaultLogDirname = "logs" defaultLogFilename = "btcwallet.log" diff --git a/createtx.go b/createtx.go index 611137a..3d975b6 100644 --- a/createtx.go +++ b/createtx.go @@ -25,10 +25,10 @@ import ( "github.com/btcsuite/btcd/blockchain" "github.com/btcsuite/btcd/txscript" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" "github.com/btcsuite/btcwallet/keystore" "github.com/btcsuite/btcwallet/txstore" - "github.com/btcsuite/btcwire" ) const ( @@ -163,7 +163,7 @@ func createTx( changeAddress func(*keystore.BlockStamp) (btcutil.Address, error)) ( *CreatedTx, error) { - msgtx := btcwire.NewMsgTx() + msgtx := wire.NewMsgTx() minAmount, err := addOutputs(msgtx, outputs) if err != nil { return nil, err @@ -184,7 +184,7 @@ func createTx( } input, eligible = eligible[0], eligible[1:] inputs = append(inputs, input) - msgtx.AddTxIn(btcwire.NewTxIn(input.OutPoint(), nil)) + msgtx.AddTxIn(wire.NewTxIn(input.OutPoint(), nil)) totalAdded += input.Amount() } @@ -202,7 +202,7 @@ func createTx( } input, eligible = eligible[0], eligible[1:] inputs = append(inputs, input) - msgtx.AddTxIn(btcwire.NewTxIn(input.OutPoint(), nil)) + msgtx.AddTxIn(wire.NewTxIn(input.OutPoint(), nil)) szEst += txInEstimate totalAdded += input.Amount() feeEst = minimumFee(feeIncrement, szEst, msgtx.TxOut, inputs, bs.Height) @@ -253,7 +253,7 @@ func createTx( } input, eligible = eligible[0], eligible[1:] inputs = append(inputs, input) - msgtx.AddTxIn(btcwire.NewTxIn(input.OutPoint(), nil)) + msgtx.AddTxIn(wire.NewTxIn(input.OutPoint(), nil)) szEst += txInEstimate totalAdded += input.Amount() feeEst = minimumFee(feeIncrement, szEst, msgtx.TxOut, inputs, bs.Height) @@ -274,12 +274,12 @@ func createTx( // addChange adds a new output with the given amount and address, and // randomizes the index (and returns it) of the newly added output. -func addChange(msgtx *btcwire.MsgTx, change btcutil.Amount, changeAddr btcutil.Address) (int, error) { +func addChange(msgtx *wire.MsgTx, change btcutil.Amount, changeAddr btcutil.Address) (int, error) { pkScript, err := txscript.PayToAddrScript(changeAddr) if err != nil { return 0, fmt.Errorf("cannot create txout script: %s", err) } - msgtx.AddTxOut(btcwire.NewTxOut(int64(change), pkScript)) + msgtx.AddTxOut(wire.NewTxOut(int64(change), pkScript)) // Randomize index of the change output. rng := badrand.New(badrand.NewSource(time.Now().UnixNano())) @@ -308,7 +308,7 @@ func (w *Wallet) changeAddress(bs *keystore.BlockStamp) (btcutil.Address, error) // addOutputs adds the given address/amount pairs as outputs to msgtx, // returning their total amount. -func addOutputs(msgtx *btcwire.MsgTx, pairs map[string]btcutil.Amount) (btcutil.Amount, error) { +func addOutputs(msgtx *wire.MsgTx, pairs map[string]btcutil.Amount) (btcutil.Amount, error) { var minAmount btcutil.Amount for addrStr, amt := range pairs { if amt <= 0 { @@ -325,7 +325,7 @@ func addOutputs(msgtx *btcwire.MsgTx, pairs map[string]btcutil.Amount) (btcutil. if err != nil { return minAmount, fmt.Errorf("cannot create txout script: %s", err) } - txout := btcwire.NewTxOut(int64(amt), pkScript) + txout := wire.NewTxOut(int64(amt), pkScript) msgtx.AddTxOut(txout) } return minAmount, nil @@ -370,7 +370,7 @@ func (w *Wallet) findEligibleOutputs(minconf int, bs *keystore.BlockStamp) ([]tx // signMsgTx sets the SignatureScript for every item in msgtx.TxIn. // It must be called every time a msgtx is changed. // Only P2PKH outputs are supported at this point. -func signMsgTx(msgtx *btcwire.MsgTx, prevOutputs []txstore.Credit, store *keystore.Store) error { +func signMsgTx(msgtx *wire.MsgTx, prevOutputs []txstore.Credit, store *keystore.Store) error { if len(prevOutputs) != len(msgtx.TxIn) { return fmt.Errorf( "Number of prevOutputs (%d) does not match number of tx inputs (%d)", @@ -410,7 +410,7 @@ func signMsgTx(msgtx *btcwire.MsgTx, prevOutputs []txstore.Credit, store *keysto return nil } -func validateMsgTx(msgtx *btcwire.MsgTx, prevOutputs []txstore.Credit) error { +func validateMsgTx(msgtx *wire.MsgTx, prevOutputs []txstore.Credit) error { flags := txscript.ScriptCanonicalSignatures | txscript.ScriptStrictMultiSig bip16 := time.Now().After(txscript.Bip16Activation) if bip16 { @@ -434,7 +434,7 @@ func validateMsgTx(msgtx *btcwire.MsgTx, prevOutputs []txstore.Credit) error { // s less than 1 kilobyte and none of the outputs contain a value // less than 1 bitcent. Otherwise, the fee will be calculated using // incr, incrementing the fee for each kilobyte of transaction. -func minimumFee(incr btcutil.Amount, txLen int, outputs []*btcwire.TxOut, prevOutputs []txstore.Credit, height int32) btcutil.Amount { +func minimumFee(incr btcutil.Amount, txLen int, outputs []*wire.TxOut, prevOutputs []txstore.Credit, height int32) btcutil.Amount { allowFree := false if !cfg.DisallowFree { allowFree = allowNoFeeTx(height, prevOutputs, txLen) diff --git a/createtx_test.go b/createtx_test.go index df15f7d..4becb72 100644 --- a/createtx_test.go +++ b/createtx_test.go @@ -7,10 +7,10 @@ import ( "testing" "github.com/btcsuite/btcd/txscript" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" "github.com/btcsuite/btcwallet/keystore" "github.com/btcsuite/btcwallet/txstore" - "github.com/btcsuite/btcwire" ) // This is a tx that transfers funds (0.371 BTC) to addresses of known privKeys. @@ -41,7 +41,7 @@ var ( ) func Test_addOutputs(t *testing.T) { - msgtx := btcwire.NewMsgTx() + msgtx := wire.NewMsgTx() pairs := map[string]btcutil.Amount{outAddr1: 10, outAddr2: 1} if _, err := addOutputs(msgtx, pairs); err != nil { t.Fatal(err) @@ -126,7 +126,7 @@ func TestCreateTxInsufficientFundsError(t *testing.T) { } // checkOutputsMatch checks that the outputs in the tx match the expected ones. -func checkOutputsMatch(t *testing.T, msgtx *btcwire.MsgTx, expected map[string]btcutil.Amount) { +func checkOutputsMatch(t *testing.T, msgtx *wire.MsgTx, expected map[string]btcutil.Amount) { // This is a bit convoluted because the index of the change output is randomized. for addrStr, v := range expected { addr, err := btcutil.DecodeAddress(addrStr, activeNet.Params) diff --git a/createtx_test_disabled.go b/createtx_test_disabled.go index 14d8113..5ee5749 100644 --- a/createtx_test_disabled.go +++ b/createtx_test_disabled.go @@ -13,9 +13,9 @@ import ( "testing" "github.com/btcsuite/btcd/txscript" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" "github.com/btcsuite/btcwallet/tx" - "github.com/btcsuite/btcwire" ) func init() { @@ -83,14 +83,14 @@ func TestAllowFree(t *testing.T) { func TestFakeTxs(t *testing.T) { // First we need a wallet. w, err := keystore.NewStore("banana wallet", "", []byte("banana"), - btcwire.MainNet, &keystore.BlockStamp{}, 100) + wire.MainNet, &keystore.BlockStamp{}, 100) if err != nil { t.Errorf("Can not create encrypted wallet: %s", err) return } a := &Wallet{ Wallet: w, - lockedOutpoints: map[btcwire.OutPoint]struct{}{}, + lockedOutpoints: map[wire.OutPoint]struct{}{}, } w.Unlock([]byte("banana")) @@ -106,10 +106,10 @@ func TestFakeTxs(t *testing.T) { return } copy(utxo.AddrHash[:], addr.ScriptAddress()) - ophash := (btcwire.ShaHash)([...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + ophash := (wire.ShaHash)([...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}) - out := btcwire.NewOutPoint(&ophash, 0) + out := wire.NewOutPoint(&ophash, 0) utxo.Out = tx.OutPoint(*out) ss, err := txscript.PayToAddrScript(addr) if err != nil { diff --git a/keystore/keystore.go b/keystore/keystore.go index 38c1735..552be06 100644 --- a/keystore/keystore.go +++ b/keystore/keystore.go @@ -37,11 +37,11 @@ import ( "golang.org/x/crypto/ripemd160" "github.com/btcsuite/btcd/txscript" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcec" "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" "github.com/btcsuite/btcwallet/rename" - "github.com/btcsuite/btcwire" ) const ( @@ -202,7 +202,7 @@ func chainedPrivKey(privkey, pubkey, chaincode []byte) ([]byte, error) { } xorbytes := make([]byte, 32) - chainMod := btcwire.DoubleSha256(pubkey) + chainMod := wire.DoubleSha256(pubkey) for i := range xorbytes { xorbytes[i] = chainMod[i] ^ chaincode[i] } @@ -234,7 +234,7 @@ func chainedPubKey(pubkey, chaincode []byte) ([]byte, error) { } xorbytes := make([]byte, 32) - chainMod := btcwire.DoubleSha256(pubkey) + chainMod := wire.DoubleSha256(pubkey) for i := range xorbytes { xorbytes[i] = chainMod[i] ^ chaincode[i] } @@ -487,12 +487,12 @@ func (net *netParams) ReadFrom(r io.Reader) (int64, error) { return n64, err } - switch btcwire.BitcoinNet(binary.LittleEndian.Uint32(uint32Bytes)) { - case btcwire.MainNet: + switch wire.BitcoinNet(binary.LittleEndian.Uint32(uint32Bytes)) { + case wire.MainNet: *net = (netParams)(btcnet.MainNetParams) - case btcwire.TestNet3: + case wire.TestNet3: *net = (netParams)(btcnet.TestNet3Params) - case btcwire.SimNet: + case wire.SimNet: *net = (netParams)(btcnet.SimNetParams) default: return n64, errors.New("unknown network") @@ -601,7 +601,7 @@ func New(dir string, desc string, passphrase []byte, net *btcnet.Params, kdfParams: *kdfp, recent: recentBlocks{ lastHeight: createdAt.Height, - hashes: []*btcwire.ShaHash{ + hashes: []*wire.ShaHash{ createdAt.Hash, }, }, @@ -1354,7 +1354,7 @@ func (s *Store) SetSyncedWith(bs *BlockStamp) { // NOTE: If the hash of the synced block is not known, hash will be nil, and // must be obtained from elsewhere. This must be explicitly checked before // dereferencing the pointer. -func (s *Store) SyncedTo() (hash *btcwire.ShaHash, height int32) { +func (s *Store) SyncedTo() (hash *wire.ShaHash, height int32) { s.mtx.RLock() defer s.mtx.RUnlock() @@ -1541,7 +1541,7 @@ func (s *Store) ExportWatchingWallet() (*Store, error) { kgwc := s.keyGenerator.watchingCopy(ws) ws.keyGenerator = *(kgwc.(*btcAddress)) if len(s.recent.hashes) != 0 { - ws.recent.hashes = make([]*btcwire.ShaHash, 0, len(s.recent.hashes)) + ws.recent.hashes = make([]*wire.ShaHash, 0, len(s.recent.hashes)) for _, hash := range s.recent.hashes { hashCpy := *hash ws.recent.hashes = append(ws.recent.hashes, &hashCpy) @@ -1796,7 +1796,7 @@ func (af *addrFlags) WriteTo(w io.Writer) (int64, error) { // recentBlocks holds at most the last 20 seen block hashes as well as // the block height of the most recently seen block. type recentBlocks struct { - hashes []*btcwire.ShaHash + hashes []*wire.ShaHash lastHeight int32 } @@ -1828,14 +1828,14 @@ func (rb *recentBlocks) readFromVersion(v version, r io.Reader) (int64, error) { } // Read block hash. - var syncedBlockHash btcwire.ShaHash + var syncedBlockHash wire.ShaHash n, err = io.ReadFull(r, syncedBlockHash[:]) read += int64(n) if err != nil { return read, err } - rb.hashes = []*btcwire.ShaHash{ + rb.hashes = []*wire.ShaHash{ &syncedBlockHash, } @@ -1879,9 +1879,9 @@ func (rb *recentBlocks) ReadFrom(r io.Reader) (int64, error) { // Read nBlocks block hashes. Hashes are expected to be in // order of oldest to newest, but there's no way to check // that here. - rb.hashes = make([]*btcwire.ShaHash, 0, nBlocks) + rb.hashes = make([]*wire.ShaHash, 0, nBlocks) for i := uint32(0); i < nBlocks; i++ { - var blockSha btcwire.ShaHash + var blockSha wire.ShaHash n, err := io.ReadFull(r, blockSha[:]) read += int64(n) if err != nil { @@ -3040,7 +3040,7 @@ func (sa *scriptAddress) watchingCopy(s *Store) walletAddress { } func walletHash(b []byte) uint32 { - sum := btcwire.DoubleSha256(b) + sum := wire.DoubleSha256(b) return binary.LittleEndian.Uint32(sum) } @@ -3247,6 +3247,6 @@ func (e *scriptEntry) ReadFrom(r io.Reader) (n int64, err error) { // used to mark a point in the blockchain that a key store element is // synced to. type BlockStamp struct { - Hash *btcwire.ShaHash + Hash *wire.ShaHash Height int32 } diff --git a/keystore/keystore_test.go b/keystore/keystore_test.go index 97982a8..7e5af17 100644 --- a/keystore/keystore_test.go +++ b/keystore/keystore_test.go @@ -24,10 +24,10 @@ import ( "testing" "github.com/btcsuite/btcd/txscript" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcec" "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" - "github.com/btcsuite/btcwire" "github.com/davecgh/go-spew/spew" ) @@ -38,7 +38,7 @@ var tstNetParams = &btcnet.MainNetParams func makeBS(height int32) *BlockStamp { return &BlockStamp{ - Hash: new(btcwire.ShaHash), + Hash: new(wire.ShaHash), Height: height, } } diff --git a/params.go b/params.go index 550b1c6..40f26b4 100644 --- a/params.go +++ b/params.go @@ -32,7 +32,7 @@ type params struct { } // mainNetParams contains parameters specific running btcwallet and -// btcd on the main network (btcwire.MainNet). +// btcd on the main network (wire.MainNet). var mainNetParams = params{ Params: &btcnet.MainNetParams, connect: "localhost:8334", @@ -41,7 +41,7 @@ var mainNetParams = params{ } // testNet3Params contains parameters specific running btcwallet and -// btcd on the test network (version 3) (btcwire.TestNet3). +// btcd on the test network (version 3) (wire.TestNet3). var testNet3Params = params{ Params: &btcnet.TestNet3Params, connect: "localhost:18334", @@ -50,7 +50,7 @@ var testNet3Params = params{ } // simNetParams contains parameters specific to the simulation test network -// (btcwire.SimNet). +// (wire.SimNet). var simNetParams = params{ Params: &btcnet.SimNetParams, connect: "localhost:18556", diff --git a/rescan.go b/rescan.go index 508f10d..49bba99 100644 --- a/rescan.go +++ b/rescan.go @@ -17,10 +17,10 @@ package main import ( + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" "github.com/btcsuite/btcwallet/chain" "github.com/btcsuite/btcwallet/keystore" - "github.com/btcsuite/btcwire" ) // RescanProgressMsg reports the current progress made by a rescan for a @@ -46,7 +46,7 @@ type RescanFinishedMsg struct { type RescanJob struct { InitialSync bool Addrs []btcutil.Address - OutPoints []*btcwire.OutPoint + OutPoints []*wire.OutPoint BlockStamp keystore.BlockStamp err chan error } @@ -56,7 +56,7 @@ type RescanJob struct { type rescanBatch struct { initialSync bool addrs []btcutil.Address - outpoints []*btcwire.OutPoint + outpoints []*wire.OutPoint bs keystore.BlockStamp errChans []chan error } @@ -301,7 +301,7 @@ func (w *Wallet) RescanActiveAddresses() (err error) { if err != nil { return } - outpoints := make([]*btcwire.OutPoint, len(unspents)) + outpoints := make([]*wire.OutPoint, len(unspents)) for i, output := range unspents { outpoints[i] = output.OutPoint() } diff --git a/rpcserver.go b/rpcserver.go index e462fe5..be9cecc 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -38,6 +38,7 @@ import ( "time" "github.com/btcsuite/btcd/txscript" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcec" "github.com/btcsuite/btcjson" "github.com/btcsuite/btcrpcclient" @@ -45,7 +46,6 @@ import ( "github.com/btcsuite/btcwallet/chain" "github.com/btcsuite/btcwallet/keystore" "github.com/btcsuite/btcwallet/txstore" - "github.com/btcsuite/btcwire" "github.com/btcsuite/btcws" "github.com/btcsuite/websocket" ) @@ -1922,7 +1922,7 @@ func GetReceivedByAddress(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) ( func GetTransaction(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (interface{}, error) { cmd := icmd.(*btcjson.GetTransactionCmd) - txSha, err := btcwire.NewShaHashFromStr(cmd.Txid) + txSha, err := wire.NewShaHashFromStr(cmd.Txid) if err != nil { return nil, btcjson.ErrDecodeHexString } @@ -2184,7 +2184,7 @@ func ListSinceBlock(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (interf height := int32(-1) if cmd.BlockHash != "" { - hash, err := btcwire.NewShaHashFromStr(cmd.BlockHash) + hash, err := wire.NewShaHashFromStr(cmd.BlockHash) if err != nil { return nil, DeserializationError{err} } @@ -2328,11 +2328,11 @@ func LockUnspent(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (interface w.ResetLockedOutpoints() default: for _, input := range cmd.Transactions { - txSha, err := btcwire.NewShaHashFromStr(input.Txid) + txSha, err := wire.NewShaHashFromStr(input.Txid) if err != nil { return nil, ParseError{err} } - op := btcwire.OutPoint{Hash: *txSha, Index: input.Vout} + op := wire.OutPoint{Hash: *txSha, Index: input.Vout} if cmd.Unlock { w.UnlockOutpoint(op) } else { @@ -2506,7 +2506,7 @@ func SignMessage(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (interface fullmsg := "Bitcoin Signed Message:\n" + cmd.Message sigbytes, err := btcec.SignCompact(btcec.S256(), privKey, - btcwire.DoubleSha256([]byte(fullmsg)), ainfo.Compressed()) + wire.DoubleSha256([]byte(fullmsg)), ainfo.Compressed()) if err != nil { return nil, err } @@ -2594,7 +2594,7 @@ func SignRawTransaction(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (in if err != nil { return nil, btcjson.ErrDecodeHexString } - msgTx := btcwire.NewMsgTx() + msgTx := wire.NewMsgTx() err = msgTx.Deserialize(bytes.NewBuffer(serializedTx)) if err != nil { e := errors.New("TX decode failed") @@ -2604,10 +2604,10 @@ func SignRawTransaction(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (in // First we add the stuff we have been given. // TODO(oga) really we probably should look these up with btcd anyway // to make sure that they match the blockchain if present. - inputs := make(map[btcwire.OutPoint][]byte) + inputs := make(map[wire.OutPoint][]byte) scripts := make(map[string][]byte) for _, rti := range cmd.Inputs { - inputSha, err := btcwire.NewShaHashFromStr(rti.Txid) + inputSha, err := wire.NewShaHashFromStr(rti.Txid) if err != nil { return nil, DeserializationError{err} } @@ -2636,7 +2636,7 @@ func SignRawTransaction(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (in } scripts[addr.String()] = redeemScript } - inputs[btcwire.OutPoint{ + inputs[wire.OutPoint{ Hash: *inputSha, Index: rti.Vout, }] = script @@ -2646,7 +2646,7 @@ func SignRawTransaction(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (in // querying btcd with getrawtransaction. We queue up a bunch of async // requests and will wait for replies after we have checked the rest of // the arguments. - requested := make(map[btcwire.ShaHash]*pendingTx) + requested := make(map[wire.ShaHash]*pendingTx) for _, txIn := range msgTx.TxIn { // Did we get this txin from the arguments? if _, ok := inputs[txIn.PreviousOutPoint]; ok { @@ -2740,7 +2740,7 @@ func SignRawTransaction(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (in return nil, InvalidParameterError{e} } - inputs[btcwire.OutPoint{ + inputs[wire.OutPoint{ Hash: txid, Index: input, }] = tx.MsgTx().TxOut[input].PkScript @@ -2933,7 +2933,7 @@ func VerifyMessage(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (interfa // Validate the signature - this just shows that it was valid at all. // we will compare it with the key next. pk, wasCompressed, err := btcec.RecoverCompact(btcec.S256(), sig, - btcwire.DoubleSha256([]byte("Bitcoin Signed Message:\n"+ + wire.DoubleSha256([]byte("Bitcoin Signed Message:\n"+ cmd.Message))) if err != nil { return nil, err diff --git a/txstore/fixedIO_test.go b/txstore/fixedIO_test.go index b2beed3..b642165 100644 --- a/txstore/fixedIO_test.go +++ b/txstore/fixedIO_test.go @@ -1,4 +1,4 @@ -// copied from btcwire +// copied from wire // Copyright (c) 2013-2014 Conformal Systems LLC. // Use of this source code is governed by an ISC diff --git a/txstore/serialization.go b/txstore/serialization.go index c4ab03d..201ad2e 100644 --- a/txstore/serialization.go +++ b/txstore/serialization.go @@ -27,9 +27,9 @@ import ( "path/filepath" "time" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" "github.com/btcsuite/btcwallet/rename" - "github.com/btcsuite/btcwire" ) // filename is the name of the file typically used to save a transaction @@ -125,7 +125,7 @@ func (s *Store) ReadFrom(r io.Reader) (int64, error) { continue } if cred.spentBy == nil { - op := btcwire.OutPoint{ + op := wire.OutPoint{ Hash: *tx.tx.Sha(), Index: uint32(outputIdx), } @@ -419,7 +419,7 @@ func (t *txRecord) ReadFrom(r io.Reader) (int64, error) { } // Create and save the btcutil.Tx of the read MsgTx and set its index. - tx := btcutil.NewTx((*btcwire.MsgTx)(msgTx)) + tx := btcutil.NewTx((*wire.MsgTx)(msgTx)) tx.SetIndex(txIndex) t.tx = tx @@ -749,20 +749,20 @@ func (t *txRecord) WriteTo(w io.Writer) (int64, error) { return n64, nil } -type msgTx btcwire.MsgTx +type msgTx wire.MsgTx func (tx *msgTx) ReadFrom(r io.Reader) (int64, error) { // Read from a TeeReader to return the number of read bytes. buf := bytes.Buffer{} tr := io.TeeReader(r, &buf) - if err := (*btcwire.MsgTx)(tx).Deserialize(tr); err != nil { + if err := (*wire.MsgTx)(tx).Deserialize(tr); err != nil { if buf.Len() != 0 && err == io.EOF { err = io.ErrUnexpectedEOF } return int64(buf.Len()), err } - return int64((*btcwire.MsgTx)(tx).SerializeSize()), nil + return int64((*wire.MsgTx)(tx).SerializeSize()), nil } func (tx *msgTx) WriteTo(w io.Writer) (int64, error) { @@ -771,7 +771,7 @@ func (tx *msgTx) WriteTo(w io.Writer) (int64, error) { // bytes.Buffer never fails except for OOM panics, so check and panic // on any unexpected non-nil returned errors. buf := bytes.Buffer{} - if err := (*btcwire.MsgTx)(tx).Serialize(&buf); err != nil { + if err := (*wire.MsgTx)(tx).Serialize(&buf); err != nil { panic(err) } return io.Copy(w, &buf) @@ -920,7 +920,7 @@ func (u *unconfirmedStore) ReadFrom(r io.Reader) (int64, error) { spentBlockOutPointCount := byteOrder.Uint32(uint32Bytes) for i := uint32(0); i < spentBlockOutPointCount; i++ { // Read outpoint hash and index (uint32). - op := btcwire.OutPoint{} + op := wire.OutPoint{} n, err := io.ReadFull(r, op.Hash[:]) n64 += int64(n) if err != nil { @@ -953,7 +953,7 @@ func (u *unconfirmedStore) ReadFrom(r io.Reader) (int64, error) { // Read transaction record hash and check that it was previously // read into the txs map. Use full record as the map value. - var txHash btcwire.ShaHash + var txHash wire.ShaHash n, err = io.ReadFull(r, txHash[:]) n64 += int64(n) if err != nil { @@ -987,7 +987,7 @@ func (u *unconfirmedStore) ReadFrom(r io.Reader) (int64, error) { spentUnconfirmedCount := byteOrder.Uint32(uint32Bytes) for i := uint32(0); i < spentUnconfirmedCount; i++ { // Read outpoint hash and index (uint32). - op := btcwire.OutPoint{} + op := wire.OutPoint{} n, err := io.ReadFull(r, op.Hash[:]) n64 += int64(n) if err != nil { @@ -1008,7 +1008,7 @@ func (u *unconfirmedStore) ReadFrom(r io.Reader) (int64, error) { // Read transaction record hash and check that it was previously // read into the txs map. Use full record as the map value. - var txHash btcwire.ShaHash + var txHash wire.ShaHash n, err = io.ReadFull(r, txHash[:]) n64 += int64(n) if err != nil { diff --git a/txstore/tx.go b/txstore/tx.go index 0e2536c..105aefc 100644 --- a/txstore/tx.go +++ b/txstore/tx.go @@ -26,9 +26,9 @@ import ( "github.com/btcsuite/btcd/blockchain" "github.com/btcsuite/btcd/txscript" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" - "github.com/btcsuite/btcwire" ) var ( @@ -128,7 +128,7 @@ type TxRecord struct { // Block holds details about a block that contains wallet transactions. type Block struct { - Hash btcwire.ShaHash + Hash wire.ShaHash Time time.Time Height int32 } @@ -172,7 +172,7 @@ type Store struct { blocks []*blockTxCollection blockIndexes map[int32]uint32 - unspent map[btcwire.OutPoint]BlockTxKey + unspent map[wire.OutPoint]BlockTxKey // unconfirmed holds a collection of wallet transactions that have not // been mined into a block yet. @@ -211,23 +211,23 @@ type blockTxCollection struct { type unconfirmedStore struct { // txs contains all unconfirmed transactions, mapping from their // transaction hash to the records. - txs map[btcwire.ShaHash]*txRecord + txs map[wire.ShaHash]*txRecord // spentBlockOutPoints maps from spent outputs from mined transaction // to the unconfirmed transaction which spends it. An additional // map is included to lookup the output key by its outpoint. spentBlockOutPoints map[BlockOutputKey]*txRecord - spentBlockOutPointKeys map[btcwire.OutPoint]BlockOutputKey + spentBlockOutPointKeys map[wire.OutPoint]BlockOutputKey // spentUnconfirmed maps from an unconfirmed outpoint to the unconfirmed // transaction which spends it. - spentUnconfirmed map[btcwire.OutPoint]*txRecord + spentUnconfirmed map[wire.OutPoint]*txRecord // previousOutpoints maps all previous outputs to the transaction record // of the unconfirmed transaction which spends it. This is primarly // designed to assist with double spend detection without iterating // through each value of the txs map. - previousOutpoints map[btcwire.OutPoint]*txRecord + previousOutpoints map[wire.OutPoint]*txRecord } // BlockTxKey is a lookup key for a single mined transaction in the store. @@ -280,13 +280,13 @@ func New(dir string) *Store { dir: dir, file: filename, blockIndexes: map[int32]uint32{}, - unspent: map[btcwire.OutPoint]BlockTxKey{}, + unspent: map[wire.OutPoint]BlockTxKey{}, unconfirmed: unconfirmedStore{ - txs: map[btcwire.ShaHash]*txRecord{}, + txs: map[wire.ShaHash]*txRecord{}, spentBlockOutPoints: map[BlockOutputKey]*txRecord{}, - spentBlockOutPointKeys: map[btcwire.OutPoint]BlockOutputKey{}, - spentUnconfirmed: map[btcwire.OutPoint]*txRecord{}, - previousOutpoints: map[btcwire.OutPoint]*txRecord{}, + spentBlockOutPointKeys: map[wire.OutPoint]BlockOutputKey{}, + spentUnconfirmed: map[wire.OutPoint]*txRecord{}, + previousOutpoints: map[wire.OutPoint]*txRecord{}, }, notificationLock: new(sync.Mutex), } @@ -482,7 +482,7 @@ func (s *Store) moveMinedTx(r *txRecord, block *Block) error { // If the credit is not spent, modify the store's unspent bookkeeping // maps to include the credit and increment the amount deltas by the // credit's value. - op := btcwire.OutPoint{Hash: *r.Tx().Sha()} + op := wire.OutPoint{Hash: *r.Tx().Sha()} for i, credit := range r.credits { if credit == nil { continue @@ -666,7 +666,7 @@ func (s *Store) findPreviousCredits(tx *btcutil.Tx) ([]Credit, error) { creditChans := make([]chan createdCredit, len(inputs)) for i, txIn := range inputs { creditChans[i] = make(chan createdCredit, 1) - go func(i int, op btcwire.OutPoint) { + go func(i int, op wire.OutPoint) { key, ok := s.unspent[op] if !ok { // Does this input spend an unconfirmed output? @@ -812,7 +812,7 @@ func (t *TxRecord) AddCredit(index uint32, change bool) (Credit, error) { } // New outputs are added unspent. - op := btcwire.OutPoint{Hash: *t.tx.Sha(), Index: index} + op := wire.OutPoint{Hash: *t.tx.Sha(), Index: index} t.s.unspent[op] = t.BlockTxKey switch t.tx.Index() { case 0: // Coinbase @@ -875,7 +875,7 @@ func (s *Store) Rollback(height int32) error { continue } - op := btcwire.OutPoint{ + op := wire.OutPoint{ Hash: *r.Tx().Sha(), Index: uint32(outIdx), } @@ -943,7 +943,7 @@ func (s *Store) Rollback(height int32) error { if err != nil { return err } - op := btcwire.OutPoint{ + op := wire.OutPoint{ Hash: *rr.Tx().Sha(), Index: prev.OutputIndex, } @@ -1025,7 +1025,7 @@ func (s *Store) removeConflict(r *txRecord) error { if credit == nil || credit.spentBy == nil { continue } - op := btcwire.NewOutPoint(r.Tx().Sha(), uint32(i)) + op := wire.NewOutPoint(r.Tx().Sha(), uint32(i)) nextSpender, ok := u.spentUnconfirmed[*op] if !ok { return ErrInconsistentStore @@ -1484,15 +1484,15 @@ func (c Credit) amount() btcutil.Amount { // OutPoint returns the outpoint needed to include in a transaction input // to spend this output. -func (c Credit) OutPoint() *btcwire.OutPoint { +func (c Credit) OutPoint() *wire.OutPoint { c.s.mtx.RLock() defer c.s.mtx.RUnlock() return c.outPoint() } -func (c Credit) outPoint() *btcwire.OutPoint { - return btcwire.NewOutPoint(c.Tx().Sha(), c.OutputIndex) +func (c Credit) outPoint() *wire.OutPoint { + return wire.NewOutPoint(c.Tx().Sha(), c.OutputIndex) } // outputKey creates and returns the block lookup key for this credit. @@ -1512,7 +1512,7 @@ func (c Credit) Spent() bool { } // TxOut returns the transaction output which this credit references. -func (c Credit) TxOut() *btcwire.TxOut { +func (c Credit) TxOut() *wire.TxOut { c.s.mtx.RLock() defer c.s.mtx.RUnlock() diff --git a/txstore/tx_test.go b/txstore/tx_test.go index a5e18d7..4ae7e44 100644 --- a/txstore/tx_test.go +++ b/txstore/tx_test.go @@ -20,10 +20,10 @@ import ( "testing" "time" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" . "github.com/btcsuite/btcwallet/txstore" - "github.com/btcsuite/btcwire" ) // Received transaction output for mainnet outpoint @@ -31,7 +31,7 @@ import ( var ( TstRecvSerializedTx, _ = hex.DecodeString("010000000114d9ff358894c486b4ae11c2a8cf7851b1df64c53d2e511278eff17c22fb7373000000008c493046022100995447baec31ee9f6d4ec0e05cb2a44f6b817a99d5f6de167d1c75354a946410022100c9ffc23b64d770b0e01e7ff4d25fbc2f1ca8091053078a247905c39fce3760b601410458b8e267add3c1e374cf40f1de02b59213a82e1d84c2b94096e22e2f09387009c96debe1d0bcb2356ffdcf65d2a83d4b34e72c62eccd8490dbf2110167783b2bffffffff0280969800000000001976a914479ed307831d0ac19ebc5f63de7d5f1a430ddb9d88ac38bfaa00000000001976a914dadf9e3484f28b385ddeaa6c575c0c0d18e9788a88ac00000000") TstRecvTx, _ = btcutil.NewTxFromBytes(TstRecvSerializedTx) - TstRecvTxSpendingTxBlockHash, _ = btcwire.NewShaHashFromStr("00000000000000017188b968a371bab95aa43522665353b646e41865abae02a4") + TstRecvTxSpendingTxBlockHash, _ = wire.NewShaHashFromStr("00000000000000017188b968a371bab95aa43522665353b646e41865abae02a4") TstRecvAmt = int64(10000000) TstRecvIndex = 684 TstRecvTxBlockDetails = &Block{ @@ -46,7 +46,7 @@ var ( TstSpendingSerializedTx, _ = hex.DecodeString("0100000003ad3fba7ebd67c09baa9538898e10d6726dcb8eadb006be0c7388c8e46d69d361000000006b4830450220702c4fbde5532575fed44f8d6e8c3432a2a9bd8cff2f966c3a79b2245a7c88db02210095d6505a57e350720cb52b89a9b56243c15ddfcea0596aedc1ba55d9fb7d5aa0012103cccb5c48a699d3efcca6dae277fee6b82e0229ed754b742659c3acdfed2651f9ffffffffdbd36173f5610e34de5c00ed092174603761595d90190f790e79cda3e5b45bc2010000006b483045022000fa20735e5875e64d05bed43d81b867f3bd8745008d3ff4331ef1617eac7c44022100ad82261fc57faac67fc482a37b6bf18158da0971e300abf5fe2f9fd39e107f58012102d4e1caf3e022757512c204bf09ff56a9981df483aba3c74bb60d3612077c9206ffffffff65536c9d964b6f89b8ef17e83c6666641bc495cb27bab60052f76cd4556ccd0d040000006a473044022068e3886e0299ffa69a1c3ee40f8b6700f5f6d463a9cf9dbf22c055a131fc4abc02202b58957fe19ff1be7a84c458d08016c53fbddec7184ac5e633f2b282ae3420ae012103b4e411b81d32a69fb81178a8ea1abaa12f613336923ee920ffbb1b313af1f4d2ffffffff02ab233200000000001976a91418808b2fbd8d2c6d022aed5cd61f0ce6c0a4cbb688ac4741f011000000001976a914f081088a300c80ce36b717a9914ab5ec8a7d283988ac00000000") TstSpendingTx, _ = btcutil.NewTxFromBytes(TstSpendingSerializedTx) TstSpendingTxBlockHeight = int32(279143) - TstSignedTxBlockHash, _ = btcwire.NewShaHashFromStr("00000000000000017188b968a371bab95aa43522665353b646e41865abae02a4") + TstSignedTxBlockHash, _ = wire.NewShaHashFromStr("00000000000000017188b968a371bab95aa43522665353b646e41865abae02a4") TstSignedTxIndex = 123 TstSignedTxBlockDetails = &Block{ Height: TstSpendingTxBlockHeight, @@ -68,11 +68,11 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) { // Create a "signed" (with invalid sigs) tx that spends output 0 of // the double spend. - spendingTx := btcwire.NewMsgTx() - spendingTxIn := btcwire.NewTxIn(btcwire.NewOutPoint(TstDoubleSpendTx.Sha(), 0), []byte{0, 1, 2, 3, 4}) + spendingTx := wire.NewMsgTx() + spendingTxIn := wire.NewTxIn(wire.NewOutPoint(TstDoubleSpendTx.Sha(), 0), []byte{0, 1, 2, 3, 4}) spendingTx.AddTxIn(spendingTxIn) - spendingTxOut1 := btcwire.NewTxOut(1e7, []byte{5, 6, 7, 8, 9}) - spendingTxOut2 := btcwire.NewTxOut(9e7, []byte{10, 11, 12, 13, 14}) + spendingTxOut1 := wire.NewTxOut(1e7, []byte{5, 6, 7, 8, 9}) + spendingTxOut2 := wire.NewTxOut(9e7, []byte{10, 11, 12, 13, 14}) spendingTx.AddTxOut(spendingTxOut1) spendingTx.AddTxOut(spendingTxOut2) TstSpendingTx := btcutil.NewTx(spendingTx) @@ -82,8 +82,8 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) { name string f func(*Store) (*Store, error) bal, unc btcutil.Amount - unspents map[btcwire.OutPoint]struct{} - unmined map[btcwire.ShaHash]struct{} + unspents map[wire.OutPoint]struct{} + unmined map[wire.ShaHash]struct{} }{ { name: "new store", @@ -92,8 +92,8 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) { }, bal: 0, unc: 0, - unspents: map[btcwire.OutPoint]struct{}{}, - unmined: map[btcwire.ShaHash]struct{}{}, + unspents: map[wire.OutPoint]struct{}{}, + unmined: map[wire.ShaHash]struct{}{}, }, { name: "txout insert", @@ -117,10 +117,10 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) { }, bal: 0, unc: btcutil.Amount(TstRecvTx.MsgTx().TxOut[0].Value), - unspents: map[btcwire.OutPoint]struct{}{ - *btcwire.NewOutPoint(TstRecvTx.Sha(), 0): {}, + unspents: map[wire.OutPoint]struct{}{ + *wire.NewOutPoint(TstRecvTx.Sha(), 0): {}, }, - unmined: map[btcwire.ShaHash]struct{}{}, + unmined: map[wire.ShaHash]struct{}{}, }, { name: "insert duplicate unconfirmed", @@ -143,10 +143,10 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) { }, bal: 0, unc: btcutil.Amount(TstRecvTx.MsgTx().TxOut[0].Value), - unspents: map[btcwire.OutPoint]struct{}{ - *btcwire.NewOutPoint(TstRecvTx.Sha(), 0): {}, + unspents: map[wire.OutPoint]struct{}{ + *wire.NewOutPoint(TstRecvTx.Sha(), 0): {}, }, - unmined: map[btcwire.ShaHash]struct{}{}, + unmined: map[wire.ShaHash]struct{}{}, }, { name: "confirmed txout insert", @@ -170,10 +170,10 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) { }, bal: btcutil.Amount(TstRecvTx.MsgTx().TxOut[0].Value), unc: 0, - unspents: map[btcwire.OutPoint]struct{}{ - *btcwire.NewOutPoint(TstRecvTx.Sha(), 0): {}, + unspents: map[wire.OutPoint]struct{}{ + *wire.NewOutPoint(TstRecvTx.Sha(), 0): {}, }, - unmined: map[btcwire.ShaHash]struct{}{}, + unmined: map[wire.ShaHash]struct{}{}, }, { name: "insert duplicate confirmed", @@ -197,10 +197,10 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) { }, bal: btcutil.Amount(TstRecvTx.MsgTx().TxOut[0].Value), unc: 0, - unspents: map[btcwire.OutPoint]struct{}{ - *btcwire.NewOutPoint(TstRecvTx.Sha(), 0): {}, + unspents: map[wire.OutPoint]struct{}{ + *wire.NewOutPoint(TstRecvTx.Sha(), 0): {}, }, - unmined: map[btcwire.ShaHash]struct{}{}, + unmined: map[wire.ShaHash]struct{}{}, }, { name: "rollback confirmed credit", @@ -213,10 +213,10 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) { }, bal: 0, unc: btcutil.Amount(TstRecvTx.MsgTx().TxOut[0].Value), - unspents: map[btcwire.OutPoint]struct{}{ - *btcwire.NewOutPoint(TstRecvTx.Sha(), 0): {}, + unspents: map[wire.OutPoint]struct{}{ + *wire.NewOutPoint(TstRecvTx.Sha(), 0): {}, }, - unmined: map[btcwire.ShaHash]struct{}{}, + unmined: map[wire.ShaHash]struct{}{}, }, { name: "insert confirmed double spend", @@ -241,10 +241,10 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) { }, bal: btcutil.Amount(TstDoubleSpendTx.MsgTx().TxOut[0].Value), unc: 0, - unspents: map[btcwire.OutPoint]struct{}{ - *btcwire.NewOutPoint(TstDoubleSpendTx.Sha(), 0): {}, + unspents: map[wire.OutPoint]struct{}{ + *wire.NewOutPoint(TstDoubleSpendTx.Sha(), 0): {}, }, - unmined: map[btcwire.ShaHash]struct{}{}, + unmined: map[wire.ShaHash]struct{}{}, }, { name: "insert unconfirmed debit", @@ -272,8 +272,8 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) { }, bal: 0, unc: 0, - unspents: map[btcwire.OutPoint]struct{}{}, - unmined: map[btcwire.ShaHash]struct{}{ + unspents: map[wire.OutPoint]struct{}{}, + unmined: map[wire.ShaHash]struct{}{ *TstSpendingTx.Sha(): {}, }, }, @@ -303,8 +303,8 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) { }, bal: 0, unc: 0, - unspents: map[btcwire.OutPoint]struct{}{}, - unmined: map[btcwire.ShaHash]struct{}{ + unspents: map[wire.OutPoint]struct{}{}, + unmined: map[wire.ShaHash]struct{}{ *TstSpendingTx.Sha(): {}, }, }, @@ -329,10 +329,10 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) { }, bal: 0, unc: btcutil.Amount(TstSpendingTx.MsgTx().TxOut[0].Value), - unspents: map[btcwire.OutPoint]struct{}{ - *btcwire.NewOutPoint(TstSpendingTx.Sha(), 0): {}, + unspents: map[wire.OutPoint]struct{}{ + *wire.NewOutPoint(TstSpendingTx.Sha(), 0): {}, }, - unmined: map[btcwire.ShaHash]struct{}{ + unmined: map[wire.ShaHash]struct{}{ *TstSpendingTx.Sha(): {}, }, }, @@ -357,11 +357,11 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) { }, bal: 0, unc: btcutil.Amount(TstSpendingTx.MsgTx().TxOut[0].Value + TstSpendingTx.MsgTx().TxOut[1].Value), - unspents: map[btcwire.OutPoint]struct{}{ - *btcwire.NewOutPoint(TstSpendingTx.Sha(), 0): {}, - *btcwire.NewOutPoint(TstSpendingTx.Sha(), 1): {}, + unspents: map[wire.OutPoint]struct{}{ + *wire.NewOutPoint(TstSpendingTx.Sha(), 0): {}, + *wire.NewOutPoint(TstSpendingTx.Sha(), 1): {}, }, - unmined: map[btcwire.ShaHash]struct{}{ + unmined: map[wire.ShaHash]struct{}{ *TstSpendingTx.Sha(): {}, }, }, @@ -382,11 +382,11 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) { }, bal: btcutil.Amount(TstSpendingTx.MsgTx().TxOut[0].Value + TstSpendingTx.MsgTx().TxOut[1].Value), unc: 0, - unspents: map[btcwire.OutPoint]struct{}{ - *btcwire.NewOutPoint(TstSpendingTx.Sha(), 0): {}, - *btcwire.NewOutPoint(TstSpendingTx.Sha(), 1): {}, + unspents: map[wire.OutPoint]struct{}{ + *wire.NewOutPoint(TstSpendingTx.Sha(), 0): {}, + *wire.NewOutPoint(TstSpendingTx.Sha(), 1): {}, }, - unmined: map[btcwire.ShaHash]struct{}{}, + unmined: map[wire.ShaHash]struct{}{}, }, { name: "rollback after spending tx", @@ -399,11 +399,11 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) { }, bal: btcutil.Amount(TstSpendingTx.MsgTx().TxOut[0].Value + TstSpendingTx.MsgTx().TxOut[1].Value), unc: 0, - unspents: map[btcwire.OutPoint]struct{}{ - *btcwire.NewOutPoint(TstSpendingTx.Sha(), 0): {}, - *btcwire.NewOutPoint(TstSpendingTx.Sha(), 1): {}, + unspents: map[wire.OutPoint]struct{}{ + *wire.NewOutPoint(TstSpendingTx.Sha(), 0): {}, + *wire.NewOutPoint(TstSpendingTx.Sha(), 1): {}, }, - unmined: map[btcwire.ShaHash]struct{}{}, + unmined: map[wire.ShaHash]struct{}{}, }, { name: "rollback spending tx block", @@ -416,11 +416,11 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) { }, bal: 0, unc: btcutil.Amount(TstSpendingTx.MsgTx().TxOut[0].Value + TstSpendingTx.MsgTx().TxOut[1].Value), - unspents: map[btcwire.OutPoint]struct{}{ - *btcwire.NewOutPoint(TstSpendingTx.Sha(), 0): {}, - *btcwire.NewOutPoint(TstSpendingTx.Sha(), 1): {}, + unspents: map[wire.OutPoint]struct{}{ + *wire.NewOutPoint(TstSpendingTx.Sha(), 0): {}, + *wire.NewOutPoint(TstSpendingTx.Sha(), 1): {}, }, - unmined: map[btcwire.ShaHash]struct{}{ + unmined: map[wire.ShaHash]struct{}{ *TstSpendingTx.Sha(): {}, }, }, @@ -435,11 +435,11 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) { }, bal: 0, unc: btcutil.Amount(TstSpendingTx.MsgTx().TxOut[0].Value + TstSpendingTx.MsgTx().TxOut[1].Value), - unspents: map[btcwire.OutPoint]struct{}{ - *btcwire.NewOutPoint(TstSpendingTx.Sha(), 0): {}, - *btcwire.NewOutPoint(TstSpendingTx.Sha(), 1): {}, + unspents: map[wire.OutPoint]struct{}{ + *wire.NewOutPoint(TstSpendingTx.Sha(), 0): {}, + *wire.NewOutPoint(TstSpendingTx.Sha(), 1): {}, }, - unmined: map[btcwire.ShaHash]struct{}{ + unmined: map[wire.ShaHash]struct{}{ *TstSpendingTx.Sha(): {}, }, }, @@ -465,10 +465,10 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) { }, bal: btcutil.Amount(TstRecvTx.MsgTx().TxOut[0].Value), unc: 0, - unspents: map[btcwire.OutPoint]struct{}{ - *btcwire.NewOutPoint(TstRecvTx.Sha(), 0): {}, + unspents: map[wire.OutPoint]struct{}{ + *wire.NewOutPoint(TstRecvTx.Sha(), 0): {}, }, - unmined: map[btcwire.ShaHash]struct{}{}, + unmined: map[wire.ShaHash]struct{}{}, }, } @@ -586,7 +586,7 @@ func TestFindingSpentCredits(t *testing.T) { if err != nil { t.Fatal(err) } - op := btcwire.NewOutPoint(TstSpendingTx.Sha(), 0) + op := wire.NewOutPoint(TstSpendingTx.Sha(), 0) if *unspents[0].OutPoint() != *op { t.Fatal("unspent outpoint doesn't match expected") } diff --git a/waddrmgr/db.go b/waddrmgr/db.go index 506c813..185fb78 100644 --- a/waddrmgr/db.go +++ b/waddrmgr/db.go @@ -22,8 +22,8 @@ import ( "fmt" "time" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcwallet/walletdb" - "github.com/btcsuite/btcwire" "github.com/btcsuite/fastsha256" ) @@ -1116,7 +1116,7 @@ func putStartBlock(tx walletdb.Tx, bs *BlockStamp) error { // fetchRecentBlocks returns the height of the most recent block height and // hashes of the most recent blocks. -func fetchRecentBlocks(tx walletdb.Tx) (int32, []btcwire.ShaHash, error) { +func fetchRecentBlocks(tx walletdb.Tx) (int32, []wire.ShaHash, error) { bucket := tx.RootBucket().Bucket(syncBucketName) // The serialized recent blocks format is: @@ -1135,7 +1135,7 @@ func fetchRecentBlocks(tx walletdb.Tx) (int32, []btcwire.ShaHash, error) { recentHeight := int32(binary.LittleEndian.Uint32(buf[0:4])) numHashes := binary.LittleEndian.Uint32(buf[4:8]) - recentHashes := make([]btcwire.ShaHash, numHashes) + recentHashes := make([]wire.ShaHash, numHashes) offset := 8 for i := uint32(0); i < numHashes; i++ { copy(recentHashes[i][:], buf[offset:offset+32]) @@ -1146,7 +1146,7 @@ func fetchRecentBlocks(tx walletdb.Tx) (int32, []btcwire.ShaHash, error) { } // putRecentBlocks stores the provided start block stamp to the database. -func putRecentBlocks(tx walletdb.Tx, recentHeight int32, recentHashes []btcwire.ShaHash) error { +func putRecentBlocks(tx walletdb.Tx, recentHeight int32, recentHashes []wire.ShaHash) error { bucket := tx.RootBucket().Bucket(syncBucketName) // The serialized recent blocks format is: diff --git a/waddrmgr/manager.go b/waddrmgr/manager.go index 007da0c..f2d3668 100644 --- a/waddrmgr/manager.go +++ b/waddrmgr/manager.go @@ -22,13 +22,13 @@ import ( "fmt" "sync" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcec" "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil/hdkeychain" "github.com/btcsuite/btcwallet/snacl" "github.com/btcsuite/btcwallet/walletdb" - "github.com/btcsuite/btcwire" ) const ( @@ -1724,7 +1724,7 @@ func loadManager(namespace walletdb.Namespace, pubPassphrase []byte, net *btcnet var cryptoKeyPubEnc, cryptoKeyPrivEnc, cryptoKeyScriptEnc []byte var syncedTo, startBlock *BlockStamp var recentHeight int32 - var recentHashes []btcwire.ShaHash + var recentHashes []wire.ShaHash err := namespace.View(func(tx walletdb.Tx) error { // Load whether or not the manager is watching-only from the db. var err error @@ -2012,7 +2012,7 @@ func Create(namespace walletdb.Namespace, seed, pubPassphrase, privPassphrase [] createdAt := &BlockStamp{Hash: *net.GenesisHash, Height: 0} // Create the initial sync state. - recentHashes := []btcwire.ShaHash{createdAt.Hash} + recentHashes := []wire.ShaHash{createdAt.Hash} recentHeight := createdAt.Height syncInfo := newSyncState(createdAt, createdAt, recentHeight, recentHashes) diff --git a/waddrmgr/manager_test.go b/waddrmgr/manager_test.go index 95413ff..a4b55f3 100644 --- a/waddrmgr/manager_test.go +++ b/waddrmgr/manager_test.go @@ -23,19 +23,19 @@ import ( "reflect" "testing" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" "github.com/btcsuite/btcwallet/waddrmgr" "github.com/btcsuite/btcwallet/walletdb" - "github.com/btcsuite/btcwire" ) -// newShaHash converts the passed big-endian hex string into a btcwire.ShaHash. -// It only differs from the one available in btcwire in that it panics on an +// newShaHash converts the passed big-endian hex string into a wire.ShaHash. +// It only differs from the one available in wire in that it panics on an // error since it will only (and must only) be called with hard-coded, and // therefore known good, hashes. -func newShaHash(hexStr string) *btcwire.ShaHash { - sha, err := btcwire.NewShaHashFromStr(hexStr) +func newShaHash(hexStr string) *wire.ShaHash { + sha, err := wire.NewShaHashFromStr(hexStr) if err != nil { panic(err) } @@ -1207,7 +1207,7 @@ func testWatchingOnly(tc *testContext) bool { func testSync(tc *testContext) bool { tests := []struct { name string - hash *btcwire.ShaHash + hash *wire.ShaHash }{ { name: "Block 1", @@ -1328,7 +1328,7 @@ func testSync(tc *testContext) bool { iter := tc.manager.NewIterateRecentBlocks() for cont := iter != nil; cont; cont = iter.Prev() { wantHeight := int32(i) - int32(j) + 1 - var wantHash *btcwire.ShaHash + var wantHash *wire.ShaHash if wantHeight == 0 { wantHash = btcnet.MainNetParams.GenesisHash } else { diff --git a/waddrmgr/sync.go b/waddrmgr/sync.go index 71d65b7..5dc7981 100644 --- a/waddrmgr/sync.go +++ b/waddrmgr/sync.go @@ -19,8 +19,8 @@ package waddrmgr import ( "sync" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcwallet/walletdb" - "github.com/btcsuite/btcwire" ) const ( @@ -34,7 +34,7 @@ const ( // synced to. type BlockStamp struct { Height int32 - Hash btcwire.ShaHash + Hash wire.ShaHash } // syncState houses the sync state of the manager. It consists of the recently @@ -53,7 +53,7 @@ type syncState struct { recentHeight int32 // recentHashes is a list of the last several seen block hashes. - recentHashes []btcwire.ShaHash + recentHashes []wire.ShaHash } // iter returns a BlockIterator that can be used to iterate over the recently @@ -72,7 +72,7 @@ func (s *syncState) iter(mtx *sync.RWMutex) *BlockIterator { // newSyncState returns a new sync state with the provided parameters. func newSyncState(startBlock, syncedTo *BlockStamp, recentHeight int32, - recentHashes []btcwire.ShaHash) *syncState { + recentHashes []wire.ShaHash) *syncState { return &syncState{ startBlock: *startBlock, diff --git a/wallet.go b/wallet.go index 9700b31..ef3c679 100644 --- a/wallet.go +++ b/wallet.go @@ -27,13 +27,13 @@ import ( "time" "github.com/btcsuite/btcd/blockchain" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcjson" "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" "github.com/btcsuite/btcwallet/chain" "github.com/btcsuite/btcwallet/keystore" "github.com/btcsuite/btcwallet/txstore" - "github.com/btcsuite/btcwire" ) var ( @@ -54,7 +54,7 @@ func networkDir(net *btcnet.Params) string { // paramaters will likely be switched to being named "testnet3" in the // future. This is done to future proof that change, and an upgrade // plan to move the testnet3 data directory can be worked out later. - if net.Net == btcwire.TestNet3 { + if net.Net == wire.TestNet3 { netname = "testnet" } @@ -73,7 +73,7 @@ type Wallet struct { chainSvrLock sync.Locker chainSynced chan struct{} // closed when synced - lockedOutpoints map[btcwire.OutPoint]struct{} + lockedOutpoints map[wire.OutPoint]struct{} FeeIncrement btcutil.Amount // Channels for rescan processing. Requests are added and merged with @@ -117,7 +117,7 @@ func newWallet(keys *keystore.Store, txs *txstore.Store) *Wallet { TxStore: txs, chainSvrLock: new(sync.Mutex), chainSynced: make(chan struct{}), - lockedOutpoints: map[btcwire.OutPoint]struct{}{}, + lockedOutpoints: map[wire.OutPoint]struct{}{}, FeeIncrement: defaultFeeIncrement, rescanAddJob: make(chan *RescanJob), rescanBatch: make(chan *rescanBatch), @@ -1110,27 +1110,27 @@ func (w *Wallet) exportBase64() (map[string]string, error) { // LockedOutpoint returns whether an outpoint has been marked as locked and // should not be used as an input for created transactions. -func (w *Wallet) LockedOutpoint(op btcwire.OutPoint) bool { +func (w *Wallet) LockedOutpoint(op wire.OutPoint) bool { _, locked := w.lockedOutpoints[op] return locked } // LockOutpoint marks an outpoint as locked, that is, it should not be used as // an input for newly created transactions. -func (w *Wallet) LockOutpoint(op btcwire.OutPoint) { +func (w *Wallet) LockOutpoint(op wire.OutPoint) { w.lockedOutpoints[op] = struct{}{} } // UnlockOutpoint marks an outpoint as unlocked, that is, it may be used as an // input for newly created transactions. -func (w *Wallet) UnlockOutpoint(op btcwire.OutPoint) { +func (w *Wallet) UnlockOutpoint(op wire.OutPoint) { delete(w.lockedOutpoints, op) } // ResetLockedOutpoints resets the set of locked outpoints so all may be used // as inputs for new transactions. func (w *Wallet) ResetLockedOutpoints() { - w.lockedOutpoints = map[btcwire.OutPoint]struct{}{} + w.lockedOutpoints = map[wire.OutPoint]struct{}{} } // LockedOutpoints returns a slice of currently locked outpoints. This is @@ -1310,7 +1310,7 @@ func (w *Wallet) RecoverAddresses(n int) error { // ReqSpentUtxoNtfns sends a message to btcd to request updates for when // a stored UTXO has been spent. func (w *Wallet) ReqSpentUtxoNtfns(credits []txstore.Credit) { - ops := make([]*btcwire.OutPoint, len(credits)) + ops := make([]*wire.OutPoint, len(credits)) for i, c := range credits { op := c.OutPoint() log.Debugf("Requesting spent UTXO notifications for Outpoint "+ @@ -1387,7 +1387,7 @@ func (w *Wallet) TotalReceivedForAddr(addr btcutil.Address, confirms int) (btcut // TxRecord iterates through all transaction records saved in the store, // returning the first with an equivalent transaction hash. -func (w *Wallet) TxRecord(txSha *btcwire.ShaHash) (r *txstore.TxRecord, ok bool) { +func (w *Wallet) TxRecord(txSha *wire.ShaHash) (r *txstore.TxRecord, ok bool) { for _, r = range w.TxStore.Records() { if *r.Tx().Sha() == *txSha { return r, true