Update btcnet path import paths to new location.
This commit is contained in:
parent
56fe089f4e
commit
1324fa1fad
9 changed files with 106 additions and 106 deletions
30
address.go
30
address.go
|
@ -10,8 +10,8 @@ import (
|
|||
|
||||
"golang.org/x/crypto/ripemd160"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcec"
|
||||
"github.com/btcsuite/btcnet"
|
||||
"github.com/btcsuite/btcutil/base58"
|
||||
)
|
||||
|
||||
|
@ -23,7 +23,7 @@ var (
|
|||
// ErrUnknownAddressType describes an error where an address can not
|
||||
// decoded as a specific address type due to the string encoding
|
||||
// begining with an identifier byte unknown to any standard or
|
||||
// registered (via btcnet.Register) network.
|
||||
// registered (via chaincfg.Register) network.
|
||||
ErrUnknownAddressType = errors.New("unknown address type")
|
||||
|
||||
// ErrAddressCollision describes an error where an address can not
|
||||
|
@ -72,7 +72,7 @@ type Address interface {
|
|||
|
||||
// IsForNet returns whether or not the address is associated with the
|
||||
// passed bitcoin network.
|
||||
IsForNet(*btcnet.Params) bool
|
||||
IsForNet(*chaincfg.Params) bool
|
||||
}
|
||||
|
||||
// DecodeAddress decodes the string encoding of an address and returns
|
||||
|
@ -81,7 +81,7 @@ type Address interface {
|
|||
// The bitcoin network the address is associated with is extracted if possible.
|
||||
// When the address does not encode the network, such as in the case of a raw
|
||||
// public key, the address will be associated with the passed defaultNet.
|
||||
func DecodeAddress(addr string, defaultNet *btcnet.Params) (Address, error) {
|
||||
func DecodeAddress(addr string, defaultNet *chaincfg.Params) (Address, error) {
|
||||
// Serialized public keys are either 65 bytes (130 hex chars) if
|
||||
// uncompressed/hybrid or 33 bytes (66 hex chars) if compressed.
|
||||
if len(addr) == 130 || len(addr) == 66 {
|
||||
|
@ -102,8 +102,8 @@ func DecodeAddress(addr string, defaultNet *btcnet.Params) (Address, error) {
|
|||
}
|
||||
switch len(decoded) {
|
||||
case ripemd160.Size: // P2PKH or P2SH
|
||||
isP2PKH := btcnet.IsPubKeyHashAddrID(netID)
|
||||
isP2SH := btcnet.IsScriptHashAddrID(netID)
|
||||
isP2PKH := chaincfg.IsPubKeyHashAddrID(netID)
|
||||
isP2SH := chaincfg.IsScriptHashAddrID(netID)
|
||||
switch hash160 := decoded; {
|
||||
case isP2PKH && isP2SH:
|
||||
return nil, ErrAddressCollision
|
||||
|
@ -127,9 +127,9 @@ type AddressPubKeyHash struct {
|
|||
netID byte
|
||||
}
|
||||
|
||||
// NewAddressPubKeyHash returns a new AddressPubKeyHash. pkHash must
|
||||
// be 20 bytes.
|
||||
func NewAddressPubKeyHash(pkHash []byte, net *btcnet.Params) (*AddressPubKeyHash, error) {
|
||||
// NewAddressPubKeyHash returns a new AddressPubKeyHash. pkHash mustbe 20
|
||||
// bytes.
|
||||
func NewAddressPubKeyHash(pkHash []byte, net *chaincfg.Params) (*AddressPubKeyHash, error) {
|
||||
return newAddressPubKeyHash(pkHash, net.PubKeyHashAddrID)
|
||||
}
|
||||
|
||||
|
@ -163,7 +163,7 @@ func (a *AddressPubKeyHash) ScriptAddress() []byte {
|
|||
|
||||
// IsForNet returns whether or not the pay-to-pubkey-hash address is associated
|
||||
// with the passed bitcoin network.
|
||||
func (a *AddressPubKeyHash) IsForNet(net *btcnet.Params) bool {
|
||||
func (a *AddressPubKeyHash) IsForNet(net *chaincfg.Params) bool {
|
||||
return a.netID == net.PubKeyHashAddrID
|
||||
}
|
||||
|
||||
|
@ -189,14 +189,14 @@ type AddressScriptHash struct {
|
|||
}
|
||||
|
||||
// NewAddressScriptHash returns a new AddressScriptHash.
|
||||
func NewAddressScriptHash(serializedScript []byte, net *btcnet.Params) (*AddressScriptHash, error) {
|
||||
func NewAddressScriptHash(serializedScript []byte, net *chaincfg.Params) (*AddressScriptHash, error) {
|
||||
scriptHash := Hash160(serializedScript)
|
||||
return newAddressScriptHashFromHash(scriptHash, net.ScriptHashAddrID)
|
||||
}
|
||||
|
||||
// NewAddressScriptHashFromHash returns a new AddressScriptHash. scriptHash
|
||||
// must be 20 bytes.
|
||||
func NewAddressScriptHashFromHash(scriptHash []byte, net *btcnet.Params) (*AddressScriptHash, error) {
|
||||
func NewAddressScriptHashFromHash(scriptHash []byte, net *chaincfg.Params) (*AddressScriptHash, error) {
|
||||
return newAddressScriptHashFromHash(scriptHash, net.ScriptHashAddrID)
|
||||
}
|
||||
|
||||
|
@ -230,7 +230,7 @@ func (a *AddressScriptHash) ScriptAddress() []byte {
|
|||
|
||||
// IsForNet returns whether or not the pay-to-script-hash address is associated
|
||||
// with the passed bitcoin network.
|
||||
func (a *AddressScriptHash) IsForNet(net *btcnet.Params) bool {
|
||||
func (a *AddressScriptHash) IsForNet(net *chaincfg.Params) bool {
|
||||
return a.netID == net.ScriptHashAddrID
|
||||
}
|
||||
|
||||
|
@ -275,7 +275,7 @@ type AddressPubKey struct {
|
|||
// NewAddressPubKey returns a new AddressPubKey which represents a pay-to-pubkey
|
||||
// address. The serializedPubKey parameter must be a valid pubkey and can be
|
||||
// uncompressed, compressed, or hybrid.
|
||||
func NewAddressPubKey(serializedPubKey []byte, net *btcnet.Params) (*AddressPubKey, error) {
|
||||
func NewAddressPubKey(serializedPubKey []byte, net *chaincfg.Params) (*AddressPubKey, error) {
|
||||
pubKey, err := btcec.ParsePubKey(serializedPubKey, btcec.S256())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -338,7 +338,7 @@ func (a *AddressPubKey) ScriptAddress() []byte {
|
|||
|
||||
// IsForNet returns whether or not the pay-to-pubkey address is associated
|
||||
// with the passed bitcoin network.
|
||||
func (a *AddressPubKey) IsForNet(net *btcnet.Params) bool {
|
||||
func (a *AddressPubKey) IsForNet(net *chaincfg.Params) bool {
|
||||
return a.pubKeyHashID == net.PubKeyHashAddrID
|
||||
}
|
||||
|
||||
|
|
104
address_test.go
104
address_test.go
|
@ -13,8 +13,8 @@ import (
|
|||
|
||||
"golang.org/x/crypto/ripemd160"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcnet"
|
||||
"github.com/btcsuite/btcutil"
|
||||
)
|
||||
|
||||
|
@ -29,7 +29,7 @@ func TestAddresses(t *testing.T) {
|
|||
valid bool
|
||||
result btcutil.Address
|
||||
f func() (btcutil.Address, error)
|
||||
net *btcnet.Params
|
||||
net *chaincfg.Params
|
||||
}{
|
||||
// Positive P2PKH tests.
|
||||
{
|
||||
|
@ -41,14 +41,14 @@ func TestAddresses(t *testing.T) {
|
|||
[ripemd160.Size]byte{
|
||||
0xe3, 0x4c, 0xce, 0x70, 0xc8, 0x63, 0x73, 0x27, 0x3e, 0xfc,
|
||||
0xc5, 0x4c, 0xe7, 0xd2, 0xa4, 0x91, 0xbb, 0x4a, 0x0e, 0x84},
|
||||
btcnet.MainNetParams.PubKeyHashAddrID),
|
||||
chaincfg.MainNetParams.PubKeyHashAddrID),
|
||||
f: func() (btcutil.Address, error) {
|
||||
pkHash := []byte{
|
||||
0xe3, 0x4c, 0xce, 0x70, 0xc8, 0x63, 0x73, 0x27, 0x3e, 0xfc,
|
||||
0xc5, 0x4c, 0xe7, 0xd2, 0xa4, 0x91, 0xbb, 0x4a, 0x0e, 0x84}
|
||||
return btcutil.NewAddressPubKeyHash(pkHash, &btcnet.MainNetParams)
|
||||
return btcutil.NewAddressPubKeyHash(pkHash, &chaincfg.MainNetParams)
|
||||
},
|
||||
net: &btcnet.MainNetParams,
|
||||
net: &chaincfg.MainNetParams,
|
||||
},
|
||||
{
|
||||
name: "mainnet p2pkh 2",
|
||||
|
@ -59,14 +59,14 @@ func TestAddresses(t *testing.T) {
|
|||
[ripemd160.Size]byte{
|
||||
0x0e, 0xf0, 0x30, 0x10, 0x7f, 0xd2, 0x6e, 0x0b, 0x6b, 0xf4,
|
||||
0x05, 0x12, 0xbc, 0xa2, 0xce, 0xb1, 0xdd, 0x80, 0xad, 0xaa},
|
||||
btcnet.MainNetParams.PubKeyHashAddrID),
|
||||
chaincfg.MainNetParams.PubKeyHashAddrID),
|
||||
f: func() (btcutil.Address, error) {
|
||||
pkHash := []byte{
|
||||
0x0e, 0xf0, 0x30, 0x10, 0x7f, 0xd2, 0x6e, 0x0b, 0x6b, 0xf4,
|
||||
0x05, 0x12, 0xbc, 0xa2, 0xce, 0xb1, 0xdd, 0x80, 0xad, 0xaa}
|
||||
return btcutil.NewAddressPubKeyHash(pkHash, &btcnet.MainNetParams)
|
||||
return btcutil.NewAddressPubKeyHash(pkHash, &chaincfg.MainNetParams)
|
||||
},
|
||||
net: &btcnet.MainNetParams,
|
||||
net: &chaincfg.MainNetParams,
|
||||
},
|
||||
{
|
||||
name: "testnet p2pkh",
|
||||
|
@ -77,14 +77,14 @@ func TestAddresses(t *testing.T) {
|
|||
[ripemd160.Size]byte{
|
||||
0x78, 0xb3, 0x16, 0xa0, 0x86, 0x47, 0xd5, 0xb7, 0x72, 0x83,
|
||||
0xe5, 0x12, 0xd3, 0x60, 0x3f, 0x1f, 0x1c, 0x8d, 0xe6, 0x8f},
|
||||
btcnet.TestNet3Params.PubKeyHashAddrID),
|
||||
chaincfg.TestNet3Params.PubKeyHashAddrID),
|
||||
f: func() (btcutil.Address, error) {
|
||||
pkHash := []byte{
|
||||
0x78, 0xb3, 0x16, 0xa0, 0x86, 0x47, 0xd5, 0xb7, 0x72, 0x83,
|
||||
0xe5, 0x12, 0xd3, 0x60, 0x3f, 0x1f, 0x1c, 0x8d, 0xe6, 0x8f}
|
||||
return btcutil.NewAddressPubKeyHash(pkHash, &btcnet.TestNet3Params)
|
||||
return btcutil.NewAddressPubKeyHash(pkHash, &chaincfg.TestNet3Params)
|
||||
},
|
||||
net: &btcnet.TestNet3Params,
|
||||
net: &chaincfg.TestNet3Params,
|
||||
},
|
||||
|
||||
// Negative P2PKH tests.
|
||||
|
@ -97,7 +97,7 @@ func TestAddresses(t *testing.T) {
|
|||
0x00, 0x0e, 0xf0, 0x30, 0x10, 0x7f, 0xd2, 0x6e, 0x0b, 0x6b,
|
||||
0xf4, 0x05, 0x12, 0xbc, 0xa2, 0xce, 0xb1, 0xdd, 0x80, 0xad,
|
||||
0xaa}
|
||||
return btcutil.NewAddressPubKeyHash(pkHash, &btcnet.MainNetParams)
|
||||
return btcutil.NewAddressPubKeyHash(pkHash, &chaincfg.MainNetParams)
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -119,7 +119,7 @@ func TestAddresses(t *testing.T) {
|
|||
[ripemd160.Size]byte{
|
||||
0xf8, 0x15, 0xb0, 0x36, 0xd9, 0xbb, 0xbc, 0xe5, 0xe9, 0xf2,
|
||||
0xa0, 0x0a, 0xbd, 0x1b, 0xf3, 0xdc, 0x91, 0xe9, 0x55, 0x10},
|
||||
btcnet.MainNetParams.ScriptHashAddrID),
|
||||
chaincfg.MainNetParams.ScriptHashAddrID),
|
||||
f: func() (btcutil.Address, error) {
|
||||
script := []byte{
|
||||
0x52, 0x41, 0x04, 0x91, 0xbb, 0xa2, 0x51, 0x09, 0x12, 0xa5,
|
||||
|
@ -143,9 +143,9 @@ func TestAddresses(t *testing.T) {
|
|||
0xdb, 0xfb, 0x1e, 0x75, 0x4e, 0x35, 0xfa, 0x1c, 0x78, 0x44,
|
||||
0xc4, 0x1f, 0x32, 0x2a, 0x18, 0x63, 0xd4, 0x62, 0x13, 0x53,
|
||||
0xae}
|
||||
return btcutil.NewAddressScriptHash(script, &btcnet.MainNetParams)
|
||||
return btcutil.NewAddressScriptHash(script, &chaincfg.MainNetParams)
|
||||
},
|
||||
net: &btcnet.MainNetParams,
|
||||
net: &chaincfg.MainNetParams,
|
||||
},
|
||||
{
|
||||
// Taken from transactions:
|
||||
|
@ -159,14 +159,14 @@ func TestAddresses(t *testing.T) {
|
|||
[ripemd160.Size]byte{
|
||||
0xe8, 0xc3, 0x00, 0xc8, 0x79, 0x86, 0xef, 0xa8, 0x4c, 0x37,
|
||||
0xc0, 0x51, 0x99, 0x29, 0x01, 0x9e, 0xf8, 0x6e, 0xb5, 0xb4},
|
||||
btcnet.MainNetParams.ScriptHashAddrID),
|
||||
chaincfg.MainNetParams.ScriptHashAddrID),
|
||||
f: func() (btcutil.Address, error) {
|
||||
hash := []byte{
|
||||
0xe8, 0xc3, 0x00, 0xc8, 0x79, 0x86, 0xef, 0xa8, 0x4c, 0x37,
|
||||
0xc0, 0x51, 0x99, 0x29, 0x01, 0x9e, 0xf8, 0x6e, 0xb5, 0xb4}
|
||||
return btcutil.NewAddressScriptHashFromHash(hash, &btcnet.MainNetParams)
|
||||
return btcutil.NewAddressScriptHashFromHash(hash, &chaincfg.MainNetParams)
|
||||
},
|
||||
net: &btcnet.MainNetParams,
|
||||
net: &chaincfg.MainNetParams,
|
||||
},
|
||||
{
|
||||
// Taken from bitcoind base58_keys_valid.
|
||||
|
@ -178,14 +178,14 @@ func TestAddresses(t *testing.T) {
|
|||
[ripemd160.Size]byte{
|
||||
0xc5, 0x79, 0x34, 0x2c, 0x2c, 0x4c, 0x92, 0x20, 0x20, 0x5e,
|
||||
0x2c, 0xdc, 0x28, 0x56, 0x17, 0x04, 0x0c, 0x92, 0x4a, 0x0a},
|
||||
btcnet.TestNet3Params.ScriptHashAddrID),
|
||||
chaincfg.TestNet3Params.ScriptHashAddrID),
|
||||
f: func() (btcutil.Address, error) {
|
||||
hash := []byte{
|
||||
0xc5, 0x79, 0x34, 0x2c, 0x2c, 0x4c, 0x92, 0x20, 0x20, 0x5e,
|
||||
0x2c, 0xdc, 0x28, 0x56, 0x17, 0x04, 0x0c, 0x92, 0x4a, 0x0a}
|
||||
return btcutil.NewAddressScriptHashFromHash(hash, &btcnet.TestNet3Params)
|
||||
return btcutil.NewAddressScriptHashFromHash(hash, &chaincfg.TestNet3Params)
|
||||
},
|
||||
net: &btcnet.TestNet3Params,
|
||||
net: &chaincfg.TestNet3Params,
|
||||
},
|
||||
|
||||
// Negative P2SH tests.
|
||||
|
@ -198,7 +198,7 @@ func TestAddresses(t *testing.T) {
|
|||
0x00, 0xf8, 0x15, 0xb0, 0x36, 0xd9, 0xbb, 0xbc, 0xe5, 0xe9,
|
||||
0xf2, 0xa0, 0x0a, 0xbd, 0x1b, 0xf3, 0xdc, 0x91, 0xe9, 0x55,
|
||||
0x10}
|
||||
return btcutil.NewAddressScriptHashFromHash(hash, &btcnet.MainNetParams)
|
||||
return btcutil.NewAddressScriptHashFromHash(hash, &chaincfg.MainNetParams)
|
||||
},
|
||||
},
|
||||
|
||||
|
@ -214,16 +214,16 @@ func TestAddresses(t *testing.T) {
|
|||
0x69, 0xc2, 0xe7, 0x79, 0x01, 0x57, 0x3d, 0x8d, 0x79, 0x03,
|
||||
0xc3, 0xeb, 0xec, 0x3a, 0x95, 0x77, 0x24, 0x89, 0x5d, 0xca,
|
||||
0x52, 0xc6, 0xb4},
|
||||
btcutil.PKFCompressed, btcnet.MainNetParams.PubKeyHashAddrID),
|
||||
btcutil.PKFCompressed, chaincfg.MainNetParams.PubKeyHashAddrID),
|
||||
f: func() (btcutil.Address, error) {
|
||||
serializedPubKey := []byte{
|
||||
0x02, 0x19, 0x2d, 0x74, 0xd0, 0xcb, 0x94, 0x34, 0x4c, 0x95,
|
||||
0x69, 0xc2, 0xe7, 0x79, 0x01, 0x57, 0x3d, 0x8d, 0x79, 0x03,
|
||||
0xc3, 0xeb, 0xec, 0x3a, 0x95, 0x77, 0x24, 0x89, 0x5d, 0xca,
|
||||
0x52, 0xc6, 0xb4}
|
||||
return btcutil.NewAddressPubKey(serializedPubKey, &btcnet.MainNetParams)
|
||||
return btcutil.NewAddressPubKey(serializedPubKey, &chaincfg.MainNetParams)
|
||||
},
|
||||
net: &btcnet.MainNetParams,
|
||||
net: &chaincfg.MainNetParams,
|
||||
},
|
||||
{
|
||||
name: "mainnet p2pk compressed (0x03)",
|
||||
|
@ -236,16 +236,16 @@ func TestAddresses(t *testing.T) {
|
|||
0xe9, 0x86, 0xe8, 0x84, 0x18, 0x5c, 0x61, 0xcf, 0x43, 0xe0,
|
||||
0x01, 0xf9, 0x13, 0x7f, 0x23, 0xc2, 0xc4, 0x09, 0x27, 0x3e,
|
||||
0xb1, 0x6e, 0x65},
|
||||
btcutil.PKFCompressed, btcnet.MainNetParams.PubKeyHashAddrID),
|
||||
btcutil.PKFCompressed, chaincfg.MainNetParams.PubKeyHashAddrID),
|
||||
f: func() (btcutil.Address, error) {
|
||||
serializedPubKey := []byte{
|
||||
0x03, 0xb0, 0xbd, 0x63, 0x42, 0x34, 0xab, 0xbb, 0x1b, 0xa1,
|
||||
0xe9, 0x86, 0xe8, 0x84, 0x18, 0x5c, 0x61, 0xcf, 0x43, 0xe0,
|
||||
0x01, 0xf9, 0x13, 0x7f, 0x23, 0xc2, 0xc4, 0x09, 0x27, 0x3e,
|
||||
0xb1, 0x6e, 0x65}
|
||||
return btcutil.NewAddressPubKey(serializedPubKey, &btcnet.MainNetParams)
|
||||
return btcutil.NewAddressPubKey(serializedPubKey, &chaincfg.MainNetParams)
|
||||
},
|
||||
net: &btcnet.MainNetParams,
|
||||
net: &chaincfg.MainNetParams,
|
||||
},
|
||||
{
|
||||
name: "mainnet p2pk uncompressed (0x04)",
|
||||
|
@ -262,7 +262,7 @@ func TestAddresses(t *testing.T) {
|
|||
0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b,
|
||||
0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43,
|
||||
0xf6, 0x56, 0xb4, 0x12, 0xa3},
|
||||
btcutil.PKFUncompressed, btcnet.MainNetParams.PubKeyHashAddrID),
|
||||
btcutil.PKFUncompressed, chaincfg.MainNetParams.PubKeyHashAddrID),
|
||||
f: func() (btcutil.Address, error) {
|
||||
serializedPubKey := []byte{
|
||||
0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b,
|
||||
|
@ -272,9 +272,9 @@ func TestAddresses(t *testing.T) {
|
|||
0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b,
|
||||
0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43,
|
||||
0xf6, 0x56, 0xb4, 0x12, 0xa3}
|
||||
return btcutil.NewAddressPubKey(serializedPubKey, &btcnet.MainNetParams)
|
||||
return btcutil.NewAddressPubKey(serializedPubKey, &chaincfg.MainNetParams)
|
||||
},
|
||||
net: &btcnet.MainNetParams,
|
||||
net: &chaincfg.MainNetParams,
|
||||
},
|
||||
{
|
||||
name: "mainnet p2pk hybrid (0x06)",
|
||||
|
@ -291,7 +291,7 @@ func TestAddresses(t *testing.T) {
|
|||
0x96, 0x85, 0x26, 0x62, 0xce, 0x6a, 0x84, 0x7b, 0x19, 0x73,
|
||||
0x76, 0x83, 0x01, 0x60, 0xc6, 0xd2, 0xeb, 0x5e, 0x6a, 0x4c,
|
||||
0x44, 0xd3, 0x3f, 0x45, 0x3e},
|
||||
btcutil.PKFHybrid, btcnet.MainNetParams.PubKeyHashAddrID),
|
||||
btcutil.PKFHybrid, chaincfg.MainNetParams.PubKeyHashAddrID),
|
||||
f: func() (btcutil.Address, error) {
|
||||
serializedPubKey := []byte{
|
||||
0x06, 0x19, 0x2d, 0x74, 0xd0, 0xcb, 0x94, 0x34, 0x4c, 0x95,
|
||||
|
@ -301,9 +301,9 @@ func TestAddresses(t *testing.T) {
|
|||
0x96, 0x85, 0x26, 0x62, 0xce, 0x6a, 0x84, 0x7b, 0x19, 0x73,
|
||||
0x76, 0x83, 0x01, 0x60, 0xc6, 0xd2, 0xeb, 0x5e, 0x6a, 0x4c,
|
||||
0x44, 0xd3, 0x3f, 0x45, 0x3e}
|
||||
return btcutil.NewAddressPubKey(serializedPubKey, &btcnet.MainNetParams)
|
||||
return btcutil.NewAddressPubKey(serializedPubKey, &chaincfg.MainNetParams)
|
||||
},
|
||||
net: &btcnet.MainNetParams,
|
||||
net: &chaincfg.MainNetParams,
|
||||
},
|
||||
{
|
||||
name: "mainnet p2pk hybrid (0x07)",
|
||||
|
@ -320,7 +320,7 @@ func TestAddresses(t *testing.T) {
|
|||
0x8a, 0x7e, 0xf8, 0xbd, 0x3b, 0x3c, 0xfb, 0x1e, 0xdb, 0x71,
|
||||
0x17, 0xab, 0x65, 0x12, 0x9b, 0x8a, 0x2e, 0x68, 0x1f, 0x3c,
|
||||
0x1e, 0x09, 0x08, 0xef, 0x7b},
|
||||
btcutil.PKFHybrid, btcnet.MainNetParams.PubKeyHashAddrID),
|
||||
btcutil.PKFHybrid, chaincfg.MainNetParams.PubKeyHashAddrID),
|
||||
f: func() (btcutil.Address, error) {
|
||||
serializedPubKey := []byte{
|
||||
0x07, 0xb0, 0xbd, 0x63, 0x42, 0x34, 0xab, 0xbb, 0x1b, 0xa1,
|
||||
|
@ -330,9 +330,9 @@ func TestAddresses(t *testing.T) {
|
|||
0x8a, 0x7e, 0xf8, 0xbd, 0x3b, 0x3c, 0xfb, 0x1e, 0xdb, 0x71,
|
||||
0x17, 0xab, 0x65, 0x12, 0x9b, 0x8a, 0x2e, 0x68, 0x1f, 0x3c,
|
||||
0x1e, 0x09, 0x08, 0xef, 0x7b}
|
||||
return btcutil.NewAddressPubKey(serializedPubKey, &btcnet.MainNetParams)
|
||||
return btcutil.NewAddressPubKey(serializedPubKey, &chaincfg.MainNetParams)
|
||||
},
|
||||
net: &btcnet.MainNetParams,
|
||||
net: &chaincfg.MainNetParams,
|
||||
},
|
||||
{
|
||||
name: "testnet p2pk compressed (0x02)",
|
||||
|
@ -345,16 +345,16 @@ func TestAddresses(t *testing.T) {
|
|||
0x69, 0xc2, 0xe7, 0x79, 0x01, 0x57, 0x3d, 0x8d, 0x79, 0x03,
|
||||
0xc3, 0xeb, 0xec, 0x3a, 0x95, 0x77, 0x24, 0x89, 0x5d, 0xca,
|
||||
0x52, 0xc6, 0xb4},
|
||||
btcutil.PKFCompressed, btcnet.TestNet3Params.PubKeyHashAddrID),
|
||||
btcutil.PKFCompressed, chaincfg.TestNet3Params.PubKeyHashAddrID),
|
||||
f: func() (btcutil.Address, error) {
|
||||
serializedPubKey := []byte{
|
||||
0x02, 0x19, 0x2d, 0x74, 0xd0, 0xcb, 0x94, 0x34, 0x4c, 0x95,
|
||||
0x69, 0xc2, 0xe7, 0x79, 0x01, 0x57, 0x3d, 0x8d, 0x79, 0x03,
|
||||
0xc3, 0xeb, 0xec, 0x3a, 0x95, 0x77, 0x24, 0x89, 0x5d, 0xca,
|
||||
0x52, 0xc6, 0xb4}
|
||||
return btcutil.NewAddressPubKey(serializedPubKey, &btcnet.TestNet3Params)
|
||||
return btcutil.NewAddressPubKey(serializedPubKey, &chaincfg.TestNet3Params)
|
||||
},
|
||||
net: &btcnet.TestNet3Params,
|
||||
net: &chaincfg.TestNet3Params,
|
||||
},
|
||||
{
|
||||
name: "testnet p2pk compressed (0x03)",
|
||||
|
@ -367,16 +367,16 @@ func TestAddresses(t *testing.T) {
|
|||
0xe9, 0x86, 0xe8, 0x84, 0x18, 0x5c, 0x61, 0xcf, 0x43, 0xe0,
|
||||
0x01, 0xf9, 0x13, 0x7f, 0x23, 0xc2, 0xc4, 0x09, 0x27, 0x3e,
|
||||
0xb1, 0x6e, 0x65},
|
||||
btcutil.PKFCompressed, btcnet.TestNet3Params.PubKeyHashAddrID),
|
||||
btcutil.PKFCompressed, chaincfg.TestNet3Params.PubKeyHashAddrID),
|
||||
f: func() (btcutil.Address, error) {
|
||||
serializedPubKey := []byte{
|
||||
0x03, 0xb0, 0xbd, 0x63, 0x42, 0x34, 0xab, 0xbb, 0x1b, 0xa1,
|
||||
0xe9, 0x86, 0xe8, 0x84, 0x18, 0x5c, 0x61, 0xcf, 0x43, 0xe0,
|
||||
0x01, 0xf9, 0x13, 0x7f, 0x23, 0xc2, 0xc4, 0x09, 0x27, 0x3e,
|
||||
0xb1, 0x6e, 0x65}
|
||||
return btcutil.NewAddressPubKey(serializedPubKey, &btcnet.TestNet3Params)
|
||||
return btcutil.NewAddressPubKey(serializedPubKey, &chaincfg.TestNet3Params)
|
||||
},
|
||||
net: &btcnet.TestNet3Params,
|
||||
net: &chaincfg.TestNet3Params,
|
||||
},
|
||||
{
|
||||
name: "testnet p2pk uncompressed (0x04)",
|
||||
|
@ -393,7 +393,7 @@ func TestAddresses(t *testing.T) {
|
|||
0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b,
|
||||
0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43,
|
||||
0xf6, 0x56, 0xb4, 0x12, 0xa3},
|
||||
btcutil.PKFUncompressed, btcnet.TestNet3Params.PubKeyHashAddrID),
|
||||
btcutil.PKFUncompressed, chaincfg.TestNet3Params.PubKeyHashAddrID),
|
||||
f: func() (btcutil.Address, error) {
|
||||
serializedPubKey := []byte{
|
||||
0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b,
|
||||
|
@ -403,9 +403,9 @@ func TestAddresses(t *testing.T) {
|
|||
0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b,
|
||||
0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43,
|
||||
0xf6, 0x56, 0xb4, 0x12, 0xa3}
|
||||
return btcutil.NewAddressPubKey(serializedPubKey, &btcnet.TestNet3Params)
|
||||
return btcutil.NewAddressPubKey(serializedPubKey, &chaincfg.TestNet3Params)
|
||||
},
|
||||
net: &btcnet.TestNet3Params,
|
||||
net: &chaincfg.TestNet3Params,
|
||||
},
|
||||
{
|
||||
name: "testnet p2pk hybrid (0x06)",
|
||||
|
@ -422,7 +422,7 @@ func TestAddresses(t *testing.T) {
|
|||
0x96, 0x85, 0x26, 0x62, 0xce, 0x6a, 0x84, 0x7b, 0x19, 0x73,
|
||||
0x76, 0x83, 0x01, 0x60, 0xc6, 0xd2, 0xeb, 0x5e, 0x6a, 0x4c,
|
||||
0x44, 0xd3, 0x3f, 0x45, 0x3e},
|
||||
btcutil.PKFHybrid, btcnet.TestNet3Params.PubKeyHashAddrID),
|
||||
btcutil.PKFHybrid, chaincfg.TestNet3Params.PubKeyHashAddrID),
|
||||
f: func() (btcutil.Address, error) {
|
||||
serializedPubKey := []byte{
|
||||
0x06, 0x19, 0x2d, 0x74, 0xd0, 0xcb, 0x94, 0x34, 0x4c, 0x95,
|
||||
|
@ -432,9 +432,9 @@ func TestAddresses(t *testing.T) {
|
|||
0x96, 0x85, 0x26, 0x62, 0xce, 0x6a, 0x84, 0x7b, 0x19, 0x73,
|
||||
0x76, 0x83, 0x01, 0x60, 0xc6, 0xd2, 0xeb, 0x5e, 0x6a, 0x4c,
|
||||
0x44, 0xd3, 0x3f, 0x45, 0x3e}
|
||||
return btcutil.NewAddressPubKey(serializedPubKey, &btcnet.TestNet3Params)
|
||||
return btcutil.NewAddressPubKey(serializedPubKey, &chaincfg.TestNet3Params)
|
||||
},
|
||||
net: &btcnet.TestNet3Params,
|
||||
net: &chaincfg.TestNet3Params,
|
||||
},
|
||||
{
|
||||
name: "testnet p2pk hybrid (0x07)",
|
||||
|
@ -451,7 +451,7 @@ func TestAddresses(t *testing.T) {
|
|||
0x8a, 0x7e, 0xf8, 0xbd, 0x3b, 0x3c, 0xfb, 0x1e, 0xdb, 0x71,
|
||||
0x17, 0xab, 0x65, 0x12, 0x9b, 0x8a, 0x2e, 0x68, 0x1f, 0x3c,
|
||||
0x1e, 0x09, 0x08, 0xef, 0x7b},
|
||||
btcutil.PKFHybrid, btcnet.TestNet3Params.PubKeyHashAddrID),
|
||||
btcutil.PKFHybrid, chaincfg.TestNet3Params.PubKeyHashAddrID),
|
||||
f: func() (btcutil.Address, error) {
|
||||
serializedPubKey := []byte{
|
||||
0x07, 0xb0, 0xbd, 0x63, 0x42, 0x34, 0xab, 0xbb, 0x1b, 0xa1,
|
||||
|
@ -461,9 +461,9 @@ func TestAddresses(t *testing.T) {
|
|||
0x8a, 0x7e, 0xf8, 0xbd, 0x3b, 0x3c, 0xfb, 0x1e, 0xdb, 0x71,
|
||||
0x17, 0xab, 0x65, 0x12, 0x9b, 0x8a, 0x2e, 0x68, 0x1f, 0x3c,
|
||||
0x1e, 0x09, 0x08, 0xef, 0x7b}
|
||||
return btcutil.NewAddressPubKey(serializedPubKey, &btcnet.TestNet3Params)
|
||||
return btcutil.NewAddressPubKey(serializedPubKey, &chaincfg.TestNet3Params)
|
||||
},
|
||||
net: &btcnet.TestNet3Params,
|
||||
net: &chaincfg.TestNet3Params,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
2
doc.go
2
doc.go
|
@ -35,7 +35,7 @@ To decode/encode an address:
|
|||
addrString := "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962" +
|
||||
"e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d57" +
|
||||
"8a4c702b6bf11d5f"
|
||||
defaultNet := &btcnet.MainNetParams
|
||||
defaultNet := &chaincfg.MainNetParams
|
||||
addr, err := btcutil.DecodeAddress(addrString, defaultNet)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
|
|
@ -21,7 +21,7 @@ report. Package hdkeychain is licensed under the liberal ISC license.
|
|||
- Support for multi-layer derivation
|
||||
- Easy serialization and deserialization for both private and public extended
|
||||
keys
|
||||
- Support for custom networks by registering them with btcnet
|
||||
- Support for custom networks by registering them with chaincfg
|
||||
- Obtaining the underlying EC pubkeys, EC privkeys, and associated bitcoin
|
||||
addresses ties in seamlessly with existing btcec and btcutil types which
|
||||
provide powerful tools for working with them to do things like sign
|
||||
|
|
|
@ -7,7 +7,7 @@ package hdkeychain_test
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/btcsuite/btcnet"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcutil/hdkeychain"
|
||||
)
|
||||
|
||||
|
@ -118,12 +118,12 @@ func Example_defaultWalletLayout() {
|
|||
|
||||
// Get and show the address associated with the extended keys for the
|
||||
// main bitcoin network.
|
||||
acct0ExtAddr, err := acct0Ext10.Address(&btcnet.MainNetParams)
|
||||
acct0ExtAddr, err := acct0Ext10.Address(&chaincfg.MainNetParams)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
acct0IntAddr, err := acct0Int0.Address(&btcnet.MainNetParams)
|
||||
acct0IntAddr, err := acct0Int0.Address(&chaincfg.MainNetParams)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
|
|
|
@ -18,9 +18,9 @@ import (
|
|||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcec"
|
||||
"github.com/btcsuite/btcnet"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/btcsuite/btcutil/base58"
|
||||
)
|
||||
|
@ -321,7 +321,7 @@ func (k *ExtendedKey) Neuter() (*ExtendedKey, error) {
|
|||
}
|
||||
|
||||
// Get the associated public extended key version bytes.
|
||||
version, err := btcnet.HDPrivateKeyToPublicKeyID(k.version)
|
||||
version, err := chaincfg.HDPrivateKeyToPublicKeyID(k.version)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -354,7 +354,7 @@ func (k *ExtendedKey) ECPrivKey() (*btcec.PrivateKey, error) {
|
|||
|
||||
// Address converts the extended key to a standard bitcoin pay-to-pubkey-hash
|
||||
// address for the passed network.
|
||||
func (k *ExtendedKey) Address(net *btcnet.Params) (*btcutil.AddressPubKeyHash, error) {
|
||||
func (k *ExtendedKey) Address(net *chaincfg.Params) (*btcutil.AddressPubKeyHash, error) {
|
||||
pkHash := btcutil.Hash160(k.pubKeyBytes())
|
||||
return btcutil.NewAddressPubKeyHash(pkHash, net)
|
||||
}
|
||||
|
@ -392,14 +392,14 @@ func (k *ExtendedKey) String() string {
|
|||
|
||||
// IsForNet returns whether or not the extended key is associated with the
|
||||
// passed bitcoin network.
|
||||
func (k *ExtendedKey) IsForNet(net *btcnet.Params) bool {
|
||||
func (k *ExtendedKey) IsForNet(net *chaincfg.Params) bool {
|
||||
return bytes.Equal(k.version, net.HDPrivateKeyID[:]) ||
|
||||
bytes.Equal(k.version, net.HDPublicKeyID[:])
|
||||
}
|
||||
|
||||
// SetNet associates the extended key, and any child keys yet to be derived from
|
||||
// it, with the passed network.
|
||||
func (k *ExtendedKey) SetNet(net *btcnet.Params) {
|
||||
func (k *ExtendedKey) SetNet(net *chaincfg.Params) {
|
||||
if k.isPrivate {
|
||||
k.version = net.HDPrivateKeyID[:]
|
||||
} else {
|
||||
|
@ -465,7 +465,7 @@ func NewMaster(seed []byte) (*ExtendedKey, error) {
|
|||
}
|
||||
|
||||
parentFP := []byte{0x00, 0x00, 0x00, 0x00}
|
||||
return newExtendedKey(btcnet.MainNetParams.HDPrivateKeyID[:], secretKey,
|
||||
return newExtendedKey(chaincfg.MainNetParams.HDPrivateKeyID[:], secretKey,
|
||||
chainCode, parentFP, 0, 0, true), nil
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/btcsuite/btcnet"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcutil/hdkeychain"
|
||||
)
|
||||
|
||||
|
@ -432,7 +432,7 @@ func TestExtendedKeyAPI(t *testing.T) {
|
|||
continue
|
||||
}
|
||||
|
||||
addr, err := key.Address(&btcnet.MainNetParams)
|
||||
addr, err := key.Address(&chaincfg.MainNetParams)
|
||||
if err != nil {
|
||||
t.Errorf("Address #%d (%s): unexpected error: %v", i,
|
||||
test.name, err)
|
||||
|
@ -452,8 +452,8 @@ func TestNet(t *testing.T) {
|
|||
tests := []struct {
|
||||
name string
|
||||
key string
|
||||
origNet *btcnet.Params
|
||||
newNet *btcnet.Params
|
||||
origNet *chaincfg.Params
|
||||
newNet *chaincfg.Params
|
||||
newPriv string
|
||||
newPub string
|
||||
isPrivate bool
|
||||
|
@ -462,8 +462,8 @@ func TestNet(t *testing.T) {
|
|||
{
|
||||
name: "mainnet -> simnet",
|
||||
key: "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi",
|
||||
origNet: &btcnet.MainNetParams,
|
||||
newNet: &btcnet.SimNetParams,
|
||||
origNet: &chaincfg.MainNetParams,
|
||||
newNet: &chaincfg.SimNetParams,
|
||||
newPriv: "sprv8Erh3X3hFeKunvVdAGQQtambRPapECWiTDtvsTGdyrhzhbYgnSZajRRWbihzvq4AM4ivm6uso31VfKaukwJJUs3GYihXP8ebhMb3F2AHu3P",
|
||||
newPub: "spub4Tr3T2ab61tD1Qa6GHwRFiiKyRRJdfEZpSpXfqgFYCEyaPsqKysqHDjzSzMJSiUEGbcsG3w2SLMoTqn44B8x6u3MLRRkYfACTUBnHK79THk",
|
||||
isPrivate: true,
|
||||
|
@ -471,8 +471,8 @@ func TestNet(t *testing.T) {
|
|||
{
|
||||
name: "simnet -> mainnet",
|
||||
key: "sprv8Erh3X3hFeKunvVdAGQQtambRPapECWiTDtvsTGdyrhzhbYgnSZajRRWbihzvq4AM4ivm6uso31VfKaukwJJUs3GYihXP8ebhMb3F2AHu3P",
|
||||
origNet: &btcnet.SimNetParams,
|
||||
newNet: &btcnet.MainNetParams,
|
||||
origNet: &chaincfg.SimNetParams,
|
||||
newNet: &chaincfg.MainNetParams,
|
||||
newPriv: "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi",
|
||||
newPub: "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8",
|
||||
isPrivate: true,
|
||||
|
@ -480,8 +480,8 @@ func TestNet(t *testing.T) {
|
|||
{
|
||||
name: "mainnet -> regtest",
|
||||
key: "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi",
|
||||
origNet: &btcnet.MainNetParams,
|
||||
newNet: &btcnet.RegressionNetParams,
|
||||
origNet: &chaincfg.MainNetParams,
|
||||
newNet: &chaincfg.RegressionNetParams,
|
||||
newPriv: "tprv8ZgxMBicQKsPeDgjzdC36fs6bMjGApWDNLR9erAXMs5skhMv36j9MV5ecvfavji5khqjWaWSFhN3YcCUUdiKH6isR4Pwy3U5y5egddBr16m",
|
||||
newPub: "tpubD6NzVbkrYhZ4XgiXtGrdW5XDAPFCL9h7we1vwNCpn8tGbBcgfVYjXyhWo4E1xkh56hjod1RhGjxbaTLV3X4FyWuejifB9jusQ46QzG87VKp",
|
||||
isPrivate: true,
|
||||
|
@ -489,8 +489,8 @@ func TestNet(t *testing.T) {
|
|||
{
|
||||
name: "regtest -> mainnet",
|
||||
key: "tprv8ZgxMBicQKsPeDgjzdC36fs6bMjGApWDNLR9erAXMs5skhMv36j9MV5ecvfavji5khqjWaWSFhN3YcCUUdiKH6isR4Pwy3U5y5egddBr16m",
|
||||
origNet: &btcnet.RegressionNetParams,
|
||||
newNet: &btcnet.MainNetParams,
|
||||
origNet: &chaincfg.RegressionNetParams,
|
||||
newNet: &chaincfg.MainNetParams,
|
||||
newPriv: "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi",
|
||||
newPub: "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8",
|
||||
isPrivate: true,
|
||||
|
@ -500,32 +500,32 @@ func TestNet(t *testing.T) {
|
|||
{
|
||||
name: "mainnet -> simnet",
|
||||
key: "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8",
|
||||
origNet: &btcnet.MainNetParams,
|
||||
newNet: &btcnet.SimNetParams,
|
||||
origNet: &chaincfg.MainNetParams,
|
||||
newNet: &chaincfg.SimNetParams,
|
||||
newPub: "spub4Tr3T2ab61tD1Qa6GHwRFiiKyRRJdfEZpSpXfqgFYCEyaPsqKysqHDjzSzMJSiUEGbcsG3w2SLMoTqn44B8x6u3MLRRkYfACTUBnHK79THk",
|
||||
isPrivate: false,
|
||||
},
|
||||
{
|
||||
name: "simnet -> mainnet",
|
||||
key: "spub4Tr3T2ab61tD1Qa6GHwRFiiKyRRJdfEZpSpXfqgFYCEyaPsqKysqHDjzSzMJSiUEGbcsG3w2SLMoTqn44B8x6u3MLRRkYfACTUBnHK79THk",
|
||||
origNet: &btcnet.SimNetParams,
|
||||
newNet: &btcnet.MainNetParams,
|
||||
origNet: &chaincfg.SimNetParams,
|
||||
newNet: &chaincfg.MainNetParams,
|
||||
newPub: "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8",
|
||||
isPrivate: false,
|
||||
},
|
||||
{
|
||||
name: "mainnet -> regtest",
|
||||
key: "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8",
|
||||
origNet: &btcnet.MainNetParams,
|
||||
newNet: &btcnet.RegressionNetParams,
|
||||
origNet: &chaincfg.MainNetParams,
|
||||
newNet: &chaincfg.RegressionNetParams,
|
||||
newPub: "tpubD6NzVbkrYhZ4XgiXtGrdW5XDAPFCL9h7we1vwNCpn8tGbBcgfVYjXyhWo4E1xkh56hjod1RhGjxbaTLV3X4FyWuejifB9jusQ46QzG87VKp",
|
||||
isPrivate: false,
|
||||
},
|
||||
{
|
||||
name: "regtest -> mainnet",
|
||||
key: "tpubD6NzVbkrYhZ4XgiXtGrdW5XDAPFCL9h7we1vwNCpn8tGbBcgfVYjXyhWo4E1xkh56hjod1RhGjxbaTLV3X4FyWuejifB9jusQ46QzG87VKp",
|
||||
origNet: &btcnet.RegressionNetParams,
|
||||
newNet: &btcnet.MainNetParams,
|
||||
origNet: &chaincfg.RegressionNetParams,
|
||||
newNet: &chaincfg.MainNetParams,
|
||||
newPub: "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8",
|
||||
isPrivate: false,
|
||||
},
|
||||
|
@ -650,7 +650,7 @@ func TestErrors(t *testing.T) {
|
|||
key: "xbad4LfUL9eKmA66w2GJdVMqhvDmYGJpTGjWRAtjHqoUY17sGaymoMV9Cm3ocn9Ud6Hh2vLFVC7KSKCRVVrqc6dsEdsTjRV1WUmkK85YEUujAPX",
|
||||
err: nil,
|
||||
neuter: true,
|
||||
neuterErr: btcnet.ErrUnknownHDKeyID,
|
||||
neuterErr: chaincfg.ErrUnknownHDKeyID,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -743,7 +743,7 @@ func TestZero(t *testing.T) {
|
|||
}
|
||||
|
||||
wantAddr := "1HT7xU2Ngenf7D4yocz2SAcnNLW7rK8d4E"
|
||||
addr, err := key.Address(&btcnet.MainNetParams)
|
||||
addr, err := key.Address(&chaincfg.MainNetParams)
|
||||
if err != nil {
|
||||
t.Errorf("Addres s #%d (%s): unexpected error: %v", i,
|
||||
testName, err)
|
||||
|
|
6
wif.go
6
wif.go
|
@ -8,9 +8,9 @@ import (
|
|||
"bytes"
|
||||
"errors"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcec"
|
||||
"github.com/btcsuite/btcnet"
|
||||
"github.com/btcsuite/btcutil/base58"
|
||||
)
|
||||
|
||||
|
@ -49,7 +49,7 @@ type WIF struct {
|
|||
// as a string encoded in the Wallet Import Format. The compress argument
|
||||
// specifies whether the address intended to be imported or exported was created
|
||||
// by serializing the public key compressed rather than uncompressed.
|
||||
func NewWIF(privKey *btcec.PrivateKey, net *btcnet.Params, compress bool) (*WIF, error) {
|
||||
func NewWIF(privKey *btcec.PrivateKey, net *chaincfg.Params, compress bool) (*WIF, error) {
|
||||
if net == nil {
|
||||
return nil, errors.New("no network")
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ func NewWIF(privKey *btcec.PrivateKey, net *btcnet.Params, compress bool) (*WIF,
|
|||
|
||||
// IsForNet returns whether or not the decoded WIF structure is associated
|
||||
// with the passed bitcoin network.
|
||||
func (w *WIF) IsForNet(net *btcnet.Params) bool {
|
||||
func (w *WIF) IsForNet(net *chaincfg.Params) bool {
|
||||
return w.netID == net.PrivateKeyID
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ package btcutil_test
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcec"
|
||||
"github.com/btcsuite/btcnet"
|
||||
. "github.com/btcsuite/btcutil"
|
||||
)
|
||||
|
||||
|
@ -25,11 +25,11 @@ func TestEncodeDecodeWIF(t *testing.T) {
|
|||
0x4e, 0x39, 0x6f, 0xb5, 0xdc, 0x29, 0x5f, 0xe9,
|
||||
0x94, 0xb9, 0x67, 0x89, 0xb2, 0x1a, 0x03, 0x98})
|
||||
|
||||
wif1, err := NewWIF(priv1, &btcnet.MainNetParams, false)
|
||||
wif1, err := NewWIF(priv1, &chaincfg.MainNetParams, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wif2, err := NewWIF(priv2, &btcnet.TestNet3Params, true)
|
||||
wif2, err := NewWIF(priv2, &chaincfg.TestNet3Params, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue