Update btcwire path import paths to new location.

This commit is contained in:
Dave Collins 2015-02-05 14:48:38 -06:00
parent d71631b41f
commit 80b97479bd
14 changed files with 177 additions and 177 deletions

View file

@ -13,13 +13,13 @@ import (
"golang.org/x/crypto/ripemd160" "golang.org/x/crypto/ripemd160"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcnet" "github.com/btcsuite/btcnet"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/btcsuite/btcwire"
) )
// invalidNet is an invalid bitcoin network. // invalidNet is an invalid bitcoin network.
const invalidNet = btcwire.BitcoinNet(0xffffffff) const invalidNet = wire.BitcoinNet(0xffffffff)
func TestAddresses(t *testing.T) { func TestAddresses(t *testing.T) {
tests := []struct { tests := []struct {

View file

@ -9,7 +9,7 @@ import (
"fmt" "fmt"
"io" "io"
"github.com/btcsuite/btcwire" "github.com/btcsuite/btcd/wire"
) )
// OutOfRangeError describes an error due to accessing an element that is out // 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 // transactions on their first access so subsequent accesses don't have to
// repeat the relatively expensive hashing operations. // repeat the relatively expensive hashing operations.
type Block struct { type Block struct {
msgBlock *btcwire.MsgBlock // Underlying MsgBlock msgBlock *wire.MsgBlock // Underlying MsgBlock
serializedBlock []byte // Serialized bytes for the block serializedBlock []byte // Serialized bytes for the block
blockSha *btcwire.ShaHash // Cached block hash blockSha *wire.ShaHash // Cached block hash
blockHeight int64 // Height in the main block chain blockHeight int64 // Height in the main block chain
transactions []*Tx // Transactions transactions []*Tx // Transactions
txnsGenerated bool // ALL wrapped transactions generated txnsGenerated bool // ALL wrapped transactions generated
} }
// MsgBlock returns the underlying btcwire.MsgBlock for the Block. // MsgBlock returns the underlying wire.MsgBlock for the Block.
func (b *Block) MsgBlock() *btcwire.MsgBlock { func (b *Block) MsgBlock() *wire.MsgBlock {
// Return the cached block. // Return the cached block.
return b.msgBlock return b.msgBlock
} }
// Bytes returns the serialized bytes for the Block. This is equivalent to // 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. // result so subsequent calls are more efficient.
func (b *Block) Bytes() ([]byte, error) { func (b *Block) Bytes() ([]byte, error) {
// Return the cached serialized bytes if it has already been generated. // 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 // 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. // 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. // Return the cached block hash if it has already been generated.
if b.blockSha != nil { if b.blockSha != nil {
return 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 // 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 // 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 // say, the first transaction in the block is txNum 0. This is nearly
// equivalent to accessing the raw transaction (btcwire.MsgTx) from the // equivalent to accessing the raw transaction (wire.MsgTx) from the
// underlying btcwire.MsgBlock, however the wrapped transaction has some helpful // underlying wire.MsgBlock, however the wrapped transaction has some helpful
// properties such as caching the hash so subsequent calls are more efficient. // properties such as caching the hash so subsequent calls are more efficient.
func (b *Block) Tx(txNum int) (*Tx, error) { func (b *Block) Tx(txNum int) (*Tx, error) {
// Ensure the requested transaction is in range. // 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 returns a slice of wrapped transactions (btcutil.Tx) for all
// transactions in the Block. This is nearly equivalent to accessing the raw // 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. // instead provides easy access to wrapped versions (btcutil.Tx) of them.
func (b *Block) Transactions() []*Tx { func (b *Block) Transactions() []*Tx {
// Return transactions if they have ALL already been generated. This // 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. // 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 // 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 // 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. // 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 // Attempt to get a wrapped transaction for the specified index. It
// will be created lazily if needed or simply return the cached version // will be created lazily if needed or simply return the cached version
// if it has already been generated. // 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. // 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 // It is used to allow fast indexing into transactions within the raw byte
// stream. // stream.
func (b *Block) TxLoc() ([]btcwire.TxLoc, error) { func (b *Block) TxLoc() ([]wire.TxLoc, error) {
rawMsg, err := b.Bytes() rawMsg, err := b.Bytes()
if err != nil { if err != nil {
return nil, err return nil, err
} }
rbuf := bytes.NewBuffer(rawMsg) rbuf := bytes.NewBuffer(rawMsg)
var mblock btcwire.MsgBlock var mblock wire.MsgBlock
txLocs, err := mblock.DeserializeTxLoc(rbuf) txLocs, err := mblock.DeserializeTxLoc(rbuf)
if err != nil { if err != nil {
return nil, err 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 // NewBlock returns a new instance of a bitcoin block given an underlying
// btcwire.MsgBlock. See Block. // wire.MsgBlock. See Block.
func NewBlock(msgBlock *btcwire.MsgBlock) *Block { func NewBlock(msgBlock *wire.MsgBlock) *Block {
return &Block{ return &Block{
msgBlock: msgBlock, msgBlock: msgBlock,
blockHeight: BlockHeightUnknown, blockHeight: BlockHeightUnknown,
@ -221,7 +221,7 @@ func NewBlockFromBytes(serializedBlock []byte) (*Block, error) {
// Reader to deserialize the block. See Block. // Reader to deserialize the block. See Block.
func NewBlockFromReader(r io.Reader) (*Block, error) { func NewBlockFromReader(r io.Reader) (*Block, error) {
// Deserialize the bytes into a MsgBlock. // Deserialize the bytes into a MsgBlock.
var msgBlock btcwire.MsgBlock var msgBlock wire.MsgBlock
err := msgBlock.Deserialize(r) err := msgBlock.Deserialize(r)
if err != nil { if err != nil {
return nil, err return nil, err
@ -235,8 +235,8 @@ func NewBlockFromReader(r io.Reader) (*Block, error) {
} }
// NewBlockFromBlockAndBytes returns a new instance of a bitcoin block given // NewBlockFromBlockAndBytes returns a new instance of a bitcoin block given
// an underlying btcwire.MsgBlock and the serialized bytes for it. See Block. // an underlying wire.MsgBlock and the serialized bytes for it. See Block.
func NewBlockFromBlockAndBytes(msgBlock *btcwire.MsgBlock, serializedBlock []byte) *Block { func NewBlockFromBlockAndBytes(msgBlock *wire.MsgBlock, serializedBlock []byte) *Block {
return &Block{ return &Block{
msgBlock: msgBlock, msgBlock: msgBlock,
serializedBlock: serializedBlock, serializedBlock: serializedBlock,

View file

@ -11,8 +11,8 @@ import (
"testing" "testing"
"time" "time"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/btcsuite/btcwire"
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
) )
@ -36,7 +36,7 @@ func TestBlock(t *testing.T) {
// Hash for block 100,000. // Hash for block 100,000.
wantShaStr := "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506" wantShaStr := "3ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506"
wantSha, err := btcwire.NewShaHashFromStr(wantShaStr) wantSha, err := wire.NewShaHashFromStr(wantShaStr)
if err != nil { if err != nil {
t.Errorf("NewShaHashFromStr: %v", err) 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. // Request sha for all transactions one at a time via Tx.
for i, txSha := range wantTxShas { for i, txSha := range wantTxShas {
wantSha, err := btcwire.NewShaHashFromStr(txSha) wantSha, err := wire.NewShaHashFromStr(txSha)
if err != nil { if err != nil {
t.Errorf("NewShaHashFromStr: %v", err) t.Errorf("NewShaHashFromStr: %v", err)
} }
@ -107,7 +107,7 @@ func TestBlock(t *testing.T) {
// Ensure all of the shas match. // Ensure all of the shas match.
for j, tx := range transactions { for j, tx := range transactions {
wantSha, err := btcwire.NewShaHashFromStr(wantTxShas[j]) wantSha, err := wire.NewShaHashFromStr(wantTxShas[j])
if err != nil { if err != nil {
t.Errorf("NewShaHashFromStr: %v", err) t.Errorf("NewShaHashFromStr: %v", err)
} }
@ -146,7 +146,7 @@ func TestBlock(t *testing.T) {
} }
// Transaction offsets and length for the transaction in Block100000. // Transaction offsets and length for the transaction in Block100000.
wantTxLocs := []btcwire.TxLoc{ wantTxLocs := []wire.TxLoc{
{TxStart: 81, TxLen: 135}, {TxStart: 81, TxLen: 135},
{TxStart: 216, TxLen: 259}, {TxStart: 216, TxLen: 259},
{TxStart: 475, TxLen: 257}, {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 // Block100000 defines block 100,000 of the block chain. It is used to
// test Block operations. // test Block operations.
var Block100000 = btcwire.MsgBlock{ var Block100000 = wire.MsgBlock{
Header: btcwire.BlockHeader{ Header: wire.BlockHeader{
Version: 1, 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, 0x50, 0x12, 0x01, 0x19, 0x17, 0x2a, 0x61, 0x04,
0x21, 0xa6, 0xc3, 0x01, 0x1d, 0xd3, 0x30, 0xd9, 0x21, 0xa6, 0xc3, 0x01, 0x1d, 0xd3, 0x30, 0xd9,
0xdf, 0x07, 0xb6, 0x36, 0x16, 0xc2, 0xcc, 0x1f, 0xdf, 0x07, 0xb6, 0x36, 0x16, 0xc2, 0xcc, 0x1f,
0x1c, 0xd0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0xd0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
}), // 000000000002d01c1fccc21636b607dfd930d31d01c3a62104612a1719011250 }), // 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, 0x66, 0x57, 0xa9, 0x25, 0x2a, 0xac, 0xd5, 0xc0,
0xb2, 0x94, 0x09, 0x96, 0xec, 0xff, 0x95, 0x22, 0xb2, 0x94, 0x09, 0x96, 0xec, 0xff, 0x95, 0x22,
0x28, 0xc3, 0x06, 0x7c, 0xc3, 0x8d, 0x48, 0x85, 0x28, 0xc3, 0x06, 0x7c, 0xc3, 0x8d, 0x48, 0x85,
@ -322,13 +322,13 @@ var Block100000 = btcwire.MsgBlock{
Bits: 0x1b04864c, // 453281356 Bits: 0x1b04864c, // 453281356
Nonce: 0x10572b0f, // 274148111 Nonce: 0x10572b0f, // 274148111
}, },
Transactions: []*btcwire.MsgTx{ Transactions: []*wire.MsgTx{
{ {
Version: 1, Version: 1,
TxIn: []*btcwire.TxIn{ TxIn: []*wire.TxIn{
{ {
PreviousOutPoint: btcwire.OutPoint{ PreviousOutPoint: wire.OutPoint{
Hash: btcwire.ShaHash{}, Hash: wire.ShaHash{},
Index: 0xffffffff, Index: 0xffffffff,
}, },
SignatureScript: []byte{ SignatureScript: []byte{
@ -337,7 +337,7 @@ var Block100000 = btcwire.MsgBlock{
Sequence: 0xffffffff, Sequence: 0xffffffff,
}, },
}, },
TxOut: []*btcwire.TxOut{ TxOut: []*wire.TxOut{
{ {
Value: 0x12a05f200, // 5000000000 Value: 0x12a05f200, // 5000000000
PkScript: []byte{ PkScript: []byte{
@ -359,10 +359,10 @@ var Block100000 = btcwire.MsgBlock{
}, },
{ {
Version: 1, Version: 1,
TxIn: []*btcwire.TxIn{ TxIn: []*wire.TxIn{
{ {
PreviousOutPoint: btcwire.OutPoint{ PreviousOutPoint: wire.OutPoint{
Hash: btcwire.ShaHash([32]byte{ // Make go vet happy. Hash: wire.ShaHash([32]byte{ // Make go vet happy.
0x03, 0x2e, 0x38, 0xe9, 0xc0, 0xa8, 0x4c, 0x60, 0x03, 0x2e, 0x38, 0xe9, 0xc0, 0xa8, 0x4c, 0x60,
0x46, 0xd6, 0x87, 0xd1, 0x05, 0x56, 0xdc, 0xac, 0x46, 0xd6, 0x87, 0xd1, 0x05, 0x56, 0xdc, 0xac,
0xc4, 0x1d, 0x27, 0x5e, 0xc5, 0x5f, 0xc0, 0x07, 0xc4, 0x1d, 0x27, 0x5e, 0xc5, 0x5f, 0xc0, 0x07,
@ -396,7 +396,7 @@ var Block100000 = btcwire.MsgBlock{
Sequence: 0xffffffff, Sequence: 0xffffffff,
}, },
}, },
TxOut: []*btcwire.TxOut{ TxOut: []*wire.TxOut{
{ {
Value: 0x2123e300, // 556000000 Value: 0x2123e300, // 556000000
PkScript: []byte{ PkScript: []byte{
@ -428,10 +428,10 @@ var Block100000 = btcwire.MsgBlock{
}, },
{ {
Version: 1, Version: 1,
TxIn: []*btcwire.TxIn{ TxIn: []*wire.TxIn{
{ {
PreviousOutPoint: btcwire.OutPoint{ PreviousOutPoint: wire.OutPoint{
Hash: btcwire.ShaHash([32]byte{ // Make go vet happy. Hash: wire.ShaHash([32]byte{ // Make go vet happy.
0xc3, 0x3e, 0xbf, 0xf2, 0xa7, 0x09, 0xf1, 0x3d, 0xc3, 0x3e, 0xbf, 0xf2, 0xa7, 0x09, 0xf1, 0x3d,
0x9f, 0x9a, 0x75, 0x69, 0xab, 0x16, 0xa3, 0x27, 0x9f, 0x9a, 0x75, 0x69, 0xab, 0x16, 0xa3, 0x27,
0x86, 0xaf, 0x7d, 0x7e, 0x2d, 0xe0, 0x92, 0x65, 0x86, 0xaf, 0x7d, 0x7e, 0x2d, 0xe0, 0x92, 0x65,
@ -464,7 +464,7 @@ var Block100000 = btcwire.MsgBlock{
Sequence: 0xffffffff, Sequence: 0xffffffff,
}, },
}, },
TxOut: []*btcwire.TxOut{ TxOut: []*wire.TxOut{
{ {
Value: 0xf4240, // 1000000 Value: 0xf4240, // 1000000
PkScript: []byte{ PkScript: []byte{
@ -496,10 +496,10 @@ var Block100000 = btcwire.MsgBlock{
}, },
{ {
Version: 1, Version: 1,
TxIn: []*btcwire.TxIn{ TxIn: []*wire.TxIn{
{ {
PreviousOutPoint: btcwire.OutPoint{ PreviousOutPoint: wire.OutPoint{
Hash: btcwire.ShaHash([32]byte{ // Make go vet happy. Hash: wire.ShaHash([32]byte{ // Make go vet happy.
0x0b, 0x60, 0x72, 0xb3, 0x86, 0xd4, 0xa7, 0x73, 0x0b, 0x60, 0x72, 0xb3, 0x86, 0xd4, 0xa7, 0x73,
0x23, 0x52, 0x37, 0xf6, 0x4c, 0x11, 0x26, 0xac, 0x23, 0x52, 0x37, 0xf6, 0x4c, 0x11, 0x26, 0xac,
0x3b, 0x24, 0x0c, 0x84, 0xb9, 0x17, 0xa3, 0x90, 0x3b, 0x24, 0x0c, 0x84, 0xb9, 0x17, 0xa3, 0x90,
@ -533,7 +533,7 @@ var Block100000 = btcwire.MsgBlock{
Sequence: 0xffffffff, Sequence: 0xffffffff,
}, },
}, },
TxOut: []*btcwire.TxOut{ TxOut: []*wire.TxOut{
{ {
Value: 0xf4240, // 1000000 Value: 0xf4240, // 1000000
PkScript: []byte{ PkScript: []byte{

View file

@ -9,8 +9,8 @@ import (
"math/rand" "math/rand"
"time" "time"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil/bloom" "github.com/btcsuite/btcutil/bloom"
"github.com/btcsuite/btcwire"
) )
// This example demonstrates how to create a new bloom filter, add a transaction // 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% // Create a new bloom filter intended to hold 10 elements with a 0.01%
// false positive rate and does not include any automatic update // false positive rate and does not include any automatic update
// functionality when transactions are matched. // 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 // Create a transaction hash and add it to the filter. This particular
// trasaction is the first transaction in block 310,000 of the main // trasaction is the first transaction in block 310,000 of the main
// bitcoin block chain. // bitcoin block chain.
txHashStr := "fd611c56ca0d378cdcd16244b45c2ba9588da3adac367c4ef43e808b280b8a45" txHashStr := "fd611c56ca0d378cdcd16244b45c2ba9588da3adac367c4ef43e808b280b8a45"
txHash, err := btcwire.NewShaHashFromStr(txHashStr) txHash, err := wire.NewShaHashFromStr(txHashStr)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return return

View file

@ -10,8 +10,8 @@ import (
"sync" "sync"
"github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/btcsuite/btcwire"
) )
// ln2Squared is simply the square of the natural log of 2. // ln2Squared is simply the square of the natural log of 2.
@ -30,7 +30,7 @@ func minUint32(a, b uint32) uint32 {
// filter data. // filter data.
type Filter struct { type Filter struct {
mtx sync.Mutex mtx sync.Mutex
msgFilterLoad *btcwire.MsgFilterLoad msgFilterLoad *wire.MsgFilterLoad
} }
// NewFilter creates a new bloom filter instance, mainly to be used by SPV // 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, // For more information on what values to use for both elements and fprate,
// see https://en.wikipedia.org/wiki/Bloom_filter. // 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. // Massage the false positive rate to sane values.
if fprate > 1.0 { if fprate > 1.0 {
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. // 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. // Then clamp it to the maximum filter size and convert to bytes.
dataLen := uint32(-1 * float64(elements) * math.Log(fprate) / ln2Squared) 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 // Calculate the number of hash functions based on the size of the
// filter calculated above and the number of elements. // 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) // Equivalent to k = (m/n) * ln(2)
// Then clamp it to the maximum allowed hash funcs. // Then clamp it to the maximum allowed hash funcs.
hashFuncs := uint32(float64(dataLen*8) / float64(elements) * math.Ln2) hashFuncs := uint32(float64(dataLen*8) / float64(elements) * math.Ln2)
hashFuncs = minUint32(hashFuncs, btcwire.MaxFilterLoadHashFuncs) hashFuncs = minUint32(hashFuncs, wire.MaxFilterLoadHashFuncs)
data := make([]byte, dataLen) data := make([]byte, dataLen)
msg := btcwire.NewMsgFilterLoad(data, hashFuncs, tweak, flags) msg := wire.NewMsgFilterLoad(data, hashFuncs, tweak, flags)
return &Filter{ return &Filter{
msgFilterLoad: msg, 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 // LoadFilter creates a new Filter instance with the given underlying
// btcwire.MsgFilterLoad. // wire.MsgFilterLoad.
func LoadFilter(filter *btcwire.MsgFilterLoad) *Filter { func LoadFilter(filter *wire.MsgFilterLoad) *Filter {
return &Filter{ return &Filter{
msgFilterLoad: filter, msgFilterLoad: filter,
} }
@ -96,7 +96,7 @@ func (bf *Filter) IsLoaded() bool {
// Reload loads a new filter replacing any existing filter. // Reload loads a new filter replacing any existing filter.
// //
// This function is safe for concurrent access. // 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.mtx.Lock()
bf.msgFilterLoad = filter bf.msgFilterLoad = filter
bf.mtx.Unlock() bf.mtx.Unlock()
@ -164,11 +164,11 @@ func (bf *Filter) Matches(data []byte) bool {
// outpoint and false if it definitely does not. // outpoint and false if it definitely does not.
// //
// This function MUST be called with the filter lock held. // 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 // Serialize
var buf [btcwire.HashSize + 4]byte var buf [wire.HashSize + 4]byte
copy(buf[:], outpoint.Hash.Bytes()) 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[:]) return bf.matches(buf[:])
} }
@ -177,7 +177,7 @@ func (bf *Filter) matchesOutPoint(outpoint *btcwire.OutPoint) bool {
// outpoint and false if it definitely does not. // outpoint and false if it definitely does not.
// //
// This function is safe for concurrent access. // 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() bf.mtx.Lock()
match := bf.matchesOutPoint(outpoint) match := bf.matchesOutPoint(outpoint)
bf.mtx.Unlock() bf.mtx.Unlock()
@ -214,10 +214,10 @@ func (bf *Filter) Add(data []byte) {
bf.mtx.Unlock() 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. // 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.mtx.Lock()
bf.add(sha.Bytes()) bf.add(sha.Bytes())
bf.mtx.Unlock() bf.mtx.Unlock()
@ -226,11 +226,11 @@ func (bf *Filter) AddShaHash(sha *btcwire.ShaHash) {
// addOutPoint adds the passed transaction outpoint to the bloom filter. // addOutPoint adds the passed transaction outpoint to the bloom filter.
// //
// This function MUST be called with the filter lock held. // 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 // Serialize
var buf [btcwire.HashSize + 4]byte var buf [wire.HashSize + 4]byte
copy(buf[:], outpoint.Hash.Bytes()) copy(buf[:], outpoint.Hash.Bytes())
binary.LittleEndian.PutUint32(buf[btcwire.HashSize:], outpoint.Index) binary.LittleEndian.PutUint32(buf[wire.HashSize:], outpoint.Index)
bf.add(buf[:]) bf.add(buf[:])
} }
@ -238,7 +238,7 @@ func (bf *Filter) addOutPoint(outpoint *btcwire.OutPoint) {
// AddOutPoint adds the passed transaction outpoint to the bloom filter. // AddOutPoint adds the passed transaction outpoint to the bloom filter.
// //
// This function is safe for concurrent access. // 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.mtx.Lock()
bf.addOutPoint(outpoint) bf.addOutPoint(outpoint)
bf.mtx.Unlock() bf.mtx.Unlock()
@ -249,15 +249,15 @@ func (bf *Filter) AddOutPoint(outpoint *btcwire.OutPoint) {
// script. // script.
// //
// This function MUST be called with the filter lock held. // 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 { switch bf.msgFilterLoad.Flags {
case btcwire.BloomUpdateAll: case wire.BloomUpdateAll:
outpoint := btcwire.NewOutPoint(outHash, outIdx) outpoint := wire.NewOutPoint(outHash, outIdx)
bf.addOutPoint(outpoint) bf.addOutPoint(outpoint)
case btcwire.BloomUpdateP2PubkeyOnly: case wire.BloomUpdateP2PubkeyOnly:
class := txscript.GetScriptClass(pkScript) class := txscript.GetScriptClass(pkScript)
if class == txscript.PubKeyTy || class == txscript.MultiSigTy { if class == txscript.PubKeyTy || class == txscript.MultiSigTy {
outpoint := btcwire.NewOutPoint(outHash, outIdx) outpoint := wire.NewOutPoint(outHash, outIdx)
bf.addOutPoint(outpoint) bf.addOutPoint(outpoint)
} }
} }
@ -341,11 +341,11 @@ func (bf *Filter) MatchTxAndUpdate(tx *btcutil.Tx) bool {
return match return match
} }
// MsgFilterLoad returns the underlying btcwire.MsgFilterLoad for the bloom // MsgFilterLoad returns the underlying wire.MsgFilterLoad for the bloom
// filter. // filter.
// //
// This function is safe for concurrent access. // This function is safe for concurrent access.
func (bf *Filter) MsgFilterLoad() *btcwire.MsgFilterLoad { func (bf *Filter) MsgFilterLoad() *wire.MsgFilterLoad {
bf.mtx.Lock() bf.mtx.Lock()
msg := bf.msgFilterLoad msg := bf.msgFilterLoad
bf.mtx.Unlock() bf.mtx.Unlock()

View file

@ -9,23 +9,23 @@ import (
"encoding/hex" "encoding/hex"
"testing" "testing"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/btcsuite/btcutil/bloom" "github.com/btcsuite/btcutil/bloom"
"github.com/btcsuite/btcwire"
) )
// TestFilterLarge ensures a maximum sized filter can be created. // TestFilterLarge ensures a maximum sized filter can be created.
func TestFilterLarge(t *testing.T) { func TestFilterLarge(t *testing.T) {
f := bloom.NewFilter(100000000, 0, 0.01, btcwire.BloomUpdateNone) f := bloom.NewFilter(100000000, 0, 0.01, wire.BloomUpdateNone)
if len(f.MsgFilterLoad().Filter) > btcwire.MaxFilterLoadFilterSize { if len(f.MsgFilterLoad().Filter) > wire.MaxFilterLoadFilterSize {
t.Errorf("TestFilterLarge test failed: %d > %d", 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. // TestFilterLoad ensures loading and unloading of a filter pass.
func TestFilterLoad(t *testing.T) { func TestFilterLoad(t *testing.T) {
merkle := btcwire.MsgFilterLoad{} merkle := wire.MsgFilterLoad{}
f := bloom.LoadFilter(&merkle) f := bloom.LoadFilter(&merkle)
if !f.IsLoaded() { if !f.IsLoaded() {
@ -55,7 +55,7 @@ func TestFilterInsert(t *testing.T) {
{"b9300670b4c5366e95b2699e8b18bc75e5f729c5", true}, {"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 { for i, test := range tests {
data, err := hex.DecodeString(test.hex) data, err := hex.DecodeString(test.hex)
@ -82,7 +82,7 @@ func TestFilterInsert(t *testing.T) {
} }
got := bytes.NewBuffer(nil) got := bytes.NewBuffer(nil)
err = f.MsgFilterLoad().BtcEncode(got, btcwire.ProtocolVersion) err = f.MsgFilterLoad().BtcEncode(got, wire.ProtocolVersion)
if err != nil { if err != nil {
t.Errorf("TestFilterInsert BtcDecode failed: %v\n", err) t.Errorf("TestFilterInsert BtcDecode failed: %v\n", err)
return return
@ -109,7 +109,7 @@ func TestFilterInsertWithTweak(t *testing.T) {
{"b9300670b4c5366e95b2699e8b18bc75e5f729c5", true}, {"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 { for i, test := range tests {
data, err := hex.DecodeString(test.hex) data, err := hex.DecodeString(test.hex)
@ -135,7 +135,7 @@ func TestFilterInsertWithTweak(t *testing.T) {
return return
} }
got := bytes.NewBuffer(nil) got := bytes.NewBuffer(nil)
err = f.MsgFilterLoad().BtcEncode(got, btcwire.ProtocolVersion) err = f.MsgFilterLoad().BtcEncode(got, wire.ProtocolVersion)
if err != nil { if err != nil {
t.Errorf("TestFilterInsertWithTweak BtcDecode failed: %v\n", err) t.Errorf("TestFilterInsertWithTweak BtcDecode failed: %v\n", err)
return return
@ -159,7 +159,7 @@ func TestFilterInsertKey(t *testing.T) {
return 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(wif.SerializePubKey())
f.Add(btcutil.Hash160(wif.SerializePubKey())) f.Add(btcutil.Hash160(wif.SerializePubKey()))
@ -169,7 +169,7 @@ func TestFilterInsertKey(t *testing.T) {
return return
} }
got := bytes.NewBuffer(nil) got := bytes.NewBuffer(nil)
err = f.MsgFilterLoad().BtcEncode(got, btcwire.ProtocolVersion) err = f.MsgFilterLoad().BtcEncode(got, wire.ProtocolVersion)
if err != nil { if err != nil {
t.Errorf("TestFilterInsertWithTweak BtcDecode failed: %v\n", err) t.Errorf("TestFilterInsertWithTweak BtcDecode failed: %v\n", err)
return return
@ -238,9 +238,9 @@ func TestFilterBloomMatch(t *testing.T) {
return return
} }
f := bloom.NewFilter(10, 0, 0.000001, btcwire.BloomUpdateAll) f := bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll)
inputStr := "b4749f017444b051c44dfd2720e88f314ff94f3dd6d56d40ef65854fcd7fff6b" inputStr := "b4749f017444b051c44dfd2720e88f314ff94f3dd6d56d40ef65854fcd7fff6b"
sha, err := btcwire.NewShaHashFromStr(inputStr) sha, err := wire.NewShaHashFromStr(inputStr)
if err != nil { if err != nil {
t.Errorf("TestFilterBloomMatch NewShaHashFromStr failed: %v\n", err) t.Errorf("TestFilterBloomMatch NewShaHashFromStr failed: %v\n", err)
return return
@ -250,7 +250,7 @@ func TestFilterBloomMatch(t *testing.T) {
t.Errorf("TestFilterBloomMatch didn't match sha %s", inputStr) 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" inputStr = "6bff7fcd4f8565ef406dd5d63d4ff94f318fe82027fd4dc451b04474019f74b4"
shaBytes, err := hex.DecodeString(inputStr) shaBytes, err := hex.DecodeString(inputStr)
if err != nil { if err != nil {
@ -262,7 +262,7 @@ func TestFilterBloomMatch(t *testing.T) {
t.Errorf("TestFilterBloomMatch didn't match sha %s", inputStr) 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" + inputStr = "30450220070aca44506c5cef3a16ed519d7c3c39f8aab192c4e1c90d065" +
"f37b8a4af6141022100a8e160b856c2d43d27d8fba71e5aef6405b8643" + "f37b8a4af6141022100a8e160b856c2d43d27d8fba71e5aef6405b8643" +
"ac4cb7cb3c462aced7f14711a01" "ac4cb7cb3c462aced7f14711a01"
@ -276,7 +276,7 @@ func TestFilterBloomMatch(t *testing.T) {
t.Errorf("TestFilterBloomMatch didn't match input signature %s", inputStr) 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" + inputStr = "046d11fee51b0e60666d5049a9101a72741df480b96ee26488a4d3466b95" +
"c9a40ac5eeef87e10a5cd336c19a84565f80fa6c547957b7700ff4dfbdefe" + "c9a40ac5eeef87e10a5cd336c19a84565f80fa6c547957b7700ff4dfbdefe" +
"76036c339" "76036c339"
@ -290,7 +290,7 @@ func TestFilterBloomMatch(t *testing.T) {
t.Errorf("TestFilterBloomMatch didn't match input pubkey %s", inputStr) 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" inputStr = "04943fdd508053c75000106d3bc6e2754dbcff19"
shaBytes, err = hex.DecodeString(inputStr) shaBytes, err = hex.DecodeString(inputStr)
if err != nil { if err != nil {
@ -305,7 +305,7 @@ func TestFilterBloomMatch(t *testing.T) {
t.Errorf("TestFilterBloomMatch spendingTx didn't match output address %s", inputStr) 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" inputStr = "a266436d2965547608b9e15d9032a7b9d64fa431"
shaBytes, err = hex.DecodeString(inputStr) shaBytes, err = hex.DecodeString(inputStr)
if err != nil { if err != nil {
@ -317,22 +317,22 @@ func TestFilterBloomMatch(t *testing.T) {
t.Errorf("TestFilterBloomMatch didn't match output address %s", inputStr) 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" inputStr = "90c122d70786e899529d71dbeba91ba216982fb6ba58f3bdaab65e73b7e9260b"
sha, err = btcwire.NewShaHashFromStr(inputStr) sha, err = wire.NewShaHashFromStr(inputStr)
if err != nil { if err != nil {
t.Errorf("TestFilterBloomMatch NewShaHashFromStr failed: %v\n", err) t.Errorf("TestFilterBloomMatch NewShaHashFromStr failed: %v\n", err)
return return
} }
outpoint := btcwire.NewOutPoint(sha, 0) outpoint := wire.NewOutPoint(sha, 0)
f.AddOutPoint(outpoint) f.AddOutPoint(outpoint)
if !f.MatchTxAndUpdate(tx) { if !f.MatchTxAndUpdate(tx) {
t.Errorf("TestFilterBloomMatch didn't match outpoint %s", inputStr) 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" inputStr = "00000009e784f32f62ef849763d4f45b98e07ba658647343b915ff832b110436"
sha, err = btcwire.NewShaHashFromStr(inputStr) sha, err = wire.NewShaHashFromStr(inputStr)
if err != nil { if err != nil {
t.Errorf("TestFilterBloomMatch NewShaHashFromStr failed: %v\n", err) t.Errorf("TestFilterBloomMatch NewShaHashFromStr failed: %v\n", err)
return return
@ -342,7 +342,7 @@ func TestFilterBloomMatch(t *testing.T) {
t.Errorf("TestFilterBloomMatch matched sha %s", inputStr) 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" inputStr = "0000006d2965547608b9e15d9032a7b9d64fa431"
shaBytes, err = hex.DecodeString(inputStr) shaBytes, err = hex.DecodeString(inputStr)
if err != nil { if err != nil {
@ -354,27 +354,27 @@ func TestFilterBloomMatch(t *testing.T) {
t.Errorf("TestFilterBloomMatch matched address %s", inputStr) 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" inputStr = "90c122d70786e899529d71dbeba91ba216982fb6ba58f3bdaab65e73b7e9260b"
sha, err = btcwire.NewShaHashFromStr(inputStr) sha, err = wire.NewShaHashFromStr(inputStr)
if err != nil { if err != nil {
t.Errorf("TestFilterBloomMatch NewShaHashFromStr failed: %v\n", err) t.Errorf("TestFilterBloomMatch NewShaHashFromStr failed: %v\n", err)
return return
} }
outpoint = btcwire.NewOutPoint(sha, 1) outpoint = wire.NewOutPoint(sha, 1)
f.AddOutPoint(outpoint) f.AddOutPoint(outpoint)
if f.MatchTxAndUpdate(tx) { if f.MatchTxAndUpdate(tx) {
t.Errorf("TestFilterBloomMatch matched outpoint %s", inputStr) 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" inputStr = "000000d70786e899529d71dbeba91ba216982fb6ba58f3bdaab65e73b7e9260b"
sha, err = btcwire.NewShaHashFromStr(inputStr) sha, err = wire.NewShaHashFromStr(inputStr)
if err != nil { if err != nil {
t.Errorf("TestFilterBloomMatch NewShaHashFromStr failed: %v\n", err) t.Errorf("TestFilterBloomMatch NewShaHashFromStr failed: %v\n", err)
return return
} }
outpoint = btcwire.NewOutPoint(sha, 0) outpoint = wire.NewOutPoint(sha, 0)
f.AddOutPoint(outpoint) f.AddOutPoint(outpoint)
if f.MatchTxAndUpdate(tx) { if f.MatchTxAndUpdate(tx) {
t.Errorf("TestFilterBloomMatch matched outpoint %s", inputStr) t.Errorf("TestFilterBloomMatch matched outpoint %s", inputStr)
@ -382,7 +382,7 @@ func TestFilterBloomMatch(t *testing.T) {
} }
func TestFilterInsertUpdateNone(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 // Add the generation pubkey
inputStr := "04eaafc2314def4ca98ac970241bcab022b9c1e1f4ea423a20f134c" + inputStr := "04eaafc2314def4ca98ac970241bcab022b9c1e1f4ea423a20f134c" +
@ -405,12 +405,12 @@ func TestFilterInsertUpdateNone(t *testing.T) {
f.Add(inputBytes) f.Add(inputBytes)
inputStr = "147caa76786596590baa4e98f5d9f48b86c7765e489f7a6ff3360fe5c674360b" inputStr = "147caa76786596590baa4e98f5d9f48b86c7765e489f7a6ff3360fe5c674360b"
sha, err := btcwire.NewShaHashFromStr(inputStr) sha, err := wire.NewShaHashFromStr(inputStr)
if err != nil { if err != nil {
t.Errorf("TestFilterInsertUpdateNone NewShaHashFromStr failed: %v", err) t.Errorf("TestFilterInsertUpdateNone NewShaHashFromStr failed: %v", err)
return return
} }
outpoint := btcwire.NewOutPoint(sha, 0) outpoint := wire.NewOutPoint(sha, 0)
if f.MatchesOutPoint(outpoint) { if f.MatchesOutPoint(outpoint) {
t.Errorf("TestFilterInsertUpdateNone matched outpoint %s", inputStr) t.Errorf("TestFilterInsertUpdateNone matched outpoint %s", inputStr)
@ -418,12 +418,12 @@ func TestFilterInsertUpdateNone(t *testing.T) {
} }
inputStr = "02981fa052f0481dbc5868f4fc2166035a10f27a03cfd2de67326471df5bc041" inputStr = "02981fa052f0481dbc5868f4fc2166035a10f27a03cfd2de67326471df5bc041"
sha, err = btcwire.NewShaHashFromStr(inputStr) sha, err = wire.NewShaHashFromStr(inputStr)
if err != nil { if err != nil {
t.Errorf("TestFilterInsertUpdateNone NewShaHashFromStr failed: %v", err) t.Errorf("TestFilterInsertUpdateNone NewShaHashFromStr failed: %v", err)
return return
} }
outpoint = btcwire.NewOutPoint(sha, 0) outpoint = wire.NewOutPoint(sha, 0)
if f.MatchesOutPoint(outpoint) { if f.MatchesOutPoint(outpoint) {
t.Errorf("TestFilterInsertUpdateNone matched outpoint %s", inputStr) t.Errorf("TestFilterInsertUpdateNone matched outpoint %s", inputStr)
@ -530,7 +530,7 @@ func TestFilterInsertP2PubKeyOnly(t *testing.T) {
return return
} }
f := bloom.NewFilter(10, 0, 0.000001, btcwire.BloomUpdateP2PubkeyOnly) f := bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateP2PubkeyOnly)
// Generation pubkey // Generation pubkey
inputStr := "04eaafc2314def4ca98ac970241bcab022b9c1e1f4ea423a20f134c" + inputStr := "04eaafc2314def4ca98ac970241bcab022b9c1e1f4ea423a20f134c" +
@ -557,12 +557,12 @@ func TestFilterInsertP2PubKeyOnly(t *testing.T) {
// We should match the generation pubkey // We should match the generation pubkey
inputStr = "147caa76786596590baa4e98f5d9f48b86c7765e489f7a6ff3360fe5c674360b" inputStr = "147caa76786596590baa4e98f5d9f48b86c7765e489f7a6ff3360fe5c674360b"
sha, err := btcwire.NewShaHashFromStr(inputStr) sha, err := wire.NewShaHashFromStr(inputStr)
if err != nil { if err != nil {
t.Errorf("TestMerkleBlockP2PubKeyOnly NewShaHashFromStr failed: %v", err) t.Errorf("TestMerkleBlockP2PubKeyOnly NewShaHashFromStr failed: %v", err)
return return
} }
outpoint := btcwire.NewOutPoint(sha, 0) outpoint := wire.NewOutPoint(sha, 0)
if !f.MatchesOutPoint(outpoint) { if !f.MatchesOutPoint(outpoint) {
t.Errorf("TestMerkleBlockP2PubKeyOnly didn't match the generation "+ t.Errorf("TestMerkleBlockP2PubKeyOnly didn't match the generation "+
"outpoint %s", inputStr) "outpoint %s", inputStr)
@ -571,12 +571,12 @@ func TestFilterInsertP2PubKeyOnly(t *testing.T) {
// We should not match the 4th transaction, which is not p2pk // We should not match the 4th transaction, which is not p2pk
inputStr = "02981fa052f0481dbc5868f4fc2166035a10f27a03cfd2de67326471df5bc041" inputStr = "02981fa052f0481dbc5868f4fc2166035a10f27a03cfd2de67326471df5bc041"
sha, err = btcwire.NewShaHashFromStr(inputStr) sha, err = wire.NewShaHashFromStr(inputStr)
if err != nil { if err != nil {
t.Errorf("TestMerkleBlockP2PubKeyOnly NewShaHashFromStr failed: %v", err) t.Errorf("TestMerkleBlockP2PubKeyOnly NewShaHashFromStr failed: %v", err)
return return
} }
outpoint = btcwire.NewOutPoint(sha, 0) outpoint = wire.NewOutPoint(sha, 0)
if f.MatchesOutPoint(outpoint) { if f.MatchesOutPoint(outpoint) {
t.Errorf("TestMerkleBlockP2PubKeyOnly matched outpoint %s", inputStr) t.Errorf("TestMerkleBlockP2PubKeyOnly matched outpoint %s", inputStr)
return return
@ -584,7 +584,7 @@ func TestFilterInsertP2PubKeyOnly(t *testing.T) {
} }
func TestFilterReload(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()) bFilter := bloom.LoadFilter(f.MsgFilterLoad())
if bFilter.MsgFilterLoad() == nil { if bFilter.MsgFilterLoad() == nil {

View file

@ -6,16 +6,16 @@ package bloom
import ( import (
"github.com/btcsuite/btcd/blockchain" "github.com/btcsuite/btcd/blockchain"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/btcsuite/btcwire"
) )
// merkleBlock is used to house intermediate information needed to generate a // 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 { type merkleBlock struct {
numTx uint32 numTx uint32
allHashes []*btcwire.ShaHash allHashes []*wire.ShaHash
finalHashes []*btcwire.ShaHash finalHashes []*wire.ShaHash
matchedBits []byte matchedBits []byte
bits []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 // calcHash returns the hash for a sub-tree given a depth-first height and
// node position. // node position.
func (m *merkleBlock) calcHash(height, pos uint32) *btcwire.ShaHash { func (m *merkleBlock) calcHash(height, pos uint32) *wire.ShaHash {
if height == 0 { if height == 0 {
return m.allHashes[pos] return m.allHashes[pos]
} }
var right *btcwire.ShaHash var right *wire.ShaHash
left := m.calcHash(height-1, pos*2) left := m.calcHash(height-1, pos*2)
if pos*2+1 < m.calcTreeWidth(height-1) { if pos*2+1 < m.calcTreeWidth(height-1) {
right = m.calcHash(height-1, pos*2+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. // 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())) numTx := uint32(len(block.Transactions()))
mBlock := merkleBlock{ mBlock := merkleBlock{
numTx: numTx, numTx: numTx,
allHashes: make([]*btcwire.ShaHash, 0, numTx), allHashes: make([]*wire.ShaHash, 0, numTx),
matchedBits: make([]byte, 0, numTx), matchedBits: make([]byte, 0, numTx),
} }
// Find and keep track of any transactions that match the filter. // Find and keep track of any transactions that match the filter.
var matchedHashes []*btcwire.ShaHash var matchedHashes []*wire.ShaHash
for _, tx := range block.Transactions() { for _, tx := range block.Transactions() {
if filter.MatchTxAndUpdate(tx) { if filter.MatchTxAndUpdate(tx) {
mBlock.matchedBits = append(mBlock.matchedBits, 0x01) mBlock.matchedBits = append(mBlock.matchedBits, 0x01)
@ -108,10 +108,10 @@ func NewMerkleBlock(block *btcutil.Block, filter *Filter) (*btcwire.MsgMerkleBlo
mBlock.traverseAndBuild(height, 0) mBlock.traverseAndBuild(height, 0)
// Create and return the merkle block. // Create and return the merkle block.
msgMerkleBlock := btcwire.MsgMerkleBlock{ msgMerkleBlock := wire.MsgMerkleBlock{
Header: block.MsgBlock().Header, Header: block.MsgBlock().Header,
Transactions: uint32(mBlock.numTx), 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), Flags: make([]byte, (len(mBlock.bits)+7)/8),
} }
for _, sha := range mBlock.finalHashes { for _, sha := range mBlock.finalHashes {

View file

@ -9,9 +9,9 @@ import (
"encoding/hex" "encoding/hex"
"testing" "testing"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/btcsuite/btcutil/bloom" "github.com/btcsuite/btcutil/bloom"
"github.com/btcsuite/btcwire"
) )
func TestMerkleBlock3(t *testing.T) { func TestMerkleBlock3(t *testing.T) {
@ -34,10 +34,10 @@ func TestMerkleBlock3(t *testing.T) {
return return
} }
f := bloom.NewFilter(10, 0, 0.000001, btcwire.BloomUpdateAll) f := bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll)
inputStr := "63194f18be0af63f2c6bc9dc0f777cbefed3d9415c4af83f3ee3a3d669c00cb5" inputStr := "63194f18be0af63f2c6bc9dc0f777cbefed3d9415c4af83f3ee3a3d669c00cb5"
sha, err := btcwire.NewShaHashFromStr(inputStr) sha, err := wire.NewShaHashFromStr(inputStr)
if err != nil { if err != nil {
t.Errorf("TestMerkleBlock3 NewShaHashFromStr failed: %v", err) t.Errorf("TestMerkleBlock3 NewShaHashFromStr failed: %v", err)
return return
@ -59,7 +59,7 @@ func TestMerkleBlock3(t *testing.T) {
} }
got := bytes.NewBuffer(nil) got := bytes.NewBuffer(nil)
err = mBlock.BtcEncode(got, btcwire.ProtocolVersion) err = mBlock.BtcEncode(got, wire.ProtocolVersion)
if err != nil { if err != nil {
t.Errorf("TestMerkleBlock3 BtcEncode failed: %v", err) t.Errorf("TestMerkleBlock3 BtcEncode failed: %v", err)
return return

View file

@ -5,13 +5,13 @@ import (
"errors" "errors"
"sort" "sort"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/btcsuite/btcwire"
) )
// Coin represents a spendable transaction outpoint // Coin represents a spendable transaction outpoint
type Coin interface { type Coin interface {
Hash() *btcwire.ShaHash Hash() *wire.ShaHash
Index() uint32 Index() uint32
Value() btcutil.Amount Value() btcutil.Amount
PkScript() []byte PkScript() []byte
@ -118,19 +118,19 @@ func (cs *CoinSet) removeElement(e *list.Element) Coin {
} }
// NewMsgTxWithInputCoins takes the coins in the CoinSet and makes them // NewMsgTxWithInputCoins takes the coins in the CoinSet and makes them
// the inputs to a new btcwire.MsgTx which is returned. // the inputs to a new wire.MsgTx which is returned.
func NewMsgTxWithInputCoins(inputCoins Coins) *btcwire.MsgTx { func NewMsgTxWithInputCoins(inputCoins Coins) *wire.MsgTx {
msgTx := btcwire.NewMsgTx() msgTx := wire.NewMsgTx()
coins := inputCoins.Coins() coins := inputCoins.Coins()
msgTx.TxIn = make([]*btcwire.TxIn, len(coins)) msgTx.TxIn = make([]*wire.TxIn, len(coins))
for i, coin := range coins { for i, coin := range coins {
msgTx.TxIn[i] = &btcwire.TxIn{ msgTx.TxIn[i] = &wire.TxIn{
PreviousOutPoint: btcwire.OutPoint{ PreviousOutPoint: wire.OutPoint{
Hash: *coin.Hash(), Hash: *coin.Hash(),
Index: coin.Index(), Index: coin.Index(),
}, },
SignatureScript: nil, SignatureScript: nil,
Sequence: btcwire.MaxTxInSequenceNum, Sequence: wire.MaxTxInSequenceNum,
} }
} }
return msgTx return msgTx
@ -354,7 +354,7 @@ type SimpleCoin struct {
var _ Coin = &SimpleCoin{} var _ Coin = &SimpleCoin{}
// Hash returns the hash value of the transaction on which the Coin is an output // 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() return c.Tx.Sha()
} }
@ -364,7 +364,7 @@ func (c *SimpleCoin) Index() uint32 {
} }
// txOut returns the TxOut of the transaction the Coin represents // 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] return c.Tx.MsgTx().TxOut[c.TxIndex]
} }

View file

@ -6,30 +6,30 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/btcsuite/btcutil/coinset" "github.com/btcsuite/btcutil/coinset"
"github.com/btcsuite/btcwire"
"github.com/btcsuite/fastsha256" "github.com/btcsuite/fastsha256"
) )
type TestCoin struct { type TestCoin struct {
TxHash *btcwire.ShaHash TxHash *wire.ShaHash
TxIndex uint32 TxIndex uint32
TxValue btcutil.Amount TxValue btcutil.Amount
TxNumConfs int64 TxNumConfs int64
} }
func (c *TestCoin) Hash() *btcwire.ShaHash { return c.TxHash } func (c *TestCoin) Hash() *wire.ShaHash { return c.TxHash }
func (c *TestCoin) Index() uint32 { return c.TxIndex } func (c *TestCoin) Index() uint32 { return c.TxIndex }
func (c *TestCoin) Value() btcutil.Amount { return c.TxValue } func (c *TestCoin) Value() btcutil.Amount { return c.TxValue }
func (c *TestCoin) PkScript() []byte { return nil } func (c *TestCoin) PkScript() []byte { return nil }
func (c *TestCoin) NumConfs() int64 { return c.TxNumConfs } func (c *TestCoin) NumConfs() int64 { return c.TxNumConfs }
func (c *TestCoin) ValueAge() int64 { return int64(c.TxValue) * c.TxNumConfs } func (c *TestCoin) ValueAge() int64 { return int64(c.TxValue) * c.TxNumConfs }
func NewCoin(index int64, value btcutil.Amount, numConfs int64) coinset.Coin { func NewCoin(index int64, value btcutil.Amount, numConfs int64) coinset.Coin {
h := fastsha256.New() h := fastsha256.New()
h.Write([]byte(fmt.Sprintf("%d", index))) h.Write([]byte(fmt.Sprintf("%d", index)))
hash, _ := btcwire.NewShaHash(h.Sum(nil)) hash, _ := wire.NewShaHash(h.Sum(nil))
c := &TestCoin{ c := &TestCoin{
TxHash: hash, TxHash: hash,
TxIndex: 0, TxIndex: 0,

View file

@ -18,11 +18,11 @@ import (
"fmt" "fmt"
"math/big" "math/big"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcec" "github.com/btcsuite/btcec"
"github.com/btcsuite/btcnet" "github.com/btcsuite/btcnet"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/btcsuite/btcutil/base58" "github.com/btcsuite/btcutil/base58"
"github.com/btcsuite/btcwire"
) )
const ( const (
@ -385,7 +385,7 @@ func (k *ExtendedKey) String() string {
serializedBytes = append(serializedBytes, k.pubKeyBytes()...) serializedBytes = append(serializedBytes, k.pubKeyBytes()...)
} }
checkSum := btcwire.DoubleSha256(serializedBytes)[:4] checkSum := wire.DoubleSha256(serializedBytes)[:4]
serializedBytes = append(serializedBytes, checkSum...) serializedBytes = append(serializedBytes, checkSum...)
return base58.Encode(serializedBytes) 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. // Split the payload and checksum up and ensure the checksum matches.
payload := decoded[:len(decoded)-4] payload := decoded[:len(decoded)-4]
checkSum := decoded[len(decoded)-4:] checkSum := decoded[len(decoded)-4:]
expectedCheckSum := btcwire.DoubleSha256(payload)[:4] expectedCheckSum := wire.DoubleSha256(payload)[:4]
if !bytes.Equal(checkSum, expectedCheckSum) { if !bytes.Equal(checkSum, expectedCheckSum) {
return nil, ErrBadChecksum return nil, ErrBadChecksum
} }

22
tx.go
View file

@ -8,7 +8,7 @@ import (
"bytes" "bytes"
"io" "io"
"github.com/btcsuite/btcwire" "github.com/btcsuite/btcd/wire"
) )
// TxIndexUnknown is the value returned for a transaction index that is unknown. // 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 // transaction on its first access so subsequent accesses don't have to repeat
// the relatively expensive hashing operations. // the relatively expensive hashing operations.
type Tx struct { type Tx struct {
msgTx *btcwire.MsgTx // Underlying MsgTx msgTx *wire.MsgTx // Underlying MsgTx
txSha *btcwire.ShaHash // Cached transaction hash txSha *wire.ShaHash // Cached transaction hash
txIndex int // Position within a block or TxIndexUnknown txIndex int // Position within a block or TxIndexUnknown
} }
// MsgTx returns the underlying btcwire.MsgTx for the transaction. // MsgTx returns the underlying wire.MsgTx for the transaction.
func (t *Tx) MsgTx() *btcwire.MsgTx { func (t *Tx) MsgTx() *wire.MsgTx {
// Return the cached transaction. // Return the cached transaction.
return t.msgTx return t.msgTx
} }
// Sha returns the hash of the transaction. This is equivalent to // 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. // 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. // Return the cached hash if it has already been generated.
if t.txSha != nil { if t.txSha != nil {
return t.txSha 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 // NewTx returns a new instance of a bitcoin transaction given an underlying
// btcwire.MsgTx. See Tx. // wire.MsgTx. See Tx.
func NewTx(msgTx *btcwire.MsgTx) *Tx { func NewTx(msgTx *wire.MsgTx) *Tx {
return &Tx{ return &Tx{
msgTx: msgTx, msgTx: msgTx,
txIndex: TxIndexUnknown, txIndex: TxIndexUnknown,
@ -81,7 +81,7 @@ func NewTxFromBytes(serializedTx []byte) (*Tx, error) {
// Reader to deserialize the transaction. See Tx. // Reader to deserialize the transaction. See Tx.
func NewTxFromReader(r io.Reader) (*Tx, error) { func NewTxFromReader(r io.Reader) (*Tx, error) {
// Deserialize the bytes into a MsgTx. // Deserialize the bytes into a MsgTx.
var msgTx btcwire.MsgTx var msgTx wire.MsgTx
err := msgTx.Deserialize(r) err := msgTx.Deserialize(r)
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -10,8 +10,8 @@ import (
"reflect" "reflect"
"testing" "testing"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/btcsuite/btcwire"
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
) )
@ -36,7 +36,7 @@ func TestTx(t *testing.T) {
// Hash for block 100,000 transaction 0. // Hash for block 100,000 transaction 0.
wantShaStr := "8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87" wantShaStr := "8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87"
wantSha, err := btcwire.NewShaHashFromStr(wantShaStr) wantSha, err := wire.NewShaHashFromStr(wantShaStr)
if err != nil { if err != nil {
t.Errorf("NewShaHashFromStr: %v", err) t.Errorf("NewShaHashFromStr: %v", err)
} }

6
wif.go
View file

@ -8,10 +8,10 @@ import (
"bytes" "bytes"
"errors" "errors"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcec" "github.com/btcsuite/btcec"
"github.com/btcsuite/btcnet" "github.com/btcsuite/btcnet"
"github.com/btcsuite/btcutil/base58" "github.com/btcsuite/btcutil/base58"
"github.com/btcsuite/btcwire"
) )
// ErrMalformedPrivateKey describes an error where a WIF-encoded private // ErrMalformedPrivateKey describes an error where a WIF-encoded private
@ -110,7 +110,7 @@ func DecodeWIF(wif string) (*WIF, error) {
} else { } else {
tosum = decoded[:1+btcec.PrivKeyBytesLen] tosum = decoded[:1+btcec.PrivKeyBytesLen]
} }
cksum := btcwire.DoubleSha256(tosum)[:4] cksum := wire.DoubleSha256(tosum)[:4]
if !bytes.Equal(cksum, decoded[decodedLen-4:]) { if !bytes.Equal(cksum, decoded[decodedLen-4:]) {
return nil, ErrChecksumMismatch return nil, ErrChecksumMismatch
} }
@ -142,7 +142,7 @@ func (w *WIF) String() string {
if w.CompressPubKey { if w.CompressPubKey {
a = append(a, compressMagic) a = append(a, compressMagic)
} }
cksum := btcwire.DoubleSha256(a)[:4] cksum := wire.DoubleSha256(a)[:4]
a = append(a, cksum...) a = append(a, cksum...)
return base58.Encode(a) return base58.Encode(a)
} }