Begin update to use btcnet.Params.

This is an intial pass at converting the btcwallet and deps codebases
to pass a network by their parameters, rather than by a magic number
to identify the network.  The parameters in params.go have been
updated to embed a *btcnet.Params, and all previous uses of cfg.Net()
have been replaced with activeNet.{Params,Net} (where activeNet is
the global var for the active network).

Although dependancy packages have not yet been updated from using
btcwire.BitcoinNet to btcnet.Params, the parameters are now accessible
at all callsites, and individual packages can be updated to use btcnet
without requiring updates in each external btc* package at once.

While here, the exported API for btcwallet internal library packages
(txstore and wallet) have been updated to pass full network parameters
rather than the btcwire definition of a network.
This commit is contained in:
Josh Rickmar 2014-05-22 21:16:50 -05:00
parent 987dc8f1c4
commit c3224f4fbc
12 changed files with 96 additions and 118 deletions

View file

@ -83,7 +83,7 @@ func (a *Account) AddressUsed(addr btcutil.Address) bool {
credits := r.Credits()
for _, c := range credits {
// Extract addresses from this output's pkScript.
_, addrs, _, err := c.Addresses(cfg.Net())
_, addrs, _, err := c.Addresses(activeNet.Params)
if err != nil {
continue
}
@ -145,7 +145,7 @@ func (a *Account) CalculateAddressBalance(addr btcutil.Address, confirms int) fl
if credit.Confirmed(confirms, bs.Height) {
// We only care about the case where len(addrs) == 1, and err
// will never be non-nil in that case
_, addrs, _, _ := credit.Addresses(cfg.Net())
_, addrs, _, _ := credit.Addresses(activeNet.Params)
if len(addrs) != 1 {
continue
}
@ -247,7 +247,7 @@ func (a *Account) ListAddressTransactions(pkHashes map[string]struct{}) (
for _, c := range r.Credits() {
// We only care about the case where len(addrs) == 1,
// and err will never be non-nil in that case.
_, addrs, _, _ := c.Addresses(cfg.Net())
_, addrs, _, _ := c.Addresses(activeNet.Params)
if len(addrs) != 1 {
continue
}
@ -391,7 +391,7 @@ func (a *Account) ImportPrivateKey(wif *btcutil.WIF, bs *wallet.BlockStamp,
// ExportToDirectory writes an account to a special export directory. Any
// previous files are overwritten.
func (a *Account) ExportToDirectory(dirBaseName string) error {
dir := filepath.Join(networkDir(cfg.Net()), dirBaseName)
dir := filepath.Join(networkDir(activeNet.Params), dirBaseName)
if err := checkCreateDir(dir); err != nil {
return err
}

View file

@ -170,7 +170,7 @@ var (
// openSavedAccount opens a named account from disk. If the wallet does not
// exist, errNoWallet is returned as an error.
func openSavedAccount(name string, cfg *config) (*Account, error) {
netdir := networkDir(cfg.Net())
netdir := networkDir(activeNet.Params)
if err := checkCreateDir(netdir); err != nil {
return nil, &walletOpenError{
Err: err.Error(),
@ -238,8 +238,8 @@ func openAccounts() *accountData {
// done for changing a wallet passphrase) and btcwallet closes after
// removing the network directory but before renaming the temporary
// directory.
netDir := networkDir(cfg.Net())
tmpNetDir := tmpNetworkDir(cfg.Net())
netDir := networkDir(activeNet.Params)
tmpNetDir := tmpNetworkDir(activeNet.Params)
if !fileExists(netDir) && fileExists(tmpNetDir) {
if err := Rename(tmpNetDir, netDir); err != nil {
log.Errorf("Cannot move temporary network dir: %v", err)
@ -617,7 +617,7 @@ func (am *AccountManager) CreateEncryptedWallet(passphrase []byte) error {
// Create new wallet in memory.
wlt, err := wallet.NewWallet("", "Default acccount", passphrase,
cfg.Net(), &bs, cfg.KeypoolSize)
activeNet.Params, &bs, cfg.KeypoolSize)
if err != nil {
return err
}
@ -826,7 +826,7 @@ func (am *AccountManager) ListUnspent(minconf, maxconf int,
continue
}
_, addrs, _, _ := credit.Addresses(cfg.Net())
_, addrs, _, _ := credit.Addresses(activeNet.Params)
if filter {
for _, addr := range addrs {
_, ok := addresses[addr.EncodeAddress()]

View file

@ -208,7 +208,7 @@ func loadConfig() (*config, []string, error) {
// Choose the active network params based on the mainnet net flag.
if cfg.MainNet {
activeNetParams = netParams(btcwire.MainNet)
activeNet = &mainNetParams
}
// Validate debug log level
@ -221,12 +221,11 @@ func loadConfig() (*config, []string, error) {
}
if cfg.RPCConnect == "" {
cfg.RPCConnect = activeNetParams.connect
cfg.RPCConnect = activeNet.connect
}
// Add default port to connect flag if missing.
cfg.RPCConnect = normalizeAddress(cfg.RPCConnect,
activeNetParams.btcdPort)
cfg.RPCConnect = normalizeAddress(cfg.RPCConnect, activeNet.btcdPort)
// If CAFile is unset, choose either the copy or local btcd cert.
if cfg.CAFile == "" {
@ -261,7 +260,7 @@ func loadConfig() (*config, []string, error) {
}
cfg.SvrListeners = make([]string, 0, len(addrs))
for _, addr := range addrs {
addr = net.JoinHostPort(addr, activeNetParams.svrPort)
addr = net.JoinHostPort(addr, activeNet.svrPort)
cfg.SvrListeners = append(cfg.SvrListeners, addr)
}
}
@ -269,7 +268,7 @@ func loadConfig() (*config, []string, error) {
// Add default port to all rpc listener addresses if needed and remove
// duplicate addresses.
cfg.SvrListeners = normalizeAddresses(cfg.SvrListeners,
activeNetParams.svrPort)
activeNet.svrPort)
// Expand environment variable and leading ~ for filepaths.
cfg.CAFile = cleanAndExpandPath(cfg.CAFile)
@ -288,13 +287,6 @@ func loadConfig() (*config, []string, error) {
return &cfg, remainingArgs, nil
}
func (c *config) Net() btcwire.BitcoinNet {
if cfg.MainNet {
return btcwire.MainNet
}
return btcwire.TestNet3
}
// validLogLevel returns whether or not logLevel is a valid debug log level.
func validLogLevel(logLevel string) bool {
switch logLevel {

View file

@ -20,25 +20,22 @@ import (
"bytes"
"errors"
"fmt"
"sort"
"sync"
"time"
"github.com/conformal/btcchain"
"github.com/conformal/btcscript"
"github.com/conformal/btcutil"
"github.com/conformal/btcwallet/txstore"
"github.com/conformal/btcwallet/wallet"
"github.com/conformal/btcwire"
"sort"
"sync"
"time"
)
// ErrInsufficientFunds represents an error where there are not enough
// funds from unspent tx outputs for a wallet to create a transaction.
var ErrInsufficientFunds = errors.New("insufficient funds")
// ErrUnknownBitcoinNet represents an error where the parsed or
// requested bitcoin network is invalid (neither mainnet nor testnet).
var ErrUnknownBitcoinNet = errors.New("unknown bitcoin network")
// ErrNonPositiveAmount represents an error where a bitcoin amount is
// not positive (either negative, or zero).
var ErrNonPositiveAmount = errors.New("amount is not positive")
@ -71,17 +68,9 @@ type CreatedTx struct {
// sort a slice of Utxos by their amount.
type ByAmount []*txstore.Credit
func (u ByAmount) Len() int {
return len(u)
}
func (u ByAmount) Less(i, j int) bool {
return u[i].Amount() < u[j].Amount()
}
func (u ByAmount) Swap(i, j int) {
u[i], u[j] = u[j], u[i]
}
func (u ByAmount) Len() int { return len(u) }
func (u ByAmount) Less(i, j int) bool { return u[i].Amount() < u[j].Amount() }
func (u ByAmount) Swap(i, j int) { u[i], u[j] = u[j], u[i] }
// selectInputs selects the minimum number possible of unspent
// outputs to use to create a new transaction that spends amt satoshis.
@ -165,7 +154,7 @@ func (a *Account) txToPairs(pairs map[string]btcutil.Amount,
// Add outputs to new tx.
for addrStr, amt := range pairs {
addr, err := btcutil.DecodeAddress(addrStr, cfg.Net())
addr, err := btcutil.DecodeAddress(addrStr, activeNet.Net)
if err != nil {
return nil, fmt.Errorf("cannot decode address: %s", err)
}
@ -244,7 +233,7 @@ func (a *Account) txToPairs(pairs map[string]btcutil.Amount,
msgtx.AddTxIn(btcwire.NewTxIn(ip.OutPoint(), nil))
}
for i, input := range inputs {
_, addrs, _, _ := input.Addresses(cfg.Net())
_, addrs, _, _ := input.Addresses(activeNet.Params)
if len(addrs) != 1 {
continue
}

View file

@ -18,27 +18,34 @@ package main
import (
"fmt"
"github.com/conformal/btcwire"
"io/ioutil"
"os"
"path/filepath"
"time"
"github.com/conformal/btcnet"
"github.com/conformal/btcwire"
)
// networkDir returns the directory name of a network directory to hold account
// files.
func networkDir(net btcwire.BitcoinNet) string {
var netname string
if net == btcwire.MainNet {
netname = "mainnet"
} else {
func networkDir(net *btcnet.Params) string {
netname := net.Name
// For now, we must always name the testnet data directory as "testnet"
// and not "testnet3" or any other version, as the btcnet testnet3
// paramaters will likely be switched to being named "testnet3" in the
// future. This is done to future proof that change, and an upgrade
// plan to move the testnet3 data directory can be worked out later.
if net.Net == btcwire.TestNet3 {
netname = "testnet"
}
return filepath.Join(cfg.DataDir, netname)
}
// tmpNetworkDir returns the temporary directory name for a given network.
func tmpNetworkDir(net btcwire.BitcoinNet) string {
func tmpNetworkDir(net *btcnet.Params) string {
return networkDir(net) + "_tmp"
}
@ -218,11 +225,11 @@ func (ds *DiskSyncer) Start() {
//
// This never returns and is should be called from a new goroutine.
func (ds *DiskSyncer) handler() {
netdir := networkDir(cfg.Net())
netdir := networkDir(activeNet.Params)
if err := checkCreateDir(netdir); err != nil {
log.Errorf("Unable to create or write to account directory: %v", err)
}
tmpnetdir := tmpNetworkDir(cfg.Net())
tmpnetdir := tmpNetworkDir(activeNet.Params)
const wait = 10 * time.Second
var timer <-chan time.Time

View file

@ -108,7 +108,7 @@ func NtfnRecvTx(n btcjson.Cmd) error {
// and record the received txout.
for outIdx, txout := range tx.MsgTx().TxOut {
var accounts []*Account
_, addrs, _, _ := btcscript.ExtractPkScriptAddrs(txout.PkScript, cfg.Net())
_, addrs, _, _ := btcscript.ExtractPkScriptAddrs(txout.PkScript, activeNet.Net)
for _, addr := range addrs {
a, err := AcctMgr.AccountByAddress(addr)
if err != nil {

View file

@ -17,14 +17,15 @@
package main
import (
"github.com/conformal/btcwire"
"github.com/conformal/btcnet"
)
var activeNetParams = netParams(defaultBtcNet)
var activeNet = &testNet3Params
// params is used to group parameters for various networks such as the main
// network and test networks.
type params struct {
*btcnet.Params
connect string
btcdPort string
svrPort string
@ -33,6 +34,7 @@ type params struct {
// mainNetParams contains parameters specific running btcwallet and
// btcd on the main network (btcwire.MainNet).
var mainNetParams = params{
Params: &btcnet.MainNetParams,
connect: "localhost:8334",
btcdPort: "8334",
svrPort: "8332",
@ -41,21 +43,8 @@ var mainNetParams = params{
// testNet3Params contains parameters specific running btcwallet and
// btcd on the test network (version 3) (btcwire.TestNet3).
var testNet3Params = params{
Params: &btcnet.TestNet3Params,
connect: "localhost:18334",
btcdPort: "18334",
svrPort: "18332",
}
// netParams returns parameters specific to the passed bitcoin network.
func netParams(btcnet btcwire.BitcoinNet) *params {
switch btcnet {
case btcwire.TestNet3:
return &testNet3Params
// Return main net by default.
case btcwire.MainNet:
fallthrough
default:
return &mainNetParams
}
}

View file

@ -277,7 +277,7 @@ func makeMultiSigScript(keys []string, nRequired int) ([]byte, *btcjson.Error) {
// mixture of the two.
for i, a := range keys {
// try to parse as pubkey address
a, err := btcutil.DecodeAddress(a, cfg.Net())
a, err := btcutil.DecodeAddress(a, activeNet.Net)
if err != nil {
return nil, &btcjson.Error{
Code: btcjson.ErrParse.Code,
@ -301,7 +301,7 @@ func makeMultiSigScript(keys []string, nRequired int) ([]byte, *btcjson.Error) {
// This will be an addresspubkey
a, err := btcutil.DecodeAddress(apkinfo.ExportPubKey(),
cfg.Net())
activeNet.Net)
if err != nil {
return nil, &btcjson.Error{
Code: btcjson.ErrParse.Code,
@ -384,7 +384,7 @@ func CreateMultiSig(icmd btcjson.Cmd) (interface{}, *btcjson.Error) {
return nil, jsonerr
}
address, err := btcutil.NewAddressScriptHash(script, cfg.Net())
address, err := btcutil.NewAddressScriptHash(script, activeNet.Net)
if err != nil {
// above is a valid script, shouldn't happen.
return nil, &btcjson.Error{
@ -409,7 +409,7 @@ func DumpPrivKey(icmd btcjson.Cmd) (interface{}, *btcjson.Error) {
return nil, &btcjson.ErrInternal
}
addr, err := btcutil.DecodeAddress(cmd.Address, cfg.Net())
addr, err := btcutil.DecodeAddress(cmd.Address, activeNet.Net)
if err != nil {
return nil, &btcjson.ErrInvalidAddressOrKey
}
@ -616,11 +616,11 @@ func GetAccount(icmd btcjson.Cmd) (interface{}, *btcjson.Error) {
}
// Is address valid?
addr, err := btcutil.DecodeAddress(cmd.Address, cfg.Net())
addr, err := btcutil.DecodeAddress(cmd.Address, activeNet.Net)
if err != nil {
return nil, &btcjson.ErrInvalidAddressOrKey
}
if !addr.IsForNet(cfg.Net()) {
if !addr.IsForNet(activeNet.Net) {
return nil, &btcjson.ErrInvalidAddressOrKey
}
@ -694,7 +694,7 @@ func GetAddressBalance(icmd btcjson.Cmd) (interface{}, *btcjson.Error) {
}
// Is address valid?
addr, err := btcutil.DecodeAddress(cmd.Address, cfg.Net())
addr, err := btcutil.DecodeAddress(cmd.Address, activeNet.Net)
if err != nil {
return nil, &btcjson.ErrInvalidAddressOrKey
}
@ -970,7 +970,7 @@ func GetTransaction(icmd btcjson.Cmd) (interface{}, *btcjson.Error) {
received += cred.Amount()
var addr string
_, addrs, _, _ := cred.Addresses(cfg.Net())
_, addrs, _, _ := cred.Addresses(activeNet.Params)
if len(addrs) == 1 {
addr = addrs[0].EncodeAddress()
}
@ -1007,7 +1007,7 @@ func GetTransaction(icmd btcjson.Cmd) (interface{}, *btcjson.Error) {
Amount: (-debits.OutputAmount(true)).ToUnit(btcutil.AmountBTC),
Fee: debits.Fee().ToUnit(btcutil.AmountBTC),
}
_, addrs, _, _ := debitTx.Credits()[0].Addresses(cfg.Net())
_, addrs, _, _ := debitTx.Credits()[0].Addresses(activeNet.Params)
if len(addrs) == 1 {
info.Address = addrs[0].EncodeAddress()
}
@ -1220,12 +1220,12 @@ func ListAddressTransactions(icmd btcjson.Cmd) (interface{}, *btcjson.Error) {
// Decode addresses.
pkHashMap := make(map[string]struct{})
for _, addrStr := range cmd.Addresses {
addr, err := btcutil.DecodeAddress(addrStr, cfg.Net())
addr, err := btcutil.DecodeAddress(addrStr, activeNet.Net)
if err != nil {
return nil, &btcjson.ErrInvalidAddressOrKey
}
apkh, ok := addr.(*btcutil.AddressPubKeyHash)
if !ok || !apkh.IsForNet(cfg.Net()) {
if !ok || !apkh.IsForNet(activeNet.Net) {
return nil, &btcjson.ErrInvalidAddressOrKey
}
pkHashMap[string(addr.ScriptAddress())] = struct{}{}
@ -1300,7 +1300,7 @@ func ListUnspent(icmd btcjson.Cmd) (interface{}, *btcjson.Error) {
if len(cmd.Addresses) != 0 {
// confirm that all of them are good:
for _, as := range cmd.Addresses {
a, err := btcutil.DecodeAddress(as, cfg.Net())
a, err := btcutil.DecodeAddress(as, activeNet.Net)
if err != nil {
return nil, &btcjson.ErrInvalidAddressOrKey
}
@ -1635,7 +1635,7 @@ func SignMessage(icmd btcjson.Cmd) (interface{}, *btcjson.Error) {
return nil, &btcjson.ErrInternal
}
addr, err := btcutil.DecodeAddress(cmd.Address, cfg.Net())
addr, err := btcutil.DecodeAddress(cmd.Address, activeNet.Net)
if err != nil {
return nil, &btcjson.Error{
Code: btcjson.ErrParse.Code,
@ -1800,7 +1800,7 @@ func SignRawTransaction(icmd btcjson.Cmd) (interface{}, *btcjson.Error) {
}
addr, err := btcutil.NewAddressScriptHash(redeemScript,
cfg.Net())
activeNet.Net)
if err != nil {
return nil, &btcjson.Error{
Code: btcjson.ErrDeserialization.Code,
@ -1861,7 +1861,7 @@ func SignRawTransaction(icmd btcjson.Cmd) (interface{}, *btcjson.Error) {
}
}
if !wif.IsForNet(cfg.Net()) {
if !wif.IsForNet(activeNet.Net) {
return nil, &btcjson.Error{
Code: btcjson.ErrDeserialization.Code,
Message: "key network doesn't match " +
@ -1870,7 +1870,7 @@ func SignRawTransaction(icmd btcjson.Cmd) (interface{}, *btcjson.Error) {
}
addr, err := btcutil.NewAddressPubKey(wif.SerializePubKey(),
cfg.Net())
activeNet.Net)
if err != nil {
return nil, &btcjson.Error{
Code: btcjson.ErrDeserialization.Code,
@ -2017,7 +2017,7 @@ func SignRawTransaction(icmd btcjson.Cmd) (interface{}, *btcjson.Error) {
if (hashType&btcscript.SigHashSingle) == 0 ||
i < len(msgTx.TxOut) {
script, err := btcscript.SignTxOutput(cfg.Net(),
script, err := btcscript.SignTxOutput(activeNet.Net,
msgTx, i, input, byte(hashType), getKey,
getScript, txIn.SignatureScript)
// Failure to sign isn't an error, it just means that
@ -2060,7 +2060,7 @@ func ValidateAddress(icmd btcjson.Cmd) (interface{}, *btcjson.Error) {
}
result := btcjson.ValidateAddressResult{}
addr, err := btcutil.DecodeAddress(cmd.Address, cfg.Net())
addr, err := btcutil.DecodeAddress(cmd.Address, activeNet.Net)
if err != nil {
return result, nil
}
@ -2116,7 +2116,7 @@ func VerifyMessage(icmd btcjson.Cmd) (interface{}, *btcjson.Error) {
return nil, &btcjson.ErrInternal
}
addr, err := btcutil.DecodeAddress(cmd.Address, cfg.Net())
addr, err := btcutil.DecodeAddress(cmd.Address, activeNet.Net)
if err != nil {
return nil, &btcjson.Error{
Code: btcjson.ErrParse.Code,

View file

@ -702,7 +702,7 @@ func Handshake(rpc ServerConn) error {
if jsonErr != nil {
return jsonErr
}
if net != cfg.Net() {
if net != activeNet.Net {
return errors.New("btcd and btcwallet running on different Bitcoin networks")
}

View file

@ -23,6 +23,7 @@ import (
"time"
"github.com/conformal/btcchain"
"github.com/conformal/btcnet"
"github.com/conformal/btcscript"
"github.com/conformal/btcutil"
"github.com/conformal/btcwire"
@ -1282,12 +1283,12 @@ func (d *Debits) Fee() btcutil.Amount {
// Addresses parses the pubkey script, extracting all addresses for a
// standard script.
func (c *Credit) Addresses(net btcwire.BitcoinNet) (btcscript.ScriptClass,
func (c *Credit) Addresses(net *btcnet.Params) (btcscript.ScriptClass,
[]btcutil.Address, int, error) {
msgTx := c.Tx().MsgTx()
pkScript := msgTx.TxOut[c.OutputIndex].PkScript
return btcscript.ExtractPkScriptAddrs(pkScript, net)
return btcscript.ExtractPkScriptAddrs(pkScript, net.Net)
}
// Change returns whether the credit is the result of a change output.

View file

@ -18,7 +18,6 @@ package wallet
import (
"bytes"
"code.google.com/p/go.crypto/ripemd160"
"crypto/aes"
"crypto/cipher"
"crypto/ecdsa"
@ -29,13 +28,17 @@ import (
"encoding/hex"
"errors"
"fmt"
"github.com/conformal/btcec"
"github.com/conformal/btcscript"
"github.com/conformal/btcutil"
"github.com/conformal/btcwire"
"io"
"math/big"
"time"
"code.google.com/p/go.crypto/ripemd160"
"github.com/conformal/btcec"
"github.com/conformal/btcnet"
"github.com/conformal/btcscript"
"github.com/conformal/btcutil"
"github.com/conformal/btcwire"
)
const (
@ -527,7 +530,7 @@ type Wallet struct {
// desc's binary representation must not exceed 32 and 256 bytes,
// respectively. All address private keys are encrypted with passphrase.
// The wallet is returned locked.
func NewWallet(name, desc string, passphrase []byte, net btcwire.BitcoinNet,
func NewWallet(name, desc string, passphrase []byte, net *btcnet.Params,
createdAt *BlockStamp, keypoolSize uint) (*Wallet, error) {
// Check sizes of inputs.
@ -538,11 +541,6 @@ func NewWallet(name, desc string, passphrase []byte, net btcwire.BitcoinNet,
return nil, errors.New("desc exceeds 256 byte maximum size")
}
// Check for a valid network.
if !(net == btcwire.MainNet || net == btcwire.TestNet3) {
return nil, errors.New("wallets must use mainnet or testnet3")
}
// Randomly-generate rootkey and chaincode.
rootkey, chaincode := make([]byte, 32), make([]byte, 32)
if _, err := rand.Read(rootkey); err != nil {
@ -562,7 +560,7 @@ func NewWallet(name, desc string, passphrase []byte, net btcwire.BitcoinNet,
// Create and fill wallet.
w := &Wallet{
vers: VersCurrent,
net: net,
net: net.Net,
flags: walletFlags{
useEncryption: true,
watchingOnly: false,

View file

@ -20,20 +20,22 @@ import (
"bytes"
"crypto/ecdsa"
"crypto/rand"
"github.com/conformal/btcec"
"github.com/conformal/btcscript"
"github.com/conformal/btcutil"
"github.com/conformal/btcwire"
"github.com/davecgh/go-spew/spew"
"math/big"
"reflect"
"testing"
"github.com/conformal/btcec"
"github.com/conformal/btcnet"
"github.com/conformal/btcscript"
"github.com/conformal/btcutil"
"github.com/davecgh/go-spew/spew"
)
var _ = spew.Dump
var netParams = &btcnet.MainNetParams
func TestBtcAddressSerializer(t *testing.T) {
fakeWallet := &Wallet{net: btcwire.TestNet3}
fakeWallet := &Wallet{net: netParams.Net}
kdfp := &kdfParameters{
mem: 1024,
nIter: 5,
@ -86,7 +88,7 @@ func TestBtcAddressSerializer(t *testing.T) {
}
func TestScriptAddressSerializer(t *testing.T) {
fakeWallet := &Wallet{net: btcwire.TestNet3}
fakeWallet := &Wallet{net: netParams.Net}
script := []byte{btcscript.OP_TRUE, btcscript.OP_DUP,
btcscript.OP_DROP}
addr, err := newScriptAddress(fakeWallet, script, &BlockStamp{})
@ -118,7 +120,7 @@ func TestScriptAddressSerializer(t *testing.T) {
func TestWalletCreationSerialization(t *testing.T) {
createdAt := &BlockStamp{}
w1, err := NewWallet("banana wallet", "A wallet for testing.",
[]byte("banana"), btcwire.MainNet, createdAt, 100)
[]byte("banana"), netParams, createdAt, 100)
if err != nil {
t.Error("Error creating new wallet: " + err.Error())
return
@ -330,7 +332,7 @@ func TestWalletPubkeyChaining(t *testing.T) {
const keypoolSize = 5
w, err := NewWallet("banana wallet", "A wallet for testing.",
[]byte("banana"), btcwire.MainNet, &BlockStamp{}, keypoolSize)
[]byte("banana"), netParams, &BlockStamp{}, keypoolSize)
if err != nil {
t.Error("Error creating new wallet: " + err.Error())
return
@ -506,7 +508,7 @@ func TestWatchingWalletExport(t *testing.T) {
const keypoolSize = 10
createdAt := &BlockStamp{}
w, err := NewWallet("banana wallet", "A wallet for testing.",
[]byte("banana"), btcwire.MainNet, createdAt, keypoolSize)
[]byte("banana"), netParams, createdAt, keypoolSize)
if err != nil {
t.Error("Error creating new wallet: " + err.Error())
return
@ -715,7 +717,7 @@ func TestWatchingWalletExport(t *testing.T) {
return
}
pk, _ := btcec.PrivKeyFromBytes(btcec.S256(), make([]byte, 32))
wif, err := btcutil.NewWIF(pk, btcwire.MainNet, true)
wif, err := btcutil.NewWIF(pk, netParams.Net, true)
if err != nil {
t.Fatal(err)
}
@ -730,7 +732,7 @@ func TestImportPrivateKey(t *testing.T) {
createHeight := int32(100)
createdAt := &BlockStamp{Height: createHeight}
w, err := NewWallet("banana wallet", "A wallet for testing.",
[]byte("banana"), btcwire.MainNet, createdAt, keypoolSize)
[]byte("banana"), netParams, createdAt, keypoolSize)
if err != nil {
t.Error("Error creating new wallet: " + err.Error())
return
@ -759,7 +761,7 @@ func TestImportPrivateKey(t *testing.T) {
}
// import priv key
wif, err := btcutil.NewWIF((*btcec.PrivateKey)(pk), btcwire.MainNet, false)
wif, err := btcutil.NewWIF((*btcec.PrivateKey)(pk), netParams.Net, false)
if err != nil {
t.Fatal(err)
}
@ -925,7 +927,7 @@ func TestImportScript(t *testing.T) {
createHeight := int32(100)
createdAt := &BlockStamp{Height: createHeight}
w, err := NewWallet("banana wallet", "A wallet for testing.",
[]byte("banana"), btcwire.MainNet, createdAt, keypoolSize)
[]byte("banana"), netParams, createdAt, keypoolSize)
if err != nil {
t.Error("Error creating new wallet: " + err.Error())
return
@ -1196,7 +1198,7 @@ func TestChangePassphrase(t *testing.T) {
const keypoolSize = 10
createdAt := &BlockStamp{}
w, err := NewWallet("banana wallet", "A wallet for testing.",
[]byte("banana"), btcwire.MainNet, createdAt, keypoolSize)
[]byte("banana"), netParams, createdAt, keypoolSize)
if err != nil {
t.Error("Error creating new wallet: " + err.Error())
return