Update btcnet path import paths to new location.
This commit is contained in:
parent
642f5e0294
commit
4a1067b6f1
15 changed files with 101 additions and 94 deletions
|
@ -21,8 +21,8 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcnet"
|
||||
"github.com/btcsuite/btcrpcclient"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/btcsuite/btcwallet/keystore"
|
||||
|
@ -32,7 +32,7 @@ import (
|
|||
|
||||
type Client struct {
|
||||
*btcrpcclient.Client
|
||||
netParams *btcnet.Params
|
||||
chainParams *chaincfg.Params
|
||||
|
||||
enqueueNotification chan interface{}
|
||||
dequeueNotification chan interface{}
|
||||
|
@ -51,9 +51,9 @@ type Client struct {
|
|||
quitMtx sync.Mutex
|
||||
}
|
||||
|
||||
func NewClient(net *btcnet.Params, connect, user, pass string, certs []byte, disableTLS bool) (*Client, error) {
|
||||
func NewClient(chainParams *chaincfg.Params, connect, user, pass string, certs []byte, disableTLS bool) (*Client, error) {
|
||||
client := Client{
|
||||
netParams: net,
|
||||
chainParams: chainParams,
|
||||
enqueueNotification: make(chan interface{}),
|
||||
dequeueNotification: make(chan interface{}),
|
||||
currentBlock: make(chan *keystore.BlockStamp),
|
||||
|
@ -98,7 +98,7 @@ func (c *Client) Start() error {
|
|||
c.Disconnect()
|
||||
return err
|
||||
}
|
||||
if net != c.netParams.Net {
|
||||
if net != c.chainParams.Net {
|
||||
c.Disconnect()
|
||||
return errors.New("mismatched networks")
|
||||
}
|
||||
|
|
|
@ -36,10 +36,10 @@ import (
|
|||
|
||||
"golang.org/x/crypto/ripemd160"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcec"
|
||||
"github.com/btcsuite/btcnet"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/btcsuite/btcwallet/rename"
|
||||
)
|
||||
|
@ -475,7 +475,7 @@ func (v *varEntries) ReadFrom(r io.Reader) (n int64, err error) {
|
|||
// erroring on unknown key store networks must happen on the read itself and not
|
||||
// after the fact. This is admitidly a hack, but with a bip32 keystore on the
|
||||
// horizon I'm not too motivated to clean this up.
|
||||
type netParams btcnet.Params
|
||||
type netParams chaincfg.Params
|
||||
|
||||
func (net *netParams) ReadFrom(r io.Reader) (int64, error) {
|
||||
var buf [4]byte
|
||||
|
@ -489,11 +489,11 @@ func (net *netParams) ReadFrom(r io.Reader) (int64, error) {
|
|||
|
||||
switch wire.BitcoinNet(binary.LittleEndian.Uint32(uint32Bytes)) {
|
||||
case wire.MainNet:
|
||||
*net = (netParams)(btcnet.MainNetParams)
|
||||
*net = (netParams)(chaincfg.MainNetParams)
|
||||
case wire.TestNet3:
|
||||
*net = (netParams)(btcnet.TestNet3Params)
|
||||
*net = (netParams)(chaincfg.TestNet3Params)
|
||||
case wire.SimNet:
|
||||
*net = (netParams)(btcnet.SimNetParams)
|
||||
*net = (netParams)(chaincfg.SimNetParams)
|
||||
default:
|
||||
return n64, errors.New("unknown network")
|
||||
}
|
||||
|
@ -560,7 +560,7 @@ type Store struct {
|
|||
// New creates and initializes a new Store. name's and desc's byte length
|
||||
// must not exceed 32 and 256 bytes, respectively. All address private keys
|
||||
// are encrypted with passphrase. The key store is returned locked.
|
||||
func New(dir string, desc string, passphrase []byte, net *btcnet.Params,
|
||||
func New(dir string, desc string, passphrase []byte, net *chaincfg.Params,
|
||||
createdAt *BlockStamp) (*Store, error) {
|
||||
|
||||
// Check sizes of inputs.
|
||||
|
@ -1268,15 +1268,15 @@ func (s *Store) Address(a btcutil.Address) (WalletAddress, error) {
|
|||
}
|
||||
|
||||
// Net returns the bitcoin network parameters for this key store.
|
||||
func (s *Store) Net() *btcnet.Params {
|
||||
func (s *Store) Net() *chaincfg.Params {
|
||||
s.mtx.RLock()
|
||||
defer s.mtx.RUnlock()
|
||||
|
||||
return s.netParams()
|
||||
}
|
||||
|
||||
func (s *Store) netParams() *btcnet.Params {
|
||||
return (*btcnet.Params)(s.net)
|
||||
func (s *Store) netParams() *chaincfg.Params {
|
||||
return (*chaincfg.Params)(s.net)
|
||||
}
|
||||
|
||||
// SetSyncStatus sets the sync status for a single key store address. This
|
||||
|
|
|
@ -23,10 +23,10 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcec"
|
||||
"github.com/btcsuite/btcnet"
|
||||
"github.com/btcsuite/btcutil"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
|
@ -34,7 +34,7 @@ import (
|
|||
|
||||
const dummyDir = ""
|
||||
|
||||
var tstNetParams = &btcnet.MainNetParams
|
||||
var tstNetParams = &chaincfg.MainNetParams
|
||||
|
||||
func makeBS(height int32) *BlockStamp {
|
||||
return &BlockStamp{
|
||||
|
|
10
params.go
10
params.go
|
@ -17,7 +17,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/btcsuite/btcnet"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
)
|
||||
|
||||
var activeNet = &testNet3Params
|
||||
|
@ -25,7 +25,7 @@ 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
|
||||
*chaincfg.Params
|
||||
connect string
|
||||
btcdPort string
|
||||
svrPort string
|
||||
|
@ -34,7 +34,7 @@ type params struct {
|
|||
// mainNetParams contains parameters specific running btcwallet and
|
||||
// btcd on the main network (wire.MainNet).
|
||||
var mainNetParams = params{
|
||||
Params: &btcnet.MainNetParams,
|
||||
Params: &chaincfg.MainNetParams,
|
||||
connect: "localhost:8334",
|
||||
btcdPort: "8334",
|
||||
svrPort: "8332",
|
||||
|
@ -43,7 +43,7 @@ var mainNetParams = params{
|
|||
// testNet3Params contains parameters specific running btcwallet and
|
||||
// btcd on the test network (version 3) (wire.TestNet3).
|
||||
var testNet3Params = params{
|
||||
Params: &btcnet.TestNet3Params,
|
||||
Params: &chaincfg.TestNet3Params,
|
||||
connect: "localhost:18334",
|
||||
btcdPort: "18334",
|
||||
svrPort: "18332",
|
||||
|
@ -52,7 +52,7 @@ var testNet3Params = params{
|
|||
// simNetParams contains parameters specific to the simulation test network
|
||||
// (wire.SimNet).
|
||||
var simNetParams = params{
|
||||
Params: &btcnet.SimNetParams,
|
||||
Params: &chaincfg.SimNetParams,
|
||||
connect: "localhost:18556",
|
||||
btcdPort: "18556",
|
||||
svrPort: "18554",
|
||||
|
|
|
@ -18,16 +18,16 @@ package txstore
|
|||
|
||||
import (
|
||||
"github.com/btcsuite/btcd/blockchain"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
"github.com/btcsuite/btcjson"
|
||||
"github.com/btcsuite/btcnet"
|
||||
"github.com/btcsuite/btcutil"
|
||||
)
|
||||
|
||||
// ToJSON returns a slice of btcjson listtransactions result types for all credits
|
||||
// and debits of this transaction.
|
||||
func (t *TxRecord) ToJSON(account string, chainHeight int32,
|
||||
net *btcnet.Params) ([]btcjson.ListTransactionsResult, error) {
|
||||
net *chaincfg.Params) ([]btcjson.ListTransactionsResult, error) {
|
||||
|
||||
t.s.mtx.RLock()
|
||||
defer t.s.mtx.RUnlock()
|
||||
|
@ -53,7 +53,7 @@ func (t *TxRecord) ToJSON(account string, chainHeight int32,
|
|||
// ToJSON returns a slice of objects that may be marshaled as a JSON array
|
||||
// of JSON objects for a listtransactions RPC reply.
|
||||
func (d Debits) ToJSON(account string, chainHeight int32,
|
||||
net *btcnet.Params) ([]btcjson.ListTransactionsResult, error) {
|
||||
net *chaincfg.Params) ([]btcjson.ListTransactionsResult, error) {
|
||||
|
||||
d.s.mtx.RLock()
|
||||
defer d.s.mtx.RUnlock()
|
||||
|
@ -62,7 +62,7 @@ func (d Debits) ToJSON(account string, chainHeight int32,
|
|||
}
|
||||
|
||||
func (d Debits) toJSON(account string, chainHeight int32,
|
||||
net *btcnet.Params) ([]btcjson.ListTransactionsResult, error) {
|
||||
net *chaincfg.Params) ([]btcjson.ListTransactionsResult, error) {
|
||||
|
||||
msgTx := d.Tx().MsgTx()
|
||||
reply := make([]btcjson.ListTransactionsResult, 0, len(msgTx.TxOut))
|
||||
|
@ -152,7 +152,7 @@ func (c CreditCategory) String() string {
|
|||
// ToJSON returns a slice of objects that may be marshaled as a JSON array
|
||||
// of JSON objects for a listtransactions RPC reply.
|
||||
func (c Credit) ToJSON(account string, chainHeight int32,
|
||||
net *btcnet.Params) (btcjson.ListTransactionsResult, error) {
|
||||
net *chaincfg.Params) (btcjson.ListTransactionsResult, error) {
|
||||
|
||||
c.s.mtx.RLock()
|
||||
defer c.s.mtx.RUnlock()
|
||||
|
@ -161,7 +161,7 @@ func (c Credit) ToJSON(account string, chainHeight int32,
|
|||
}
|
||||
|
||||
func (c Credit) toJSON(account string, chainHeight int32,
|
||||
net *btcnet.Params) (btcjson.ListTransactionsResult, error) {
|
||||
net *chaincfg.Params) (btcjson.ListTransactionsResult, error) {
|
||||
|
||||
msgTx := c.Tx().MsgTx()
|
||||
txout := msgTx.TxOut[c.OutputIndex]
|
||||
|
|
|
@ -25,9 +25,9 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/blockchain"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcnet"
|
||||
"github.com/btcsuite/btcutil"
|
||||
)
|
||||
|
||||
|
@ -1420,7 +1420,7 @@ func (d Debits) Fee() btcutil.Amount {
|
|||
|
||||
// Addresses parses the pubkey script, extracting all addresses for a
|
||||
// standard script.
|
||||
func (c Credit) Addresses(net *btcnet.Params) (txscript.ScriptClass,
|
||||
func (c Credit) Addresses(net *chaincfg.Params) (txscript.ScriptClass,
|
||||
[]btcutil.Address, int, error) {
|
||||
|
||||
c.s.mtx.RLock()
|
||||
|
|
|
@ -20,8 +20,8 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcnet"
|
||||
"github.com/btcsuite/btcutil"
|
||||
. "github.com/btcsuite/btcwallet/txstore"
|
||||
)
|
||||
|
@ -109,7 +109,7 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
|||
}
|
||||
// Verify that we can create the JSON output without any
|
||||
// errors.
|
||||
_, err = r.ToJSON("", 100, &btcnet.MainNetParams)
|
||||
_, err = r.ToJSON("", 100, &chaincfg.MainNetParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
_, err = r.ToJSON("", 100, &btcnet.MainNetParams)
|
||||
_, err = r.ToJSON("", 100, &chaincfg.MainNetParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
_, err = r.ToJSON("", 100, &btcnet.MainNetParams)
|
||||
_, err = r.ToJSON("", 100, &chaincfg.MainNetParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
_, err = r.ToJSON("", 100, &btcnet.MainNetParams)
|
||||
_, err = r.ToJSON("", 100, &chaincfg.MainNetParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
_, err = r.ToJSON("", 100, &btcnet.MainNetParams)
|
||||
_, err = r.ToJSON("", 100, &chaincfg.MainNetParams)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -264,7 +264,7 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
_, err = r.ToJSON("", 100, &btcnet.MainNetParams)
|
||||
_, err = r.ToJSON("", 100, &chaincfg.MainNetParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -295,7 +295,7 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
_, err = r.ToJSON("", 100, &btcnet.MainNetParams)
|
||||
_, err = r.ToJSON("", 100, &chaincfg.MainNetParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -321,7 +321,7 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
_, err = r.ToJSON("", 100, &btcnet.MainNetParams)
|
||||
_, err = r.ToJSON("", 100, &chaincfg.MainNetParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -349,7 +349,7 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
_, err = r.ToJSON("", 100, &btcnet.MainNetParams)
|
||||
_, err = r.ToJSON("", 100, &chaincfg.MainNetParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -374,7 +374,7 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
_, err = r.ToJSON("", 100, &btcnet.MainNetParams)
|
||||
_, err = r.ToJSON("", 100, &chaincfg.MainNetParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -457,7 +457,7 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
_, err = r.ToJSON("", 100, &btcnet.MainNetParams)
|
||||
_, err = r.ToJSON("", 100, &chaincfg.MainNetParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/btcsuite/btcnet"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcwallet/votingpool"
|
||||
"github.com/btcsuite/btcwallet/waddrmgr"
|
||||
"github.com/btcsuite/btcwallet/walletdb"
|
||||
|
@ -57,7 +57,7 @@ func Example_basic() {
|
|||
|
||||
// Create the address manager
|
||||
mgr, err := waddrmgr.Create(mgrNamespace, seed, pubPassphrase, privPassphrase,
|
||||
&btcnet.MainNetParams, nil)
|
||||
&chaincfg.MainNetParams, nil)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to create addr manager: %v\n", err)
|
||||
return
|
||||
|
|
|
@ -480,7 +480,8 @@ func (vp *Pool) DepositScriptAddress(seriesID, branch, index uint32) (btcutil.Ad
|
|||
}
|
||||
scriptHash := btcutil.Hash160(script)
|
||||
|
||||
return btcutil.NewAddressScriptHashFromHash(scriptHash, vp.manager.Net())
|
||||
return btcutil.NewAddressScriptHashFromHash(scriptHash,
|
||||
vp.manager.ChainParams())
|
||||
}
|
||||
|
||||
// DepositScript constructs and returns a multi-signature redemption script where
|
||||
|
@ -512,7 +513,8 @@ func (vp *Pool) DepositScript(seriesID, branch, index uint32) ([]byte, error) {
|
|||
str := fmt.Sprintf("child #%d for this pubkey %d does not exist", index, i)
|
||||
return nil, managerError(waddrmgr.ErrKeyChain, str, err)
|
||||
}
|
||||
pks[i], err = btcutil.NewAddressPubKey(pubkey.SerializeCompressed(), vp.manager.Net())
|
||||
pks[i], err = btcutil.NewAddressPubKey(pubkey.SerializeCompressed(),
|
||||
vp.manager.ChainParams())
|
||||
if err != nil {
|
||||
str := fmt.Sprintf(
|
||||
"child #%d for this pubkey %d could not be converted to an address",
|
||||
|
|
|
@ -27,7 +27,7 @@ import (
|
|||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/btcsuite/btcnet"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcutil/hdkeychain"
|
||||
"github.com/btcsuite/btcwallet/votingpool"
|
||||
"github.com/btcsuite/btcwallet/waddrmgr"
|
||||
|
@ -115,7 +115,7 @@ func setUp(t *testing.T) (tearDownFunc func(), mgr *waddrmgr.Manager, pool *voti
|
|||
t.Fatalf("Failed to create addr manager DB namespace: %v", err)
|
||||
}
|
||||
mgr, err = waddrmgr.Create(mgrNamespace, seed, pubPassphrase, privPassphrase,
|
||||
&btcnet.MainNetParams, fastScrypt)
|
||||
&chaincfg.MainNetParams, fastScrypt)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create addr manager: %v", err)
|
||||
}
|
||||
|
|
|
@ -274,7 +274,7 @@ func (a *managedAddress) ExportPrivKey() (*btcutil.WIF, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return btcutil.NewWIF(pk, a.manager.net, a.compressed)
|
||||
return btcutil.NewWIF(pk, a.manager.chainParams, a.compressed)
|
||||
}
|
||||
|
||||
// newManagedAddressWithoutPrivKey returns a new managed address based on the
|
||||
|
@ -288,7 +288,7 @@ func newManagedAddressWithoutPrivKey(m *Manager, account uint32, pubKey *btcec.P
|
|||
} else {
|
||||
pubKeyHash = btcutil.Hash160(pubKey.SerializeUncompressed())
|
||||
}
|
||||
address, err := btcutil.NewAddressPubKeyHash(pubKeyHash, m.net)
|
||||
address, err := btcutil.NewAddressPubKeyHash(pubKeyHash, m.chainParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -491,7 +491,8 @@ func (a *scriptAddress) Script() ([]byte, error) {
|
|||
|
||||
// newScriptAddress initializes and returns a new pay-to-script-hash address.
|
||||
func newScriptAddress(m *Manager, account uint32, scriptHash, scriptEncrypted []byte) (*scriptAddress, error) {
|
||||
address, err := btcutil.NewAddressScriptHashFromHash(scriptHash, m.net)
|
||||
address, err := btcutil.NewAddressScriptHashFromHash(scriptHash,
|
||||
m.chainParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import (
|
|||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/btcsuite/btcnet"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcwallet/waddrmgr"
|
||||
"github.com/btcsuite/btcwallet/walletdb"
|
||||
_ "github.com/btcsuite/btcwallet/walletdb/bdb"
|
||||
|
@ -131,7 +131,7 @@ func setupManager(t *testing.T) (tearDownFunc func(), mgr *waddrmgr.Manager) {
|
|||
t.Fatalf("createDbNamespace: unexpected error: %v", err)
|
||||
}
|
||||
mgr, err = waddrmgr.Create(namespace, seed, pubPassphrase,
|
||||
privPassphrase, &btcnet.MainNetParams, fastScrypt)
|
||||
privPassphrase, &chaincfg.MainNetParams, fastScrypt)
|
||||
if err != nil {
|
||||
db.Close()
|
||||
_ = os.RemoveAll(dirName)
|
||||
|
|
|
@ -22,9 +22,9 @@ import (
|
|||
"fmt"
|
||||
"sync"
|
||||
|
||||
"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/hdkeychain"
|
||||
"github.com/btcsuite/btcwallet/snacl"
|
||||
|
@ -210,7 +210,7 @@ type Manager struct {
|
|||
mtx sync.RWMutex
|
||||
|
||||
namespace walletdb.Namespace
|
||||
net *btcnet.Params
|
||||
chainParams *chaincfg.Params
|
||||
addrs map[addrKey]ManagedAddress
|
||||
syncState syncState
|
||||
watchingOnly bool
|
||||
|
@ -935,9 +935,10 @@ func (m *Manager) existsAddress(addressID []byte) (bool, error) {
|
|||
func (m *Manager) ImportPrivateKey(wif *btcutil.WIF, bs *BlockStamp) (ManagedPubKeyAddress, error) {
|
||||
// Ensure the address is intended for network the address manager is
|
||||
// associated with.
|
||||
if !wif.IsForNet(m.net) {
|
||||
if !wif.IsForNet(m.chainParams) {
|
||||
str := fmt.Sprintf("private key is not for the same network the "+
|
||||
"address manager is configured for (%s)", m.net.Name)
|
||||
"address manager is configured for (%s)",
|
||||
m.chainParams.Name)
|
||||
return nil, managerError(ErrWrongNet, str, nil)
|
||||
}
|
||||
|
||||
|
@ -1288,12 +1289,12 @@ func (m *Manager) Unlock(passphrase []byte) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Net returns the network parameters for this address manager.
|
||||
func (m *Manager) Net() *btcnet.Params {
|
||||
// ChainParams returns the chain parameters for this address manager.
|
||||
func (m *Manager) ChainParams() *chaincfg.Params {
|
||||
// NOTE: No need for mutex here since the net field does not change
|
||||
// after the manager instance is created.
|
||||
|
||||
return m.net
|
||||
return m.chainParams
|
||||
}
|
||||
|
||||
// nextAddresses returns the specified number of next chained address from the
|
||||
|
@ -1364,7 +1365,7 @@ func (m *Manager) nextAddresses(account uint32, numAddresses uint32, internal bo
|
|||
nextIndex)
|
||||
return nil, managerError(ErrKeyChain, str, err)
|
||||
}
|
||||
key.SetNet(m.net)
|
||||
key.SetNet(m.chainParams)
|
||||
|
||||
nextIndex++
|
||||
nextKey = key
|
||||
|
@ -1625,7 +1626,7 @@ func (m *Manager) Decrypt(keyType CryptoKeyType, in []byte) ([]byte, error) {
|
|||
}
|
||||
|
||||
// newManager returns a new locked address manager with the given parameters.
|
||||
func newManager(namespace walletdb.Namespace, net *btcnet.Params,
|
||||
func newManager(namespace walletdb.Namespace, chainParams *chaincfg.Params,
|
||||
masterKeyPub *snacl.SecretKey, masterKeyPriv *snacl.SecretKey,
|
||||
cryptoKeyPub EncryptorDecryptor, cryptoKeyPrivEncrypted,
|
||||
cryptoKeyScriptEncrypted []byte, syncInfo *syncState,
|
||||
|
@ -1633,7 +1634,7 @@ func newManager(namespace walletdb.Namespace, net *btcnet.Params,
|
|||
|
||||
return &Manager{
|
||||
namespace: namespace,
|
||||
net: net,
|
||||
chainParams: chainParams,
|
||||
addrs: make(map[addrKey]ManagedAddress),
|
||||
syncState: *syncInfo,
|
||||
locked: true,
|
||||
|
@ -1717,7 +1718,7 @@ func checkBranchKeys(acctKey *hdkeychain.ExtendedKey) error {
|
|||
// loadManager returns a new address manager that results from loading it from
|
||||
// the passed opened database. The public passphrase is required to decrypt the
|
||||
// public keys.
|
||||
func loadManager(namespace walletdb.Namespace, pubPassphrase []byte, net *btcnet.Params, config *Options) (*Manager, error) {
|
||||
func loadManager(namespace walletdb.Namespace, pubPassphrase []byte, chainParams *chaincfg.Params, config *Options) (*Manager, error) {
|
||||
// Perform all database lookups in a read-only view.
|
||||
var watchingOnly bool
|
||||
var masterKeyPubParams, masterKeyPrivParams []byte
|
||||
|
@ -1811,7 +1812,7 @@ func loadManager(namespace walletdb.Namespace, pubPassphrase []byte, net *btcnet
|
|||
// Create new address manager with the given parameters. Also, override
|
||||
// the defaults for the additional fields which are not specified in the
|
||||
// call to new with the values loaded from the database.
|
||||
mgr := newManager(namespace, net, &masterKeyPub, &masterKeyPriv,
|
||||
mgr := newManager(namespace, chainParams, &masterKeyPub, &masterKeyPriv,
|
||||
cryptoKeyPub, cryptoKeyPrivEnc, cryptoKeyScriptEnc, syncInfo,
|
||||
config, privPassphraseSalt)
|
||||
mgr.watchingOnly = watchingOnly
|
||||
|
@ -1828,7 +1829,7 @@ func loadManager(namespace walletdb.Namespace, pubPassphrase []byte, net *btcnet
|
|||
//
|
||||
// A ManagerError with an error code of ErrNoExist will be returned if the
|
||||
// passed manager does not exist in the specified namespace.
|
||||
func Open(namespace walletdb.Namespace, pubPassphrase []byte, net *btcnet.Params, config *Options) (*Manager, error) {
|
||||
func Open(namespace walletdb.Namespace, pubPassphrase []byte, chainParams *chaincfg.Params, config *Options) (*Manager, error) {
|
||||
// Return an error if the manager has NOT already been created in the
|
||||
// given database namespace.
|
||||
exists, err := managerExists(namespace)
|
||||
|
@ -1850,7 +1851,7 @@ func Open(namespace walletdb.Namespace, pubPassphrase []byte, net *btcnet.Params
|
|||
config = defaultConfig
|
||||
}
|
||||
|
||||
return loadManager(namespace, pubPassphrase, net, config)
|
||||
return loadManager(namespace, pubPassphrase, chainParams, config)
|
||||
}
|
||||
|
||||
// Create returns a new locked address manager in the given namespace. The
|
||||
|
@ -1870,7 +1871,7 @@ func Open(namespace walletdb.Namespace, pubPassphrase []byte, net *btcnet.Params
|
|||
//
|
||||
// A ManagerError with an error code of ErrAlreadyExists will be returned the
|
||||
// address manager already exists in the specified namespace.
|
||||
func Create(namespace walletdb.Namespace, seed, pubPassphrase, privPassphrase []byte, net *btcnet.Params, config *Options) (*Manager, error) {
|
||||
func Create(namespace walletdb.Namespace, seed, pubPassphrase, privPassphrase []byte, chainParams *chaincfg.Params, config *Options) (*Manager, error) {
|
||||
// Return an error if the manager has already been created in the given
|
||||
// database namespace.
|
||||
exists, err := managerExists(namespace)
|
||||
|
@ -1902,7 +1903,7 @@ func Create(namespace walletdb.Namespace, seed, pubPassphrase, privPassphrase []
|
|||
}
|
||||
|
||||
// Derive the account key for the first account according to BIP0044.
|
||||
acctKeyPriv, err := deriveAccountKey(root, net.HDCoinType, 0)
|
||||
acctKeyPriv, err := deriveAccountKey(root, chainParams.HDCoinType, 0)
|
||||
if err != nil {
|
||||
// The seed is unusable if the any of the children in the
|
||||
// required hierarchy can't be derived due to invalid child.
|
||||
|
@ -2007,9 +2008,9 @@ func Create(namespace walletdb.Namespace, seed, pubPassphrase, privPassphrase []
|
|||
return nil, managerError(ErrCrypto, str, err)
|
||||
}
|
||||
|
||||
// Use the genesis block for the passed network as the created at block
|
||||
// for the defaut.
|
||||
createdAt := &BlockStamp{Hash: *net.GenesisHash, Height: 0}
|
||||
// Use the genesis block for the passed chain as the created at block
|
||||
// for the default.
|
||||
createdAt := &BlockStamp{Hash: *chainParams.GenesisHash, Height: 0}
|
||||
|
||||
// Create the initial sync state.
|
||||
recentHashes := []wire.ShaHash{createdAt.Hash}
|
||||
|
@ -2074,7 +2075,7 @@ func Create(namespace walletdb.Namespace, seed, pubPassphrase, privPassphrase []
|
|||
masterKeyPriv.Zero()
|
||||
cryptoKeyPriv.Zero()
|
||||
cryptoKeyScript.Zero()
|
||||
return newManager(namespace, net, masterKeyPub, masterKeyPriv,
|
||||
return newManager(namespace, chainParams, masterKeyPub, masterKeyPriv,
|
||||
cryptoKeyPub, cryptoKeyPrivEnc, cryptoKeyScriptEnc, syncInfo,
|
||||
config, privPassphraseSalt), nil
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcnet"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/btcsuite/btcwallet/waddrmgr"
|
||||
"github.com/btcsuite/btcwallet/walletdb"
|
||||
|
@ -391,10 +391,11 @@ func testExternalAddresses(tc *testContext) bool {
|
|||
|
||||
// Now, use the Address API to retrieve each of the expected new
|
||||
// addresses and ensure they're accurate.
|
||||
net := tc.manager.Net()
|
||||
chainParams := tc.manager.ChainParams()
|
||||
for i := 0; i < len(expectedAddrs); i++ {
|
||||
pkHash := expectedAddrs[i].addressHash
|
||||
utilAddr, err := btcutil.NewAddressPubKeyHash(pkHash, net)
|
||||
utilAddr, err := btcutil.NewAddressPubKeyHash(pkHash,
|
||||
chainParams)
|
||||
if err != nil {
|
||||
tc.t.Errorf("%s NewAddressPubKeyHash #%d: "+
|
||||
"unexpected error: %v", prefix, i, err)
|
||||
|
@ -571,10 +572,11 @@ func testInternalAddresses(tc *testContext) bool {
|
|||
|
||||
// Now, use the Address API to retrieve each of the expected new
|
||||
// addresses and ensure they're accurate.
|
||||
net := tc.manager.Net()
|
||||
chainParams := tc.manager.ChainParams()
|
||||
for i := 0; i < len(expectedAddrs); i++ {
|
||||
pkHash := expectedAddrs[i].addressHash
|
||||
utilAddr, err := btcutil.NewAddressPubKeyHash(pkHash, net)
|
||||
utilAddr, err := btcutil.NewAddressPubKeyHash(pkHash,
|
||||
chainParams)
|
||||
if err != nil {
|
||||
tc.t.Errorf("%s NewAddressPubKeyHash #%d: "+
|
||||
"unexpected error: %v", prefix, i, err)
|
||||
|
@ -794,7 +796,7 @@ func testImportPrivateKey(tc *testContext) bool {
|
|||
|
||||
// Setup a closure to test the results since the same tests need to be
|
||||
// repeated with the manager unlocked and locked.
|
||||
net := tc.manager.Net()
|
||||
chainParams := tc.manager.ChainParams()
|
||||
testResults := func() bool {
|
||||
failed := false
|
||||
for i, test := range tests {
|
||||
|
@ -803,7 +805,7 @@ func testImportPrivateKey(tc *testContext) bool {
|
|||
// Use the Address API to retrieve each of the expected
|
||||
// new addresses and ensure they're accurate.
|
||||
utilAddr, err := btcutil.NewAddressPubKeyHash(
|
||||
test.expected.addressHash, net)
|
||||
test.expected.addressHash, chainParams)
|
||||
if err != nil {
|
||||
tc.t.Errorf("%s NewAddressPubKeyHash #%d (%s): "+
|
||||
"unexpected error: %v", prefix, i,
|
||||
|
@ -947,7 +949,7 @@ func testImportScript(tc *testContext) bool {
|
|||
|
||||
// Setup a closure to test the results since the same tests need to be
|
||||
// repeated with the manager unlocked and locked.
|
||||
net := tc.manager.Net()
|
||||
chainParams := tc.manager.ChainParams()
|
||||
testResults := func() bool {
|
||||
failed := false
|
||||
for i, test := range tests {
|
||||
|
@ -955,7 +957,8 @@ func testImportScript(tc *testContext) bool {
|
|||
|
||||
// Use the Address API to retrieve each of the expected
|
||||
// new addresses and ensure they're accurate.
|
||||
utilAddr, err := btcutil.NewAddressScriptHash(test.in, net)
|
||||
utilAddr, err := btcutil.NewAddressScriptHash(test.in,
|
||||
chainParams)
|
||||
if err != nil {
|
||||
tc.t.Errorf("%s NewAddressScriptHash #%d (%s): "+
|
||||
"unexpected error: %v", prefix, i,
|
||||
|
@ -1160,7 +1163,7 @@ func testWatchingOnly(tc *testContext) bool {
|
|||
|
||||
// Open the manager using the namespace and convert it to watching-only.
|
||||
mgr, err := waddrmgr.Open(namespace, pubPassphrase,
|
||||
&btcnet.MainNetParams, fastScrypt)
|
||||
&chaincfg.MainNetParams, fastScrypt)
|
||||
if err != nil {
|
||||
tc.t.Errorf("%v", err)
|
||||
return false
|
||||
|
@ -1183,7 +1186,7 @@ func testWatchingOnly(tc *testContext) bool {
|
|||
mgr.Close()
|
||||
|
||||
// Open the watching-only manager and run all the tests again.
|
||||
mgr, err = waddrmgr.Open(namespace, pubPassphrase, &btcnet.MainNetParams,
|
||||
mgr, err = waddrmgr.Open(namespace, pubPassphrase, &chaincfg.MainNetParams,
|
||||
fastScrypt)
|
||||
if err != nil {
|
||||
tc.t.Errorf("Open Watching-Only: unexpected error: %v", err)
|
||||
|
@ -1330,7 +1333,7 @@ func testSync(tc *testContext) bool {
|
|||
wantHeight := int32(i) - int32(j) + 1
|
||||
var wantHash *wire.ShaHash
|
||||
if wantHeight == 0 {
|
||||
wantHash = btcnet.MainNetParams.GenesisHash
|
||||
wantHash = chaincfg.MainNetParams.GenesisHash
|
||||
} else {
|
||||
wantHash = tests[wantHeight-1].hash
|
||||
}
|
||||
|
@ -1437,7 +1440,7 @@ func testSync(tc *testContext) bool {
|
|||
}
|
||||
blockStamp = waddrmgr.BlockStamp{
|
||||
Height: 0,
|
||||
Hash: *btcnet.MainNetParams.GenesisHash,
|
||||
Hash: *chaincfg.MainNetParams.GenesisHash,
|
||||
}
|
||||
gotBlockStamp = tc.manager.SyncedTo()
|
||||
if gotBlockStamp != blockStamp {
|
||||
|
@ -1468,14 +1471,14 @@ func TestManager(t *testing.T) {
|
|||
// Open manager that does not exist to ensure the expected error is
|
||||
// returned.
|
||||
_, err = waddrmgr.Open(mgrNamespace, pubPassphrase,
|
||||
&btcnet.MainNetParams, fastScrypt)
|
||||
&chaincfg.MainNetParams, fastScrypt)
|
||||
if !checkManagerError(t, "Open non-existant", err, waddrmgr.ErrNoExist) {
|
||||
return
|
||||
}
|
||||
|
||||
// Create a new manager.
|
||||
mgr, err := waddrmgr.Create(mgrNamespace, seed, pubPassphrase,
|
||||
privPassphrase, &btcnet.MainNetParams, fastScrypt)
|
||||
privPassphrase, &chaincfg.MainNetParams, fastScrypt)
|
||||
if err != nil {
|
||||
t.Errorf("Create: unexpected error: %v", err)
|
||||
return
|
||||
|
@ -1487,7 +1490,7 @@ func TestManager(t *testing.T) {
|
|||
// Attempt to create the manager again to ensure the expected error is
|
||||
// returned.
|
||||
_, err = waddrmgr.Create(mgrNamespace, seed, pubPassphrase,
|
||||
privPassphrase, &btcnet.MainNetParams, fastScrypt)
|
||||
privPassphrase, &chaincfg.MainNetParams, fastScrypt)
|
||||
if !checkManagerError(t, "Create existing", err, waddrmgr.ErrAlreadyExists) {
|
||||
mgr.Close()
|
||||
return
|
||||
|
@ -1508,7 +1511,7 @@ func TestManager(t *testing.T) {
|
|||
// Open the manager and run all the tests again in open mode which
|
||||
// avoids reinserting new addresses like the create mode tests do.
|
||||
mgr, err = waddrmgr.Open(mgrNamespace, pubPassphrase,
|
||||
&btcnet.MainNetParams, fastScrypt)
|
||||
&chaincfg.MainNetParams, fastScrypt)
|
||||
if err != nil {
|
||||
t.Errorf("Open: unexpected error: %v", err)
|
||||
return
|
||||
|
|
10
wallet.go
10
wallet.go
|
@ -27,9 +27,9 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/blockchain"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcjson"
|
||||
"github.com/btcsuite/btcnet"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/btcsuite/btcwallet/chain"
|
||||
"github.com/btcsuite/btcwallet/keystore"
|
||||
|
@ -46,15 +46,15 @@ var (
|
|||
|
||||
// networkDir returns the directory name of a network directory to hold wallet
|
||||
// files.
|
||||
func networkDir(net *btcnet.Params) string {
|
||||
netname := net.Name
|
||||
func networkDir(chainParams *chaincfg.Params) string {
|
||||
netname := chainParams.Name
|
||||
|
||||
// For now, we must always name the testnet data directory as "testnet"
|
||||
// and not "testnet3" or any other version, as the btcnet testnet3
|
||||
// and not "testnet3" or any other version, as the chaincfg 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 == wire.TestNet3 {
|
||||
if chainParams.Net == wire.TestNet3 {
|
||||
netname = "testnet"
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue