From 80b97479bd665104a01500ae00c694dd4c614fdf Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Thu, 5 Feb 2015 14:48:38 -0600 Subject: [PATCH] Update btcwire path import paths to new location. --- address_test.go | 4 +- block.go | 48 +++++++++++------------ block_test.go | 52 ++++++++++++------------- bloom/example_test.go | 6 +-- bloom/filter.go | 52 ++++++++++++------------- bloom/filter_test.go | 82 +++++++++++++++++++-------------------- bloom/merkleblock.go | 24 ++++++------ bloom/merkleblock_test.go | 8 ++-- coinset/coins.go | 22 +++++------ coinset/coins_test.go | 18 ++++----- hdkeychain/extendedkey.go | 6 +-- tx.go | 22 +++++------ tx_test.go | 4 +- wif.go | 6 +-- 14 files changed, 177 insertions(+), 177 deletions(-) diff --git a/address_test.go b/address_test.go index e84ff87..10460a0 100644 --- a/address_test.go +++ b/address_test.go @@ -13,13 +13,13 @@ import ( "golang.org/x/crypto/ripemd160" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" - "github.com/btcsuite/btcwire" ) // invalidNet is an invalid bitcoin network. -const invalidNet = btcwire.BitcoinNet(0xffffffff) +const invalidNet = wire.BitcoinNet(0xffffffff) func TestAddresses(t *testing.T) { tests := []struct { diff --git a/block.go b/block.go index 79aea17..cc7e9b7 100644 --- a/block.go +++ b/block.go @@ -9,7 +9,7 @@ import ( "fmt" "io" - "github.com/btcsuite/btcwire" + "github.com/btcsuite/btcd/wire" ) // OutOfRangeError describes an error due to accessing an element that is out @@ -31,22 +31,22 @@ func (e OutOfRangeError) Error() string { // transactions on their first access so subsequent accesses don't have to // repeat the relatively expensive hashing operations. type Block struct { - msgBlock *btcwire.MsgBlock // Underlying MsgBlock - serializedBlock []byte // Serialized bytes for the block - blockSha *btcwire.ShaHash // Cached block hash - blockHeight int64 // Height in the main block chain - transactions []*Tx // Transactions - txnsGenerated bool // ALL wrapped transactions generated + msgBlock *wire.MsgBlock // Underlying MsgBlock + serializedBlock []byte // Serialized bytes for the block + blockSha *wire.ShaHash // Cached block hash + blockHeight int64 // Height in the main block chain + transactions []*Tx // Transactions + txnsGenerated bool // ALL wrapped transactions generated } -// MsgBlock returns the underlying btcwire.MsgBlock for the Block. -func (b *Block) MsgBlock() *btcwire.MsgBlock { +// MsgBlock returns the underlying wire.MsgBlock for the Block. +func (b *Block) MsgBlock() *wire.MsgBlock { // Return the cached block. return b.msgBlock } // Bytes returns the serialized bytes for the Block. This is equivalent to -// calling Serialize on the underlying btcwire.MsgBlock, however it caches the +// calling Serialize on the underlying wire.MsgBlock, however it caches the // result so subsequent calls are more efficient. func (b *Block) Bytes() ([]byte, error) { // Return the cached serialized bytes if it has already been generated. @@ -68,9 +68,9 @@ func (b *Block) Bytes() ([]byte, error) { } // Sha returns the block identifier hash for the Block. This is equivalent to -// calling BlockSha on the underlying btcwire.MsgBlock, however it caches the +// calling BlockSha on the underlying wire.MsgBlock, however it caches the // result so subsequent calls are more efficient. -func (b *Block) Sha() (*btcwire.ShaHash, error) { +func (b *Block) Sha() (*wire.ShaHash, error) { // Return the cached block hash if it has already been generated. if b.blockSha != nil { return b.blockSha, nil @@ -88,8 +88,8 @@ func (b *Block) Sha() (*btcwire.ShaHash, error) { // Tx returns a wrapped transaction (btcutil.Tx) for the transaction at the // specified index in the Block. The supplied index is 0 based. That is to // say, the first transaction in the block is txNum 0. This is nearly -// equivalent to accessing the raw transaction (btcwire.MsgTx) from the -// underlying btcwire.MsgBlock, however the wrapped transaction has some helpful +// equivalent to accessing the raw transaction (wire.MsgTx) from the +// underlying wire.MsgBlock, however the wrapped transaction has some helpful // properties such as caching the hash so subsequent calls are more efficient. func (b *Block) Tx(txNum int) (*Tx, error) { // Ensure the requested transaction is in range. @@ -119,7 +119,7 @@ func (b *Block) Tx(txNum int) (*Tx, error) { // Transactions returns a slice of wrapped transactions (btcutil.Tx) for all // transactions in the Block. This is nearly equivalent to accessing the raw -// transactions (btcwire.MsgTx) in the underlying btcwire.MsgBlock, however it +// transactions (wire.MsgTx) in the underlying wire.MsgBlock, however it // instead provides easy access to wrapped versions (btcutil.Tx) of them. func (b *Block) Transactions() []*Tx { // Return transactions if they have ALL already been generated. This @@ -151,9 +151,9 @@ func (b *Block) Transactions() []*Tx { // TxSha returns the hash for the requested transaction number in the Block. // The supplied index is 0 based. That is to say, the first transaction in the // block is txNum 0. This is equivalent to calling TxSha on the underlying -// btcwire.MsgTx, however it caches the result so subsequent calls are more +// wire.MsgTx, however it caches the result so subsequent calls are more // efficient. -func (b *Block) TxSha(txNum int) (*btcwire.ShaHash, error) { +func (b *Block) TxSha(txNum int) (*wire.ShaHash, error) { // Attempt to get a wrapped transaction for the specified index. It // will be created lazily if needed or simply return the cached version // if it has already been generated. @@ -170,14 +170,14 @@ func (b *Block) TxSha(txNum int) (*btcwire.ShaHash, error) { // TxLoc returns the offsets and lengths of each transaction in a raw block. // It is used to allow fast indexing into transactions within the raw byte // stream. -func (b *Block) TxLoc() ([]btcwire.TxLoc, error) { +func (b *Block) TxLoc() ([]wire.TxLoc, error) { rawMsg, err := b.Bytes() if err != nil { return nil, err } rbuf := bytes.NewBuffer(rawMsg) - var mblock btcwire.MsgBlock + var mblock wire.MsgBlock txLocs, err := mblock.DeserializeTxLoc(rbuf) if err != nil { return nil, err @@ -197,8 +197,8 @@ func (b *Block) SetHeight(height int64) { } // NewBlock returns a new instance of a bitcoin block given an underlying -// btcwire.MsgBlock. See Block. -func NewBlock(msgBlock *btcwire.MsgBlock) *Block { +// wire.MsgBlock. See Block. +func NewBlock(msgBlock *wire.MsgBlock) *Block { return &Block{ msgBlock: msgBlock, blockHeight: BlockHeightUnknown, @@ -221,7 +221,7 @@ func NewBlockFromBytes(serializedBlock []byte) (*Block, error) { // Reader to deserialize the block. See Block. func NewBlockFromReader(r io.Reader) (*Block, error) { // Deserialize the bytes into a MsgBlock. - var msgBlock btcwire.MsgBlock + var msgBlock wire.MsgBlock err := msgBlock.Deserialize(r) if err != nil { return nil, err @@ -235,8 +235,8 @@ func NewBlockFromReader(r io.Reader) (*Block, error) { } // NewBlockFromBlockAndBytes returns a new instance of a bitcoin block given -// an underlying btcwire.MsgBlock and the serialized bytes for it. See Block. -func NewBlockFromBlockAndBytes(msgBlock *btcwire.MsgBlock, serializedBlock []byte) *Block { +// an underlying wire.MsgBlock and the serialized bytes for it. See Block. +func NewBlockFromBlockAndBytes(msgBlock *wire.MsgBlock, serializedBlock []byte) *Block { return &Block{ msgBlock: msgBlock, serializedBlock: serializedBlock, diff --git a/block_test.go b/block_test.go index 4469f7d..b950eef 100644 --- a/block_test.go +++ b/block_test.go @@ -11,8 +11,8 @@ import ( "testing" "time" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" - "github.com/btcsuite/btcwire" "github.com/davecgh/go-spew/spew" ) @@ -36,7 +36,7 @@ func TestBlock(t *testing.T) { // Hash for block 100,000. wantShaStr := "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506" - wantSha, err := btcwire.NewShaHashFromStr(wantShaStr) + wantSha, err := wire.NewShaHashFromStr(wantShaStr) if err != nil { t.Errorf("NewShaHashFromStr: %v", err) } @@ -67,7 +67,7 @@ func TestBlock(t *testing.T) { // Request sha for all transactions one at a time via Tx. for i, txSha := range wantTxShas { - wantSha, err := btcwire.NewShaHashFromStr(txSha) + wantSha, err := wire.NewShaHashFromStr(txSha) if err != nil { t.Errorf("NewShaHashFromStr: %v", err) } @@ -107,7 +107,7 @@ func TestBlock(t *testing.T) { // Ensure all of the shas match. for j, tx := range transactions { - wantSha, err := btcwire.NewShaHashFromStr(wantTxShas[j]) + wantSha, err := wire.NewShaHashFromStr(wantTxShas[j]) if err != nil { t.Errorf("NewShaHashFromStr: %v", err) } @@ -146,7 +146,7 @@ func TestBlock(t *testing.T) { } // Transaction offsets and length for the transaction in Block100000. - wantTxLocs := []btcwire.TxLoc{ + wantTxLocs := []wire.TxLoc{ {TxStart: 81, TxLen: 135}, {TxStart: 216, TxLen: 259}, {TxStart: 475, TxLen: 257}, @@ -303,16 +303,16 @@ func TestBlockErrors(t *testing.T) { // Block100000 defines block 100,000 of the block chain. It is used to // test Block operations. -var Block100000 = btcwire.MsgBlock{ - Header: btcwire.BlockHeader{ +var Block100000 = wire.MsgBlock{ + Header: wire.BlockHeader{ Version: 1, - PrevBlock: btcwire.ShaHash([32]byte{ // Make go vet happy. + PrevBlock: wire.ShaHash([32]byte{ // Make go vet happy. 0x50, 0x12, 0x01, 0x19, 0x17, 0x2a, 0x61, 0x04, 0x21, 0xa6, 0xc3, 0x01, 0x1d, 0xd3, 0x30, 0xd9, 0xdf, 0x07, 0xb6, 0x36, 0x16, 0xc2, 0xcc, 0x1f, 0x1c, 0xd0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, }), // 000000000002d01c1fccc21636b607dfd930d31d01c3a62104612a1719011250 - MerkleRoot: btcwire.ShaHash([32]byte{ // Make go vet happy. + MerkleRoot: wire.ShaHash([32]byte{ // Make go vet happy. 0x66, 0x57, 0xa9, 0x25, 0x2a, 0xac, 0xd5, 0xc0, 0xb2, 0x94, 0x09, 0x96, 0xec, 0xff, 0x95, 0x22, 0x28, 0xc3, 0x06, 0x7c, 0xc3, 0x8d, 0x48, 0x85, @@ -322,13 +322,13 @@ var Block100000 = btcwire.MsgBlock{ Bits: 0x1b04864c, // 453281356 Nonce: 0x10572b0f, // 274148111 }, - Transactions: []*btcwire.MsgTx{ + Transactions: []*wire.MsgTx{ { Version: 1, - TxIn: []*btcwire.TxIn{ + TxIn: []*wire.TxIn{ { - PreviousOutPoint: btcwire.OutPoint{ - Hash: btcwire.ShaHash{}, + PreviousOutPoint: wire.OutPoint{ + Hash: wire.ShaHash{}, Index: 0xffffffff, }, SignatureScript: []byte{ @@ -337,7 +337,7 @@ var Block100000 = btcwire.MsgBlock{ Sequence: 0xffffffff, }, }, - TxOut: []*btcwire.TxOut{ + TxOut: []*wire.TxOut{ { Value: 0x12a05f200, // 5000000000 PkScript: []byte{ @@ -359,10 +359,10 @@ var Block100000 = btcwire.MsgBlock{ }, { Version: 1, - TxIn: []*btcwire.TxIn{ + TxIn: []*wire.TxIn{ { - PreviousOutPoint: btcwire.OutPoint{ - Hash: btcwire.ShaHash([32]byte{ // Make go vet happy. + PreviousOutPoint: wire.OutPoint{ + Hash: wire.ShaHash([32]byte{ // Make go vet happy. 0x03, 0x2e, 0x38, 0xe9, 0xc0, 0xa8, 0x4c, 0x60, 0x46, 0xd6, 0x87, 0xd1, 0x05, 0x56, 0xdc, 0xac, 0xc4, 0x1d, 0x27, 0x5e, 0xc5, 0x5f, 0xc0, 0x07, @@ -396,7 +396,7 @@ var Block100000 = btcwire.MsgBlock{ Sequence: 0xffffffff, }, }, - TxOut: []*btcwire.TxOut{ + TxOut: []*wire.TxOut{ { Value: 0x2123e300, // 556000000 PkScript: []byte{ @@ -428,10 +428,10 @@ var Block100000 = btcwire.MsgBlock{ }, { Version: 1, - TxIn: []*btcwire.TxIn{ + TxIn: []*wire.TxIn{ { - PreviousOutPoint: btcwire.OutPoint{ - Hash: btcwire.ShaHash([32]byte{ // Make go vet happy. + PreviousOutPoint: wire.OutPoint{ + Hash: wire.ShaHash([32]byte{ // Make go vet happy. 0xc3, 0x3e, 0xbf, 0xf2, 0xa7, 0x09, 0xf1, 0x3d, 0x9f, 0x9a, 0x75, 0x69, 0xab, 0x16, 0xa3, 0x27, 0x86, 0xaf, 0x7d, 0x7e, 0x2d, 0xe0, 0x92, 0x65, @@ -464,7 +464,7 @@ var Block100000 = btcwire.MsgBlock{ Sequence: 0xffffffff, }, }, - TxOut: []*btcwire.TxOut{ + TxOut: []*wire.TxOut{ { Value: 0xf4240, // 1000000 PkScript: []byte{ @@ -496,10 +496,10 @@ var Block100000 = btcwire.MsgBlock{ }, { Version: 1, - TxIn: []*btcwire.TxIn{ + TxIn: []*wire.TxIn{ { - PreviousOutPoint: btcwire.OutPoint{ - Hash: btcwire.ShaHash([32]byte{ // Make go vet happy. + PreviousOutPoint: wire.OutPoint{ + Hash: wire.ShaHash([32]byte{ // Make go vet happy. 0x0b, 0x60, 0x72, 0xb3, 0x86, 0xd4, 0xa7, 0x73, 0x23, 0x52, 0x37, 0xf6, 0x4c, 0x11, 0x26, 0xac, 0x3b, 0x24, 0x0c, 0x84, 0xb9, 0x17, 0xa3, 0x90, @@ -533,7 +533,7 @@ var Block100000 = btcwire.MsgBlock{ Sequence: 0xffffffff, }, }, - TxOut: []*btcwire.TxOut{ + TxOut: []*wire.TxOut{ { Value: 0xf4240, // 1000000 PkScript: []byte{ diff --git a/bloom/example_test.go b/bloom/example_test.go index d44e0a9..a101da4 100644 --- a/bloom/example_test.go +++ b/bloom/example_test.go @@ -9,8 +9,8 @@ import ( "math/rand" "time" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil/bloom" - "github.com/btcsuite/btcwire" ) // This example demonstrates how to create a new bloom filter, add a transaction @@ -22,13 +22,13 @@ func ExampleNewFilter() { // Create a new bloom filter intended to hold 10 elements with a 0.01% // false positive rate and does not include any automatic update // functionality when transactions are matched. - filter := bloom.NewFilter(10, tweak, 0.0001, btcwire.BloomUpdateNone) + filter := bloom.NewFilter(10, tweak, 0.0001, wire.BloomUpdateNone) // Create a transaction hash and add it to the filter. This particular // trasaction is the first transaction in block 310,000 of the main // bitcoin block chain. txHashStr := "fd611c56ca0d378cdcd16244b45c2ba9588da3adac367c4ef43e808b280b8a45" - txHash, err := btcwire.NewShaHashFromStr(txHashStr) + txHash, err := wire.NewShaHashFromStr(txHashStr) if err != nil { fmt.Println(err) return diff --git a/bloom/filter.go b/bloom/filter.go index 45b50eb..d86caa3 100644 --- a/bloom/filter.go +++ b/bloom/filter.go @@ -10,8 +10,8 @@ import ( "sync" "github.com/btcsuite/btcd/txscript" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" - "github.com/btcsuite/btcwire" ) // ln2Squared is simply the square of the natural log of 2. @@ -30,7 +30,7 @@ func minUint32(a, b uint32) uint32 { // filter data. type Filter struct { mtx sync.Mutex - msgFilterLoad *btcwire.MsgFilterLoad + msgFilterLoad *wire.MsgFilterLoad } // NewFilter creates a new bloom filter instance, mainly to be used by SPV @@ -42,7 +42,7 @@ type Filter struct { // // For more information on what values to use for both elements and fprate, // see https://en.wikipedia.org/wiki/Bloom_filter. -func NewFilter(elements, tweak uint32, fprate float64, flags btcwire.BloomUpdateType) *Filter { +func NewFilter(elements, tweak uint32, fprate float64, flags wire.BloomUpdateType) *Filter { // Massage the false positive rate to sane values. if fprate > 1.0 { fprate = 1.0 @@ -57,7 +57,7 @@ func NewFilter(elements, tweak uint32, fprate float64, flags btcwire.BloomUpdate // Equivalent to m = -(n*ln(p) / ln(2)^2), where m is in bits. // Then clamp it to the maximum filter size and convert to bytes. dataLen := uint32(-1 * float64(elements) * math.Log(fprate) / ln2Squared) - dataLen = minUint32(dataLen, btcwire.MaxFilterLoadFilterSize*8) / 8 + dataLen = minUint32(dataLen, wire.MaxFilterLoadFilterSize*8) / 8 // Calculate the number of hash functions based on the size of the // filter calculated above and the number of elements. @@ -65,10 +65,10 @@ func NewFilter(elements, tweak uint32, fprate float64, flags btcwire.BloomUpdate // Equivalent to k = (m/n) * ln(2) // Then clamp it to the maximum allowed hash funcs. hashFuncs := uint32(float64(dataLen*8) / float64(elements) * math.Ln2) - hashFuncs = minUint32(hashFuncs, btcwire.MaxFilterLoadHashFuncs) + hashFuncs = minUint32(hashFuncs, wire.MaxFilterLoadHashFuncs) data := make([]byte, dataLen) - msg := btcwire.NewMsgFilterLoad(data, hashFuncs, tweak, flags) + msg := wire.NewMsgFilterLoad(data, hashFuncs, tweak, flags) return &Filter{ msgFilterLoad: msg, @@ -76,8 +76,8 @@ func NewFilter(elements, tweak uint32, fprate float64, flags btcwire.BloomUpdate } // LoadFilter creates a new Filter instance with the given underlying -// btcwire.MsgFilterLoad. -func LoadFilter(filter *btcwire.MsgFilterLoad) *Filter { +// wire.MsgFilterLoad. +func LoadFilter(filter *wire.MsgFilterLoad) *Filter { return &Filter{ msgFilterLoad: filter, } @@ -96,7 +96,7 @@ func (bf *Filter) IsLoaded() bool { // Reload loads a new filter replacing any existing filter. // // This function is safe for concurrent access. -func (bf *Filter) Reload(filter *btcwire.MsgFilterLoad) { +func (bf *Filter) Reload(filter *wire.MsgFilterLoad) { bf.mtx.Lock() bf.msgFilterLoad = filter bf.mtx.Unlock() @@ -164,11 +164,11 @@ func (bf *Filter) Matches(data []byte) bool { // outpoint and false if it definitely does not. // // This function MUST be called with the filter lock held. -func (bf *Filter) matchesOutPoint(outpoint *btcwire.OutPoint) bool { +func (bf *Filter) matchesOutPoint(outpoint *wire.OutPoint) bool { // Serialize - var buf [btcwire.HashSize + 4]byte + var buf [wire.HashSize + 4]byte copy(buf[:], outpoint.Hash.Bytes()) - binary.LittleEndian.PutUint32(buf[btcwire.HashSize:], outpoint.Index) + binary.LittleEndian.PutUint32(buf[wire.HashSize:], outpoint.Index) return bf.matches(buf[:]) } @@ -177,7 +177,7 @@ func (bf *Filter) matchesOutPoint(outpoint *btcwire.OutPoint) bool { // outpoint and false if it definitely does not. // // This function is safe for concurrent access. -func (bf *Filter) MatchesOutPoint(outpoint *btcwire.OutPoint) bool { +func (bf *Filter) MatchesOutPoint(outpoint *wire.OutPoint) bool { bf.mtx.Lock() match := bf.matchesOutPoint(outpoint) bf.mtx.Unlock() @@ -214,10 +214,10 @@ func (bf *Filter) Add(data []byte) { bf.mtx.Unlock() } -// AddShaHash adds the passed btcwire.ShaHash to the Filter. +// AddShaHash adds the passed wire.ShaHash to the Filter. // // This function is safe for concurrent access. -func (bf *Filter) AddShaHash(sha *btcwire.ShaHash) { +func (bf *Filter) AddShaHash(sha *wire.ShaHash) { bf.mtx.Lock() bf.add(sha.Bytes()) bf.mtx.Unlock() @@ -226,11 +226,11 @@ func (bf *Filter) AddShaHash(sha *btcwire.ShaHash) { // addOutPoint adds the passed transaction outpoint to the bloom filter. // // This function MUST be called with the filter lock held. -func (bf *Filter) addOutPoint(outpoint *btcwire.OutPoint) { +func (bf *Filter) addOutPoint(outpoint *wire.OutPoint) { // Serialize - var buf [btcwire.HashSize + 4]byte + var buf [wire.HashSize + 4]byte copy(buf[:], outpoint.Hash.Bytes()) - binary.LittleEndian.PutUint32(buf[btcwire.HashSize:], outpoint.Index) + binary.LittleEndian.PutUint32(buf[wire.HashSize:], outpoint.Index) bf.add(buf[:]) } @@ -238,7 +238,7 @@ func (bf *Filter) addOutPoint(outpoint *btcwire.OutPoint) { // AddOutPoint adds the passed transaction outpoint to the bloom filter. // // This function is safe for concurrent access. -func (bf *Filter) AddOutPoint(outpoint *btcwire.OutPoint) { +func (bf *Filter) AddOutPoint(outpoint *wire.OutPoint) { bf.mtx.Lock() bf.addOutPoint(outpoint) bf.mtx.Unlock() @@ -249,15 +249,15 @@ func (bf *Filter) AddOutPoint(outpoint *btcwire.OutPoint) { // script. // // This function MUST be called with the filter lock held. -func (bf *Filter) maybeAddOutpoint(pkScript []byte, outHash *btcwire.ShaHash, outIdx uint32) { +func (bf *Filter) maybeAddOutpoint(pkScript []byte, outHash *wire.ShaHash, outIdx uint32) { switch bf.msgFilterLoad.Flags { - case btcwire.BloomUpdateAll: - outpoint := btcwire.NewOutPoint(outHash, outIdx) + case wire.BloomUpdateAll: + outpoint := wire.NewOutPoint(outHash, outIdx) bf.addOutPoint(outpoint) - case btcwire.BloomUpdateP2PubkeyOnly: + case wire.BloomUpdateP2PubkeyOnly: class := txscript.GetScriptClass(pkScript) if class == txscript.PubKeyTy || class == txscript.MultiSigTy { - outpoint := btcwire.NewOutPoint(outHash, outIdx) + outpoint := wire.NewOutPoint(outHash, outIdx) bf.addOutPoint(outpoint) } } @@ -341,11 +341,11 @@ func (bf *Filter) MatchTxAndUpdate(tx *btcutil.Tx) bool { return match } -// MsgFilterLoad returns the underlying btcwire.MsgFilterLoad for the bloom +// MsgFilterLoad returns the underlying wire.MsgFilterLoad for the bloom // filter. // // This function is safe for concurrent access. -func (bf *Filter) MsgFilterLoad() *btcwire.MsgFilterLoad { +func (bf *Filter) MsgFilterLoad() *wire.MsgFilterLoad { bf.mtx.Lock() msg := bf.msgFilterLoad bf.mtx.Unlock() diff --git a/bloom/filter_test.go b/bloom/filter_test.go index 3da881b..3e4a9e5 100644 --- a/bloom/filter_test.go +++ b/bloom/filter_test.go @@ -9,23 +9,23 @@ import ( "encoding/hex" "testing" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil/bloom" - "github.com/btcsuite/btcwire" ) // TestFilterLarge ensures a maximum sized filter can be created. func TestFilterLarge(t *testing.T) { - f := bloom.NewFilter(100000000, 0, 0.01, btcwire.BloomUpdateNone) - if len(f.MsgFilterLoad().Filter) > btcwire.MaxFilterLoadFilterSize { + f := bloom.NewFilter(100000000, 0, 0.01, wire.BloomUpdateNone) + if len(f.MsgFilterLoad().Filter) > wire.MaxFilterLoadFilterSize { t.Errorf("TestFilterLarge test failed: %d > %d", - len(f.MsgFilterLoad().Filter), btcwire.MaxFilterLoadFilterSize) + len(f.MsgFilterLoad().Filter), wire.MaxFilterLoadFilterSize) } } // TestFilterLoad ensures loading and unloading of a filter pass. func TestFilterLoad(t *testing.T) { - merkle := btcwire.MsgFilterLoad{} + merkle := wire.MsgFilterLoad{} f := bloom.LoadFilter(&merkle) if !f.IsLoaded() { @@ -55,7 +55,7 @@ func TestFilterInsert(t *testing.T) { {"b9300670b4c5366e95b2699e8b18bc75e5f729c5", true}, } - f := bloom.NewFilter(3, 0, 0.01, btcwire.BloomUpdateAll) + f := bloom.NewFilter(3, 0, 0.01, wire.BloomUpdateAll) for i, test := range tests { data, err := hex.DecodeString(test.hex) @@ -82,7 +82,7 @@ func TestFilterInsert(t *testing.T) { } got := bytes.NewBuffer(nil) - err = f.MsgFilterLoad().BtcEncode(got, btcwire.ProtocolVersion) + err = f.MsgFilterLoad().BtcEncode(got, wire.ProtocolVersion) if err != nil { t.Errorf("TestFilterInsert BtcDecode failed: %v\n", err) return @@ -109,7 +109,7 @@ func TestFilterInsertWithTweak(t *testing.T) { {"b9300670b4c5366e95b2699e8b18bc75e5f729c5", true}, } - f := bloom.NewFilter(3, 2147483649, 0.01, btcwire.BloomUpdateAll) + f := bloom.NewFilter(3, 2147483649, 0.01, wire.BloomUpdateAll) for i, test := range tests { data, err := hex.DecodeString(test.hex) @@ -135,7 +135,7 @@ func TestFilterInsertWithTweak(t *testing.T) { return } got := bytes.NewBuffer(nil) - err = f.MsgFilterLoad().BtcEncode(got, btcwire.ProtocolVersion) + err = f.MsgFilterLoad().BtcEncode(got, wire.ProtocolVersion) if err != nil { t.Errorf("TestFilterInsertWithTweak BtcDecode failed: %v\n", err) return @@ -159,7 +159,7 @@ func TestFilterInsertKey(t *testing.T) { return } - f := bloom.NewFilter(2, 0, 0.001, btcwire.BloomUpdateAll) + f := bloom.NewFilter(2, 0, 0.001, wire.BloomUpdateAll) f.Add(wif.SerializePubKey()) f.Add(btcutil.Hash160(wif.SerializePubKey())) @@ -169,7 +169,7 @@ func TestFilterInsertKey(t *testing.T) { return } got := bytes.NewBuffer(nil) - err = f.MsgFilterLoad().BtcEncode(got, btcwire.ProtocolVersion) + err = f.MsgFilterLoad().BtcEncode(got, wire.ProtocolVersion) if err != nil { t.Errorf("TestFilterInsertWithTweak BtcDecode failed: %v\n", err) return @@ -238,9 +238,9 @@ func TestFilterBloomMatch(t *testing.T) { return } - f := bloom.NewFilter(10, 0, 0.000001, btcwire.BloomUpdateAll) + f := bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr := "b4749f017444b051c44dfd2720e88f314ff94f3dd6d56d40ef65854fcd7fff6b" - sha, err := btcwire.NewShaHashFromStr(inputStr) + sha, err := wire.NewShaHashFromStr(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch NewShaHashFromStr failed: %v\n", err) return @@ -250,7 +250,7 @@ func TestFilterBloomMatch(t *testing.T) { t.Errorf("TestFilterBloomMatch didn't match sha %s", inputStr) } - f = bloom.NewFilter(10, 0, 0.000001, btcwire.BloomUpdateAll) + f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "6bff7fcd4f8565ef406dd5d63d4ff94f318fe82027fd4dc451b04474019f74b4" shaBytes, err := hex.DecodeString(inputStr) if err != nil { @@ -262,7 +262,7 @@ func TestFilterBloomMatch(t *testing.T) { t.Errorf("TestFilterBloomMatch didn't match sha %s", inputStr) } - f = bloom.NewFilter(10, 0, 0.000001, btcwire.BloomUpdateAll) + f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "30450220070aca44506c5cef3a16ed519d7c3c39f8aab192c4e1c90d065" + "f37b8a4af6141022100a8e160b856c2d43d27d8fba71e5aef6405b8643" + "ac4cb7cb3c462aced7f14711a01" @@ -276,7 +276,7 @@ func TestFilterBloomMatch(t *testing.T) { t.Errorf("TestFilterBloomMatch didn't match input signature %s", inputStr) } - f = bloom.NewFilter(10, 0, 0.000001, btcwire.BloomUpdateAll) + f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "046d11fee51b0e60666d5049a9101a72741df480b96ee26488a4d3466b95" + "c9a40ac5eeef87e10a5cd336c19a84565f80fa6c547957b7700ff4dfbdefe" + "76036c339" @@ -290,7 +290,7 @@ func TestFilterBloomMatch(t *testing.T) { t.Errorf("TestFilterBloomMatch didn't match input pubkey %s", inputStr) } - f = bloom.NewFilter(10, 0, 0.000001, btcwire.BloomUpdateAll) + f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "04943fdd508053c75000106d3bc6e2754dbcff19" shaBytes, err = hex.DecodeString(inputStr) if err != nil { @@ -305,7 +305,7 @@ func TestFilterBloomMatch(t *testing.T) { t.Errorf("TestFilterBloomMatch spendingTx didn't match output address %s", inputStr) } - f = bloom.NewFilter(10, 0, 0.000001, btcwire.BloomUpdateAll) + f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "a266436d2965547608b9e15d9032a7b9d64fa431" shaBytes, err = hex.DecodeString(inputStr) if err != nil { @@ -317,22 +317,22 @@ func TestFilterBloomMatch(t *testing.T) { t.Errorf("TestFilterBloomMatch didn't match output address %s", inputStr) } - f = bloom.NewFilter(10, 0, 0.000001, btcwire.BloomUpdateAll) + f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "90c122d70786e899529d71dbeba91ba216982fb6ba58f3bdaab65e73b7e9260b" - sha, err = btcwire.NewShaHashFromStr(inputStr) + sha, err = wire.NewShaHashFromStr(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch NewShaHashFromStr failed: %v\n", err) return } - outpoint := btcwire.NewOutPoint(sha, 0) + outpoint := wire.NewOutPoint(sha, 0) f.AddOutPoint(outpoint) if !f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch didn't match outpoint %s", inputStr) } - f = bloom.NewFilter(10, 0, 0.000001, btcwire.BloomUpdateAll) + f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "00000009e784f32f62ef849763d4f45b98e07ba658647343b915ff832b110436" - sha, err = btcwire.NewShaHashFromStr(inputStr) + sha, err = wire.NewShaHashFromStr(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch NewShaHashFromStr failed: %v\n", err) return @@ -342,7 +342,7 @@ func TestFilterBloomMatch(t *testing.T) { t.Errorf("TestFilterBloomMatch matched sha %s", inputStr) } - f = bloom.NewFilter(10, 0, 0.000001, btcwire.BloomUpdateAll) + f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "0000006d2965547608b9e15d9032a7b9d64fa431" shaBytes, err = hex.DecodeString(inputStr) if err != nil { @@ -354,27 +354,27 @@ func TestFilterBloomMatch(t *testing.T) { t.Errorf("TestFilterBloomMatch matched address %s", inputStr) } - f = bloom.NewFilter(10, 0, 0.000001, btcwire.BloomUpdateAll) + f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "90c122d70786e899529d71dbeba91ba216982fb6ba58f3bdaab65e73b7e9260b" - sha, err = btcwire.NewShaHashFromStr(inputStr) + sha, err = wire.NewShaHashFromStr(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch NewShaHashFromStr failed: %v\n", err) return } - outpoint = btcwire.NewOutPoint(sha, 1) + outpoint = wire.NewOutPoint(sha, 1) f.AddOutPoint(outpoint) if f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch matched outpoint %s", inputStr) } - f = bloom.NewFilter(10, 0, 0.000001, btcwire.BloomUpdateAll) + f = bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr = "000000d70786e899529d71dbeba91ba216982fb6ba58f3bdaab65e73b7e9260b" - sha, err = btcwire.NewShaHashFromStr(inputStr) + sha, err = wire.NewShaHashFromStr(inputStr) if err != nil { t.Errorf("TestFilterBloomMatch NewShaHashFromStr failed: %v\n", err) return } - outpoint = btcwire.NewOutPoint(sha, 0) + outpoint = wire.NewOutPoint(sha, 0) f.AddOutPoint(outpoint) if f.MatchTxAndUpdate(tx) { t.Errorf("TestFilterBloomMatch matched outpoint %s", inputStr) @@ -382,7 +382,7 @@ func TestFilterBloomMatch(t *testing.T) { } func TestFilterInsertUpdateNone(t *testing.T) { - f := bloom.NewFilter(10, 0, 0.000001, btcwire.BloomUpdateNone) + f := bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateNone) // Add the generation pubkey inputStr := "04eaafc2314def4ca98ac970241bcab022b9c1e1f4ea423a20f134c" + @@ -405,12 +405,12 @@ func TestFilterInsertUpdateNone(t *testing.T) { f.Add(inputBytes) inputStr = "147caa76786596590baa4e98f5d9f48b86c7765e489f7a6ff3360fe5c674360b" - sha, err := btcwire.NewShaHashFromStr(inputStr) + sha, err := wire.NewShaHashFromStr(inputStr) if err != nil { t.Errorf("TestFilterInsertUpdateNone NewShaHashFromStr failed: %v", err) return } - outpoint := btcwire.NewOutPoint(sha, 0) + outpoint := wire.NewOutPoint(sha, 0) if f.MatchesOutPoint(outpoint) { t.Errorf("TestFilterInsertUpdateNone matched outpoint %s", inputStr) @@ -418,12 +418,12 @@ func TestFilterInsertUpdateNone(t *testing.T) { } inputStr = "02981fa052f0481dbc5868f4fc2166035a10f27a03cfd2de67326471df5bc041" - sha, err = btcwire.NewShaHashFromStr(inputStr) + sha, err = wire.NewShaHashFromStr(inputStr) if err != nil { t.Errorf("TestFilterInsertUpdateNone NewShaHashFromStr failed: %v", err) return } - outpoint = btcwire.NewOutPoint(sha, 0) + outpoint = wire.NewOutPoint(sha, 0) if f.MatchesOutPoint(outpoint) { t.Errorf("TestFilterInsertUpdateNone matched outpoint %s", inputStr) @@ -530,7 +530,7 @@ func TestFilterInsertP2PubKeyOnly(t *testing.T) { return } - f := bloom.NewFilter(10, 0, 0.000001, btcwire.BloomUpdateP2PubkeyOnly) + f := bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateP2PubkeyOnly) // Generation pubkey inputStr := "04eaafc2314def4ca98ac970241bcab022b9c1e1f4ea423a20f134c" + @@ -557,12 +557,12 @@ func TestFilterInsertP2PubKeyOnly(t *testing.T) { // We should match the generation pubkey inputStr = "147caa76786596590baa4e98f5d9f48b86c7765e489f7a6ff3360fe5c674360b" - sha, err := btcwire.NewShaHashFromStr(inputStr) + sha, err := wire.NewShaHashFromStr(inputStr) if err != nil { t.Errorf("TestMerkleBlockP2PubKeyOnly NewShaHashFromStr failed: %v", err) return } - outpoint := btcwire.NewOutPoint(sha, 0) + outpoint := wire.NewOutPoint(sha, 0) if !f.MatchesOutPoint(outpoint) { t.Errorf("TestMerkleBlockP2PubKeyOnly didn't match the generation "+ "outpoint %s", inputStr) @@ -571,12 +571,12 @@ func TestFilterInsertP2PubKeyOnly(t *testing.T) { // We should not match the 4th transaction, which is not p2pk inputStr = "02981fa052f0481dbc5868f4fc2166035a10f27a03cfd2de67326471df5bc041" - sha, err = btcwire.NewShaHashFromStr(inputStr) + sha, err = wire.NewShaHashFromStr(inputStr) if err != nil { t.Errorf("TestMerkleBlockP2PubKeyOnly NewShaHashFromStr failed: %v", err) return } - outpoint = btcwire.NewOutPoint(sha, 0) + outpoint = wire.NewOutPoint(sha, 0) if f.MatchesOutPoint(outpoint) { t.Errorf("TestMerkleBlockP2PubKeyOnly matched outpoint %s", inputStr) return @@ -584,7 +584,7 @@ func TestFilterInsertP2PubKeyOnly(t *testing.T) { } func TestFilterReload(t *testing.T) { - f := bloom.NewFilter(10, 0, 0.000001, btcwire.BloomUpdateAll) + f := bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) bFilter := bloom.LoadFilter(f.MsgFilterLoad()) if bFilter.MsgFilterLoad() == nil { diff --git a/bloom/merkleblock.go b/bloom/merkleblock.go index bb2beea..4186537 100644 --- a/bloom/merkleblock.go +++ b/bloom/merkleblock.go @@ -6,16 +6,16 @@ package bloom import ( "github.com/btcsuite/btcd/blockchain" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" - "github.com/btcsuite/btcwire" ) // merkleBlock is used to house intermediate information needed to generate a -// btcwire.MsgMerkleBlock according to a filter. +// wire.MsgMerkleBlock according to a filter. type merkleBlock struct { numTx uint32 - allHashes []*btcwire.ShaHash - finalHashes []*btcwire.ShaHash + allHashes []*wire.ShaHash + finalHashes []*wire.ShaHash matchedBits []byte bits []byte } @@ -28,12 +28,12 @@ func (m *merkleBlock) calcTreeWidth(height uint32) uint32 { // calcHash returns the hash for a sub-tree given a depth-first height and // node position. -func (m *merkleBlock) calcHash(height, pos uint32) *btcwire.ShaHash { +func (m *merkleBlock) calcHash(height, pos uint32) *wire.ShaHash { if height == 0 { return m.allHashes[pos] } - var right *btcwire.ShaHash + var right *wire.ShaHash left := m.calcHash(height-1, pos*2) if pos*2+1 < m.calcTreeWidth(height-1) { right = m.calcHash(height-1, pos*2+1) @@ -76,18 +76,18 @@ func (m *merkleBlock) traverseAndBuild(height, pos uint32) { } } -// NewMerkleBlock returns a new *btcwire.MsgMerkleBlock and an array of the matched +// NewMerkleBlock returns a new *wire.MsgMerkleBlock and an array of the matched // transaction hashes based on the passed block and filter. -func NewMerkleBlock(block *btcutil.Block, filter *Filter) (*btcwire.MsgMerkleBlock, []*btcwire.ShaHash) { +func NewMerkleBlock(block *btcutil.Block, filter *Filter) (*wire.MsgMerkleBlock, []*wire.ShaHash) { numTx := uint32(len(block.Transactions())) mBlock := merkleBlock{ numTx: numTx, - allHashes: make([]*btcwire.ShaHash, 0, numTx), + allHashes: make([]*wire.ShaHash, 0, numTx), matchedBits: make([]byte, 0, numTx), } // Find and keep track of any transactions that match the filter. - var matchedHashes []*btcwire.ShaHash + var matchedHashes []*wire.ShaHash for _, tx := range block.Transactions() { if filter.MatchTxAndUpdate(tx) { mBlock.matchedBits = append(mBlock.matchedBits, 0x01) @@ -108,10 +108,10 @@ func NewMerkleBlock(block *btcutil.Block, filter *Filter) (*btcwire.MsgMerkleBlo mBlock.traverseAndBuild(height, 0) // Create and return the merkle block. - msgMerkleBlock := btcwire.MsgMerkleBlock{ + msgMerkleBlock := wire.MsgMerkleBlock{ Header: block.MsgBlock().Header, Transactions: uint32(mBlock.numTx), - Hashes: make([]*btcwire.ShaHash, 0, len(mBlock.finalHashes)), + Hashes: make([]*wire.ShaHash, 0, len(mBlock.finalHashes)), Flags: make([]byte, (len(mBlock.bits)+7)/8), } for _, sha := range mBlock.finalHashes { diff --git a/bloom/merkleblock_test.go b/bloom/merkleblock_test.go index f06bdfc..7000a33 100644 --- a/bloom/merkleblock_test.go +++ b/bloom/merkleblock_test.go @@ -9,9 +9,9 @@ import ( "encoding/hex" "testing" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil/bloom" - "github.com/btcsuite/btcwire" ) func TestMerkleBlock3(t *testing.T) { @@ -34,10 +34,10 @@ func TestMerkleBlock3(t *testing.T) { return } - f := bloom.NewFilter(10, 0, 0.000001, btcwire.BloomUpdateAll) + f := bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll) inputStr := "63194f18be0af63f2c6bc9dc0f777cbefed3d9415c4af83f3ee3a3d669c00cb5" - sha, err := btcwire.NewShaHashFromStr(inputStr) + sha, err := wire.NewShaHashFromStr(inputStr) if err != nil { t.Errorf("TestMerkleBlock3 NewShaHashFromStr failed: %v", err) return @@ -59,7 +59,7 @@ func TestMerkleBlock3(t *testing.T) { } got := bytes.NewBuffer(nil) - err = mBlock.BtcEncode(got, btcwire.ProtocolVersion) + err = mBlock.BtcEncode(got, wire.ProtocolVersion) if err != nil { t.Errorf("TestMerkleBlock3 BtcEncode failed: %v", err) return diff --git a/coinset/coins.go b/coinset/coins.go index c947193..9d7849b 100644 --- a/coinset/coins.go +++ b/coinset/coins.go @@ -5,13 +5,13 @@ import ( "errors" "sort" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" - "github.com/btcsuite/btcwire" ) // Coin represents a spendable transaction outpoint type Coin interface { - Hash() *btcwire.ShaHash + Hash() *wire.ShaHash Index() uint32 Value() btcutil.Amount PkScript() []byte @@ -118,19 +118,19 @@ func (cs *CoinSet) removeElement(e *list.Element) Coin { } // NewMsgTxWithInputCoins takes the coins in the CoinSet and makes them -// the inputs to a new btcwire.MsgTx which is returned. -func NewMsgTxWithInputCoins(inputCoins Coins) *btcwire.MsgTx { - msgTx := btcwire.NewMsgTx() +// the inputs to a new wire.MsgTx which is returned. +func NewMsgTxWithInputCoins(inputCoins Coins) *wire.MsgTx { + msgTx := wire.NewMsgTx() coins := inputCoins.Coins() - msgTx.TxIn = make([]*btcwire.TxIn, len(coins)) + msgTx.TxIn = make([]*wire.TxIn, len(coins)) for i, coin := range coins { - msgTx.TxIn[i] = &btcwire.TxIn{ - PreviousOutPoint: btcwire.OutPoint{ + msgTx.TxIn[i] = &wire.TxIn{ + PreviousOutPoint: wire.OutPoint{ Hash: *coin.Hash(), Index: coin.Index(), }, SignatureScript: nil, - Sequence: btcwire.MaxTxInSequenceNum, + Sequence: wire.MaxTxInSequenceNum, } } return msgTx @@ -354,7 +354,7 @@ type SimpleCoin struct { var _ Coin = &SimpleCoin{} // Hash returns the hash value of the transaction on which the Coin is an output -func (c *SimpleCoin) Hash() *btcwire.ShaHash { +func (c *SimpleCoin) Hash() *wire.ShaHash { return c.Tx.Sha() } @@ -364,7 +364,7 @@ func (c *SimpleCoin) Index() uint32 { } // txOut returns the TxOut of the transaction the Coin represents -func (c *SimpleCoin) txOut() *btcwire.TxOut { +func (c *SimpleCoin) txOut() *wire.TxOut { return c.Tx.MsgTx().TxOut[c.TxIndex] } diff --git a/coinset/coins_test.go b/coinset/coins_test.go index 8c9a50d..c61b347 100644 --- a/coinset/coins_test.go +++ b/coinset/coins_test.go @@ -6,30 +6,30 @@ import ( "fmt" "testing" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil/coinset" - "github.com/btcsuite/btcwire" "github.com/btcsuite/fastsha256" ) type TestCoin struct { - TxHash *btcwire.ShaHash + TxHash *wire.ShaHash TxIndex uint32 TxValue btcutil.Amount TxNumConfs int64 } -func (c *TestCoin) Hash() *btcwire.ShaHash { return c.TxHash } -func (c *TestCoin) Index() uint32 { return c.TxIndex } -func (c *TestCoin) Value() btcutil.Amount { return c.TxValue } -func (c *TestCoin) PkScript() []byte { return nil } -func (c *TestCoin) NumConfs() int64 { return c.TxNumConfs } -func (c *TestCoin) ValueAge() int64 { return int64(c.TxValue) * c.TxNumConfs } +func (c *TestCoin) Hash() *wire.ShaHash { return c.TxHash } +func (c *TestCoin) Index() uint32 { return c.TxIndex } +func (c *TestCoin) Value() btcutil.Amount { return c.TxValue } +func (c *TestCoin) PkScript() []byte { return nil } +func (c *TestCoin) NumConfs() int64 { return c.TxNumConfs } +func (c *TestCoin) ValueAge() int64 { return int64(c.TxValue) * c.TxNumConfs } func NewCoin(index int64, value btcutil.Amount, numConfs int64) coinset.Coin { h := fastsha256.New() h.Write([]byte(fmt.Sprintf("%d", index))) - hash, _ := btcwire.NewShaHash(h.Sum(nil)) + hash, _ := wire.NewShaHash(h.Sum(nil)) c := &TestCoin{ TxHash: hash, TxIndex: 0, diff --git a/hdkeychain/extendedkey.go b/hdkeychain/extendedkey.go index da310ab..4cdeafe 100644 --- a/hdkeychain/extendedkey.go +++ b/hdkeychain/extendedkey.go @@ -18,11 +18,11 @@ import ( "fmt" "math/big" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcec" "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil/base58" - "github.com/btcsuite/btcwire" ) const ( @@ -385,7 +385,7 @@ func (k *ExtendedKey) String() string { serializedBytes = append(serializedBytes, k.pubKeyBytes()...) } - checkSum := btcwire.DoubleSha256(serializedBytes)[:4] + checkSum := wire.DoubleSha256(serializedBytes)[:4] serializedBytes = append(serializedBytes, checkSum...) return base58.Encode(serializedBytes) } @@ -486,7 +486,7 @@ func NewKeyFromString(key string) (*ExtendedKey, error) { // Split the payload and checksum up and ensure the checksum matches. payload := decoded[:len(decoded)-4] checkSum := decoded[len(decoded)-4:] - expectedCheckSum := btcwire.DoubleSha256(payload)[:4] + expectedCheckSum := wire.DoubleSha256(payload)[:4] if !bytes.Equal(checkSum, expectedCheckSum) { return nil, ErrBadChecksum } diff --git a/tx.go b/tx.go index 9801d8e..8dda596 100644 --- a/tx.go +++ b/tx.go @@ -8,7 +8,7 @@ import ( "bytes" "io" - "github.com/btcsuite/btcwire" + "github.com/btcsuite/btcd/wire" ) // TxIndexUnknown is the value returned for a transaction index that is unknown. @@ -21,21 +21,21 @@ const TxIndexUnknown = -1 // transaction on its first access so subsequent accesses don't have to repeat // the relatively expensive hashing operations. type Tx struct { - msgTx *btcwire.MsgTx // Underlying MsgTx - txSha *btcwire.ShaHash // Cached transaction hash - txIndex int // Position within a block or TxIndexUnknown + msgTx *wire.MsgTx // Underlying MsgTx + txSha *wire.ShaHash // Cached transaction hash + txIndex int // Position within a block or TxIndexUnknown } -// MsgTx returns the underlying btcwire.MsgTx for the transaction. -func (t *Tx) MsgTx() *btcwire.MsgTx { +// MsgTx returns the underlying wire.MsgTx for the transaction. +func (t *Tx) MsgTx() *wire.MsgTx { // Return the cached transaction. return t.msgTx } // Sha returns the hash of the transaction. This is equivalent to -// calling TxSha on the underlying btcwire.MsgTx, however it caches the +// calling TxSha on the underlying wire.MsgTx, however it caches the // result so subsequent calls are more efficient. -func (t *Tx) Sha() *btcwire.ShaHash { +func (t *Tx) Sha() *wire.ShaHash { // Return the cached hash if it has already been generated. if t.txSha != nil { return t.txSha @@ -62,8 +62,8 @@ func (t *Tx) SetIndex(index int) { } // NewTx returns a new instance of a bitcoin transaction given an underlying -// btcwire.MsgTx. See Tx. -func NewTx(msgTx *btcwire.MsgTx) *Tx { +// wire.MsgTx. See Tx. +func NewTx(msgTx *wire.MsgTx) *Tx { return &Tx{ msgTx: msgTx, txIndex: TxIndexUnknown, @@ -81,7 +81,7 @@ func NewTxFromBytes(serializedTx []byte) (*Tx, error) { // Reader to deserialize the transaction. See Tx. func NewTxFromReader(r io.Reader) (*Tx, error) { // Deserialize the bytes into a MsgTx. - var msgTx btcwire.MsgTx + var msgTx wire.MsgTx err := msgTx.Deserialize(r) if err != nil { return nil, err diff --git a/tx_test.go b/tx_test.go index fce338f..377a1b9 100644 --- a/tx_test.go +++ b/tx_test.go @@ -10,8 +10,8 @@ import ( "reflect" "testing" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" - "github.com/btcsuite/btcwire" "github.com/davecgh/go-spew/spew" ) @@ -36,7 +36,7 @@ func TestTx(t *testing.T) { // Hash for block 100,000 transaction 0. wantShaStr := "8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87" - wantSha, err := btcwire.NewShaHashFromStr(wantShaStr) + wantSha, err := wire.NewShaHashFromStr(wantShaStr) if err != nil { t.Errorf("NewShaHashFromStr: %v", err) } diff --git a/wif.go b/wif.go index c1119ff..f6d086b 100644 --- a/wif.go +++ b/wif.go @@ -8,10 +8,10 @@ import ( "bytes" "errors" + "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcec" "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil/base58" - "github.com/btcsuite/btcwire" ) // ErrMalformedPrivateKey describes an error where a WIF-encoded private @@ -110,7 +110,7 @@ func DecodeWIF(wif string) (*WIF, error) { } else { tosum = decoded[:1+btcec.PrivKeyBytesLen] } - cksum := btcwire.DoubleSha256(tosum)[:4] + cksum := wire.DoubleSha256(tosum)[:4] if !bytes.Equal(cksum, decoded[decodedLen-4:]) { return nil, ErrChecksumMismatch } @@ -142,7 +142,7 @@ func (w *WIF) String() string { if w.CompressPubKey { a = append(a, compressMagic) } - cksum := btcwire.DoubleSha256(a)[:4] + cksum := wire.DoubleSha256(a)[:4] a = append(a, cksum...) return base58.Encode(a) }