Rename wallet package to keystore.

This package is used solely for the storage of private and public
keys, and the addresses they represent.  Since "wallet" is an
overloaded term and a working wallet requires transaction history as
well, rename this package and its data structures to more clearly
reflect what it is for.
This commit is contained in:
Josh Rickmar 2014-07-08 13:17:24 -05:00
parent 2d9fb71afd
commit 3dba4ba87d
9 changed files with 556 additions and 549 deletions

View file

@ -24,8 +24,8 @@ import (
"github.com/conformal/btcjson" "github.com/conformal/btcjson"
"github.com/conformal/btcutil" "github.com/conformal/btcutil"
"github.com/conformal/btcwallet/keystore"
"github.com/conformal/btcwallet/txstore" "github.com/conformal/btcwallet/txstore"
"github.com/conformal/btcwallet/wallet"
"github.com/conformal/btcwire" "github.com/conformal/btcwire"
) )
@ -34,17 +34,17 @@ import (
// addresses and keys), and tx and utxo stores, and a mutex to prevent // addresses and keys), and tx and utxo stores, and a mutex to prevent
// incorrect multiple access. // incorrect multiple access.
type Account struct { type Account struct {
name string name string
*wallet.Wallet KeyStore *keystore.Store
TxStore *txstore.Store TxStore *txstore.Store
lockedOutpoints map[btcwire.OutPoint]struct{} lockedOutpoints map[btcwire.OutPoint]struct{}
FeeIncrement btcutil.Amount FeeIncrement btcutil.Amount
} }
func newAccount(name string, w *wallet.Wallet, txs *txstore.Store) *Account { func newAccount(name string, keys *keystore.Store, txs *txstore.Store) *Account {
return &Account{ return &Account{
name: name, name: name,
Wallet: w, KeyStore: keys,
TxStore: txs, TxStore: txs,
lockedOutpoints: map[btcwire.OutPoint]struct{}{}, lockedOutpoints: map[btcwire.OutPoint]struct{}{},
FeeIncrement: defaultFeeIncrement, FeeIncrement: defaultFeeIncrement,
@ -53,12 +53,12 @@ func newAccount(name string, w *wallet.Wallet, txs *txstore.Store) *Account {
// Lock locks the underlying wallet for an account. // Lock locks the underlying wallet for an account.
func (a *Account) Lock() error { func (a *Account) Lock() error {
switch err := a.Wallet.Lock(); err { switch err := a.KeyStore.Lock(); err {
case nil: case nil:
server.NotifyWalletLockStateChange(a.Name(), true) server.NotifyWalletLockStateChange(a.KeyStore.Name(), true)
return nil return nil
case wallet.ErrWalletLocked: case keystore.ErrLocked:
// Do not pass wallet already locked errors to the caller. // Do not pass wallet already locked errors to the caller.
return nil return nil
@ -69,11 +69,11 @@ func (a *Account) Lock() error {
// Unlock unlocks the underlying wallet for an account. // Unlock unlocks the underlying wallet for an account.
func (a *Account) Unlock(passphrase []byte) error { func (a *Account) Unlock(passphrase []byte) error {
if err := a.Wallet.Unlock(passphrase); err != nil { if err := a.KeyStore.Unlock(passphrase); err != nil {
return err return err
} }
server.NotifyWalletLockStateChange(a.Name(), false) server.NotifyWalletLockStateChange(a.KeyStore.Name(), false)
return nil return nil
} }
@ -173,7 +173,7 @@ func (a *Account) CalculateAddressBalance(addr btcutil.Address, confirms int) (b
// one transaction spending to it in the blockchain or btcd mempool), the next // one transaction spending to it in the blockchain or btcd mempool), the next
// chained address is returned. // chained address is returned.
func (a *Account) CurrentAddress() (btcutil.Address, error) { func (a *Account) CurrentAddress() (btcutil.Address, error) {
addr := a.Wallet.LastChainedAddress() addr := a.KeyStore.LastChainedAddress()
// Get next chained address if the last one has already been used. // Get next chained address if the last one has already been used.
if a.AddressUsed(addr) { if a.AddressUsed(addr) {
@ -203,7 +203,8 @@ func (a *Account) ListSinceBlock(since, curBlockHeight int32,
continue continue
} }
jsonResults, err := txRecord.ToJSON(a.name, curBlockHeight, a.Net()) jsonResults, err := txRecord.ToJSON(a.name, curBlockHeight,
a.KeyStore.Net())
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -234,7 +235,8 @@ func (a *Account) ListTransactions(from, count int) ([]btcjson.ListTransactionsR
lastLookupIdx := len(records) - count lastLookupIdx := len(records) - count
// Search in reverse order: lookup most recently-added first. // Search in reverse order: lookup most recently-added first.
for i := len(records) - 1; i >= from && i >= lastLookupIdx; i-- { for i := len(records) - 1; i >= from && i >= lastLookupIdx; i-- {
jsonResults, err := records[i].ToJSON(a.name, bs.Height, a.Net()) jsonResults, err := records[i].ToJSON(a.name, bs.Height,
a.KeyStore.Net())
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -279,7 +281,8 @@ func (a *Account) ListAddressTransactions(pkHashes map[string]struct{}) (
if _, ok := pkHashes[string(apkh.ScriptAddress())]; !ok { if _, ok := pkHashes[string(apkh.ScriptAddress())]; !ok {
continue continue
} }
jsonResult, err := c.ToJSON(a.name, bs.Height, a.Net()) jsonResult, err := c.ToJSON(a.name, bs.Height,
a.KeyStore.Net())
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -310,7 +313,8 @@ func (a *Account) ListAllTransactions() ([]btcjson.ListTransactionsResult, error
// Search in reverse order: lookup most recently-added first. // Search in reverse order: lookup most recently-added first.
records := a.TxStore.Records() records := a.TxStore.Records()
for i := len(records) - 1; i >= 0; i-- { for i := len(records) - 1; i >= 0; i-- {
jsonResults, err := records[i].ToJSON(a.name, bs.Height, a.Net()) jsonResults, err := records[i].ToJSON(a.name, bs.Height,
a.KeyStore.Net())
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -326,9 +330,9 @@ func (a *Account) DumpPrivKeys() ([]string, error) {
// Iterate over each active address, appending the private // Iterate over each active address, appending the private
// key to privkeys. // key to privkeys.
privkeys := []string{} privkeys := []string{}
for _, info := range a.Wallet.ActiveAddresses() { for _, info := range a.KeyStore.ActiveAddresses() {
// Only those addresses with keys needed. // Only those addresses with keys needed.
pka, ok := info.(wallet.PubKeyAddress) pka, ok := info.(keystore.PubKeyAddress)
if !ok { if !ok {
continue continue
} }
@ -349,12 +353,12 @@ func (a *Account) DumpPrivKeys() ([]string, error) {
// single wallet address. // single wallet address.
func (a *Account) DumpWIFPrivateKey(addr btcutil.Address) (string, error) { func (a *Account) DumpWIFPrivateKey(addr btcutil.Address) (string, error) {
// Get private key from wallet if it exists. // Get private key from wallet if it exists.
address, err := a.Wallet.Address(addr) address, err := a.KeyStore.Address(addr)
if err != nil { if err != nil {
return "", err return "", err
} }
pka, ok := address.(wallet.PubKeyAddress) pka, ok := address.(keystore.PubKeyAddress)
if !ok { if !ok {
return "", fmt.Errorf("address %s is not a key type", addr) return "", fmt.Errorf("address %s is not a key type", addr)
} }
@ -368,11 +372,11 @@ func (a *Account) DumpWIFPrivateKey(addr btcutil.Address) (string, error) {
// ImportPrivateKey imports a private key to the account's wallet and // ImportPrivateKey imports a private key to the account's wallet and
// writes the new wallet to disk. // writes the new wallet to disk.
func (a *Account) ImportPrivateKey(wif *btcutil.WIF, bs *wallet.BlockStamp, func (a *Account) ImportPrivateKey(wif *btcutil.WIF, bs *keystore.BlockStamp,
rescan bool) (string, error) { rescan bool) (string, error) {
// Attempt to import private key into wallet. // Attempt to import private key into wallet.
addr, err := a.Wallet.ImportPrivateKey(wif, bs) addr, err := a.KeyStore.ImportPrivateKey(wif, bs)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -430,13 +434,13 @@ func (a *Account) ExportToDirectory(dirBaseName string) error {
// should be exported quickly, either to file or to an rpc caller, and then // should be exported quickly, either to file or to an rpc caller, and then
// dropped from scope. // dropped from scope.
func (a *Account) ExportWatchingWallet() (*Account, error) { func (a *Account) ExportWatchingWallet() (*Account, error) {
ww, err := a.Wallet.ExportWatchingWallet() ww, err := a.KeyStore.ExportWatchingWallet()
if err != nil { if err != nil {
return nil, err return nil, err
} }
wa := *a wa := *a
wa.Wallet = ww wa.KeyStore = ww
return &wa, nil return &wa, nil
} }
@ -446,7 +450,7 @@ func (a *Account) exportBase64() (map[string]string, error) {
buf := bytes.Buffer{} buf := bytes.Buffer{}
m := make(map[string]string) m := make(map[string]string)
_, err := a.Wallet.WriteTo(&buf) _, err := a.KeyStore.WriteTo(&buf)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -517,7 +521,7 @@ func (a *Account) Track() {
// //
// TODO: return as slice? (doesn't have to be ordered, or // TODO: return as slice? (doesn't have to be ordered, or
// SortedActiveAddresses would be fine.) // SortedActiveAddresses would be fine.)
addrMap := a.ActiveAddresses() addrMap := a.KeyStore.ActiveAddresses()
addrs := make([]btcutil.Address, 0, len(addrMap)) addrs := make([]btcutil.Address, 0, len(addrMap))
for addr := range addrMap { for addr := range addrMap {
addrs = append(addrs, addr) addrs = append(addrs, addr)
@ -542,9 +546,9 @@ func (a *Account) Track() {
func (a *Account) RescanActiveJob() (*RescanJob, error) { func (a *Account) RescanActiveJob() (*RescanJob, error) {
// Determine the block necesary to start the rescan for all active // Determine the block necesary to start the rescan for all active
// addresses. // addresses.
height := a.SyncHeight() height := a.KeyStore.SyncHeight()
actives := a.SortedActiveAddresses() actives := a.KeyStore.SortedActiveAddresses()
addrs := make([]btcutil.Address, 0, len(actives)) addrs := make([]btcutil.Address, 0, len(actives))
for i := range actives { for i := range actives {
addrs = append(addrs, actives[i].Address()) addrs = append(addrs, actives[i].Address())
@ -594,7 +598,7 @@ func (a *Account) ResendUnminedTxs() {
// SortedActivePaymentAddresses returns a slice of all active payment // SortedActivePaymentAddresses returns a slice of all active payment
// addresses in an account. // addresses in an account.
func (a *Account) SortedActivePaymentAddresses() []string { func (a *Account) SortedActivePaymentAddresses() []string {
infos := a.Wallet.SortedActiveAddresses() infos := a.KeyStore.SortedActiveAddresses()
addrs := make([]string, len(infos)) addrs := make([]string, len(infos))
for i, info := range infos { for i, info := range infos {
@ -607,7 +611,7 @@ func (a *Account) SortedActivePaymentAddresses() []string {
// ActivePaymentAddresses returns a set of all active pubkey hashes // ActivePaymentAddresses returns a set of all active pubkey hashes
// in an account. // in an account.
func (a *Account) ActivePaymentAddresses() map[string]struct{} { func (a *Account) ActivePaymentAddresses() map[string]struct{} {
infos := a.ActiveAddresses() infos := a.KeyStore.ActiveAddresses()
addrs := make(map[string]struct{}, len(infos)) addrs := make(map[string]struct{}, len(infos))
for _, info := range infos { for _, info := range infos {
@ -630,7 +634,7 @@ func (a *Account) NewAddress() (btcutil.Address, error) {
} }
// Get next address from wallet. // Get next address from wallet.
addr, err := a.Wallet.NextChainedAddress(&bs, cfg.KeypoolSize) addr, err := a.KeyStore.NextChainedAddress(&bs, cfg.KeypoolSize)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -665,7 +669,7 @@ func (a *Account) NewChangeAddress() (btcutil.Address, error) {
} }
// Get next chained change address from wallet. // Get next chained change address from wallet.
addr, err := a.Wallet.ChangeAddress(&bs, cfg.KeypoolSize) addr, err := a.KeyStore.ChangeAddress(&bs, cfg.KeypoolSize)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -691,13 +695,13 @@ func (a *Account) NewChangeAddress() (btcutil.Address, error) {
func (a *Account) RecoverAddresses(n int) error { func (a *Account) RecoverAddresses(n int) error {
// Get info on the last chained address. The rescan starts at the // Get info on the last chained address. The rescan starts at the
// earliest block height the last chained address might appear at. // earliest block height the last chained address might appear at.
last := a.Wallet.LastChainedAddress() last := a.KeyStore.LastChainedAddress()
lastInfo, err := a.Wallet.Address(last) lastInfo, err := a.KeyStore.Address(last)
if err != nil { if err != nil {
return err return err
} }
addrs, err := a.Wallet.ExtendActiveAddresses(n, cfg.KeypoolSize) addrs, err := a.KeyStore.ExtendActiveAddresses(n, cfg.KeypoolSize)
if err != nil { if err != nil {
return err return err
} }

View file

@ -30,8 +30,8 @@ import (
"github.com/conformal/btcchain" "github.com/conformal/btcchain"
"github.com/conformal/btcjson" "github.com/conformal/btcjson"
"github.com/conformal/btcutil" "github.com/conformal/btcutil"
"github.com/conformal/btcwallet/keystore"
"github.com/conformal/btcwallet/txstore" "github.com/conformal/btcwallet/txstore"
"github.com/conformal/btcwallet/wallet"
"github.com/conformal/btcwire" "github.com/conformal/btcwire"
) )
@ -219,9 +219,9 @@ func openSavedAccount(name string, cfg *config) (*Account, error) {
} }
} }
wlt := new(wallet.Wallet) keys := new(keystore.Store)
txs := txstore.New() txs := txstore.New()
a := newAccount(name, wlt, txs) a := newAccount(name, keys, txs)
walletPath := accountFilename("wallet.bin", name, netdir) walletPath := accountFilename("wallet.bin", name, netdir)
txstorePath := accountFilename("tx.bin", name, netdir) txstorePath := accountFilename("tx.bin", name, netdir)
@ -236,7 +236,7 @@ func openSavedAccount(name string, cfg *config) (*Account, error) {
msg := fmt.Sprintf("cannot open wallet file: %s", err) msg := fmt.Sprintf("cannot open wallet file: %s", err)
return nil, &walletOpenError{msg} return nil, &walletOpenError{msg}
} }
if _, err = wlt.ReadFrom(walletFi); err != nil { if _, err = keys.ReadFrom(walletFi); err != nil {
if err := walletFi.Close(); err != nil { if err := walletFi.Close(); err != nil {
log.Warnf("Cannot close wallet file: %v", err) log.Warnf("Cannot close wallet file: %v", err)
} }
@ -329,12 +329,12 @@ func writeUnsyncedWallet(a *Account, path string) error {
// to SyncHeight will use the wallet creation height, or possibly // to SyncHeight will use the wallet creation height, or possibly
// an earlier height for imported keys. // an earlier height for imported keys.
netdir, _ := filepath.Split(path) netdir, _ := filepath.Split(path)
a.SetSyncedWith(nil) a.KeyStore.SetSyncedWith(nil)
tmpwallet, err := ioutil.TempFile(netdir, "wallet.bin") tmpwallet, err := ioutil.TempFile(netdir, "wallet.bin")
if err != nil { if err != nil {
return fmt.Errorf("cannot create temporary wallet: %v", err) return fmt.Errorf("cannot create temporary wallet: %v", err)
} }
if _, err := a.Wallet.WriteTo(tmpwallet); err != nil { if _, err := a.KeyStore.WriteTo(tmpwallet); err != nil {
return fmt.Errorf("cannot write back unsynced wallet: %v", err) return fmt.Errorf("cannot write back unsynced wallet: %v", err)
} }
tmpwalletpath := tmpwallet.Name() tmpwalletpath := tmpwallet.Name()
@ -552,7 +552,8 @@ func (am *AccountManager) rescanListener() {
case *RescanProgressMsg: case *RescanProgressMsg:
for acct, addrs := range e.Addresses { for acct, addrs := range e.Addresses {
for i := range addrs { for i := range addrs {
err := acct.SetSyncStatus(addrs[i], wallet.PartialSync(e.Height)) err := acct.KeyStore.SetSyncStatus(addrs[i],
keystore.PartialSync(e.Height))
if err != nil { if err != nil {
log.Errorf("Error marking address partially synced: %v", err) log.Errorf("Error marking address partially synced: %v", err)
continue continue
@ -577,7 +578,8 @@ func (am *AccountManager) rescanListener() {
for acct, addrs := range e.Addresses { for acct, addrs := range e.Addresses {
n += len(addrs) n += len(addrs)
for i := range addrs { for i := range addrs {
err := acct.SetSyncStatus(addrs[i], wallet.FullSync{}) err := acct.KeyStore.SetSyncStatus(addrs[i],
keystore.FullSync{})
if err != nil { if err != nil {
log.Errorf("Error marking address synced: %v", err) log.Errorf("Error marking address synced: %v", err)
continue continue
@ -672,13 +674,13 @@ func (am *AccountManager) MarkAddressForAccount(address btcutil.Address,
} }
// Address looks up an address if it is known to wallet at all. // Address looks up an address if it is known to wallet at all.
func (am *AccountManager) Address(addr btcutil.Address) (wallet.WalletAddress, error) { func (am *AccountManager) Address(addr btcutil.Address) (keystore.WalletAddress, error) {
a, err := am.AccountByAddress(addr) a, err := am.AccountByAddress(addr)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return a.Address(addr) return a.KeyStore.Address(addr)
} }
// AllAccounts returns a slice of all managed accounts. // AllAccounts returns a slice of all managed accounts.
@ -748,7 +750,7 @@ func (am *AccountManager) Rollback(height int32, hash *btcwire.ShaHash) error {
// BlockNotify notifies all wallet clients of any changes from the new block, // BlockNotify notifies all wallet clients of any changes from the new block,
// including changed balances. Each account is then set to be synced // including changed balances. Each account is then set to be synced
// with the latest block. // with the latest block.
func (am *AccountManager) BlockNotify(bs *wallet.BlockStamp) { func (am *AccountManager) BlockNotify(bs *keystore.BlockStamp) {
for _, a := range am.AllAccounts() { for _, a := range am.AllAccounts() {
// TODO: need a flag or check that the utxo store was actually // TODO: need a flag or check that the utxo store was actually
// modified, or this will notify even if there are no balance // modified, or this will notify even if there are no balance
@ -766,8 +768,8 @@ func (am *AccountManager) BlockNotify(bs *wallet.BlockStamp) {
// If this is the default account, update the block all accounts // If this is the default account, update the block all accounts
// are synced with, and schedule a wallet write. // are synced with, and schedule a wallet write.
if a.Name() == "" { if a.KeyStore.Name() == "" {
a.Wallet.SetSyncedWith(bs) a.KeyStore.SetSyncedWith(bs)
am.ds.ScheduleWalletWrite(a) am.ds.ScheduleWalletWrite(a)
} }
} }
@ -825,7 +827,7 @@ func (am *AccountManager) CreateEncryptedWallet(passphrase []byte) error {
} }
// Create new wallet in memory. // Create new wallet in memory.
wlt, err := wallet.NewWallet("", "Default acccount", passphrase, keys, err := keystore.NewStore("", "Default acccount", passphrase,
activeNet.Params, &bs, cfg.KeypoolSize) activeNet.Params, &bs, cfg.KeypoolSize)
if err != nil { if err != nil {
return err return err
@ -834,7 +836,7 @@ func (am *AccountManager) CreateEncryptedWallet(passphrase []byte) error {
// Create new account and begin managing with the global account // Create new account and begin managing with the global account
// manager. Registering will fail if the new account can not be // manager. Registering will fail if the new account can not be
// written immediately to disk. // written immediately to disk.
a := newAccount("", wlt, txstore.New()) a := newAccount("", keys, txstore.New())
if err := am.RegisterNewAccount(a); err != nil { if err := am.RegisterNewAccount(a); err != nil {
return err return err
} }
@ -858,7 +860,7 @@ func (am *AccountManager) ChangePassphrase(old, new []byte) error {
// Change passphrase for each unlocked wallet. // Change passphrase for each unlocked wallet.
for _, a := range accts { for _, a := range accts {
err = a.Wallet.ChangePassphrase(new) err = a.KeyStore.ChangePassphrase(new)
if err != nil { if err != nil {
return err return err
} }
@ -893,7 +895,7 @@ func (am *AccountManager) DumpKeys() ([]string, error) {
keys := []string{} keys := []string{}
for _, a := range am.AllAccounts() { for _, a := range am.AllAccounts() {
switch walletKeys, err := a.DumpPrivKeys(); err { switch walletKeys, err := a.DumpPrivKeys(); err {
case wallet.ErrWalletLocked: case keystore.ErrLocked:
return nil, err return nil, err
case nil: case nil:
@ -1055,7 +1057,7 @@ func (am *AccountManager) ListUnspent(minconf, maxconf int,
result := &btcjson.ListUnspentResult{ result := &btcjson.ListUnspentResult{
TxId: credit.Tx().Sha().String(), TxId: credit.Tx().Sha().String(),
Vout: credit.OutputIndex, Vout: credit.OutputIndex,
Account: a.Name(), Account: a.KeyStore.Name(),
ScriptPubKey: hex.EncodeToString(credit.TxOut().PkScript), ScriptPubKey: hex.EncodeToString(credit.TxOut().PkScript),
Amount: credit.Amount().ToUnit(btcutil.AmountBTC), Amount: credit.Amount().ToUnit(btcutil.AmountBTC),
Confirmations: int64(confs), Confirmations: int64(confs),
@ -1082,7 +1084,7 @@ func (am *AccountManager) ListUnspent(minconf, maxconf int,
// caller to mark the progress that the rescan is expected to complete // caller to mark the progress that the rescan is expected to complete
// through, if the account otherwise does not contain any recently // through, if the account otherwise does not contain any recently
// seen blocks. // seen blocks.
func (am *AccountManager) RescanActiveAddresses(markBestBlock *wallet.BlockStamp) error { func (am *AccountManager) RescanActiveAddresses(markBestBlock *keystore.BlockStamp) error {
var job *RescanJob var job *RescanJob
var defaultAcct *Account var defaultAcct *Account
for _, a := range am.AllAccounts() { for _, a := range am.AllAccounts() {
@ -1102,7 +1104,7 @@ func (am *AccountManager) RescanActiveAddresses(markBestBlock *wallet.BlockStamp
} }
if job != nil { if job != nil {
if markBestBlock != nil { if markBestBlock != nil {
defaultAcct.SetSyncedWith(markBestBlock) defaultAcct.KeyStore.SetSyncedWith(markBestBlock)
} }
// Submit merged job and block until rescan completes. // Submit merged job and block until rescan completes.

View file

@ -27,8 +27,8 @@ import (
"github.com/conformal/btcchain" "github.com/conformal/btcchain"
"github.com/conformal/btcscript" "github.com/conformal/btcscript"
"github.com/conformal/btcutil" "github.com/conformal/btcutil"
"github.com/conformal/btcwallet/keystore"
"github.com/conformal/btcwallet/txstore" "github.com/conformal/btcwallet/txstore"
"github.com/conformal/btcwallet/wallet"
"github.com/conformal/btcwire" "github.com/conformal/btcwire"
) )
@ -118,8 +118,8 @@ func (a *Account) txToPairs(pairs map[string]btcutil.Amount,
minconf int) (*CreatedTx, error) { minconf int) (*CreatedTx, error) {
// Wallet must be unlocked to compose transaction. // Wallet must be unlocked to compose transaction.
if a.IsLocked() { if a.KeyStore.IsLocked() {
return nil, wallet.ErrWalletLocked return nil, keystore.ErrLocked
} }
// Create a new transaction which will include all input scripts. // Create a new transaction which will include all input scripts.
@ -228,7 +228,7 @@ func (a *Account) txToPairs(pairs map[string]btcutil.Amount,
if change > 0 { if change > 0 {
// Get a new change address if one has not already been found. // Get a new change address if one has not already been found.
if changeAddr == nil { if changeAddr == nil {
changeAddr, err = a.ChangeAddress(&bs, cfg.KeypoolSize) changeAddr, err = a.KeyStore.ChangeAddress(&bs, cfg.KeypoolSize)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to get next address: %s", err) return nil, fmt.Errorf("failed to get next address: %s", err)
} }
@ -267,16 +267,16 @@ func (a *Account) txToPairs(pairs map[string]btcutil.Amount,
continue // don't handle inputs to this yes continue // don't handle inputs to this yes
} }
ai, err := a.Address(apkh) ai, err := a.KeyStore.Address(apkh)
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot get address info: %v", err) return nil, fmt.Errorf("cannot get address info: %v", err)
} }
pka := ai.(wallet.PubKeyAddress) pka := ai.(keystore.PubKeyAddress)
privkey, err := pka.PrivKey() privkey, err := pka.PrivKey()
if err == wallet.ErrWalletLocked { if err == keystore.ErrLocked {
return nil, wallet.ErrWalletLocked return nil, keystore.ErrLocked
} else if err != nil { } else if err != nil {
return nil, fmt.Errorf("cannot get address key: %v", err) return nil, fmt.Errorf("cannot get address key: %v", err)
} }

View file

@ -83,8 +83,8 @@ func TestAllowFree(t *testing.T) {
func TestFakeTxs(t *testing.T) { func TestFakeTxs(t *testing.T) {
// First we need a wallet. // First we need a wallet.
w, err := wallet.NewWallet("banana wallet", "", []byte("banana"), w, err := keystore.NewStore("banana wallet", "", []byte("banana"),
btcwire.MainNet, &wallet.BlockStamp{}, 100) btcwire.MainNet, &keystore.BlockStamp{}, 100)
if err != nil { if err != nil {
t.Errorf("Can not create encrypted wallet: %s", err) t.Errorf("Can not create encrypted wallet: %s", err)
return return
@ -101,7 +101,7 @@ func TestFakeTxs(t *testing.T) {
// This will pass validation because btcscript is unaware of invalid // This will pass validation because btcscript is unaware of invalid
// tx inputs, however, this example would fail in btcd. // tx inputs, however, this example would fail in btcd.
utxo := &tx.Utxo{} utxo := &tx.Utxo{}
addr, err := w.NextChainedAddress(&wallet.BlockStamp{}, 100) addr, err := w.NextChainedAddress(&keystore.BlockStamp{}, 100)
if err != nil { if err != nil {
t.Errorf("Cannot get next address: %s", err) t.Errorf("Cannot get next address: %s", err)
return return

View file

@ -394,7 +394,7 @@ func (a *Account) writeWallet(dir string) error {
if err != nil { if err != nil {
return err return err
} }
if _, err = a.Wallet.WriteTo(tmpfile); err != nil { if _, err = a.KeyStore.WriteTo(tmpfile); err != nil {
return err return err
} }

File diff suppressed because it is too large Load diff

View file

@ -14,7 +14,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
package wallet package keystore
import ( import (
"bytes" "bytes"
@ -35,7 +35,7 @@ import (
var tstNetParams = &btcnet.MainNetParams var tstNetParams = &btcnet.MainNetParams
func TestBtcAddressSerializer(t *testing.T) { func TestBtcAddressSerializer(t *testing.T) {
fakeWallet := &Wallet{net: (*netParams)(tstNetParams)} fakeWallet := &Store{net: (*netParams)(tstNetParams)}
kdfp := &kdfParameters{ kdfp := &kdfParameters{
mem: 1024, mem: 1024,
nIter: 5, nIter: 5,
@ -70,7 +70,7 @@ func TestBtcAddressSerializer(t *testing.T) {
} }
var readAddr btcAddress var readAddr btcAddress
readAddr.wallet = fakeWallet readAddr.store = fakeWallet
_, err = readAddr.ReadFrom(buf) _, err = readAddr.ReadFrom(buf)
if err != nil { if err != nil {
t.Error(err.Error()) t.Error(err.Error())
@ -88,7 +88,7 @@ func TestBtcAddressSerializer(t *testing.T) {
} }
func TestScriptAddressSerializer(t *testing.T) { func TestScriptAddressSerializer(t *testing.T) {
fakeWallet := &Wallet{net: (*netParams)(tstNetParams)} fakeWallet := &Store{net: (*netParams)(tstNetParams)}
script := []byte{btcscript.OP_TRUE, btcscript.OP_DUP, script := []byte{btcscript.OP_TRUE, btcscript.OP_DUP,
btcscript.OP_DROP} btcscript.OP_DROP}
addr, err := newScriptAddress(fakeWallet, script, &BlockStamp{}) addr, err := newScriptAddress(fakeWallet, script, &BlockStamp{})
@ -105,7 +105,7 @@ func TestScriptAddressSerializer(t *testing.T) {
} }
var readAddr scriptAddress var readAddr scriptAddress
readAddr.wallet = fakeWallet readAddr.store = fakeWallet
_, err = readAddr.ReadFrom(buf) _, err = readAddr.ReadFrom(buf)
if err != nil { if err != nil {
t.Error(err.Error()) t.Error(err.Error())
@ -119,7 +119,7 @@ func TestScriptAddressSerializer(t *testing.T) {
func TestWalletCreationSerialization(t *testing.T) { func TestWalletCreationSerialization(t *testing.T) {
createdAt := &BlockStamp{} createdAt := &BlockStamp{}
w1, err := NewWallet("banana wallet", "A wallet for testing.", w1, err := NewStore("banana wallet", "A wallet for testing.",
[]byte("banana"), tstNetParams, createdAt, 100) []byte("banana"), tstNetParams, createdAt, 100)
if err != nil { if err != nil {
t.Error("Error creating new wallet: " + err.Error()) t.Error("Error creating new wallet: " + err.Error())
@ -133,7 +133,7 @@ func TestWalletCreationSerialization(t *testing.T) {
return return
} }
w2 := new(Wallet) w2 := new(Store)
_, err = w2.ReadFrom(buf) _, err = w2.ReadFrom(buf)
if err != nil { if err != nil {
t.Error("Error reading newly written wallet: " + err.Error()) t.Error("Error reading newly written wallet: " + err.Error())
@ -331,7 +331,7 @@ func TestWalletPubkeyChaining(t *testing.T) {
// Set a reasonable keypool size that isn't too big nor too small for testing. // Set a reasonable keypool size that isn't too big nor too small for testing.
const keypoolSize = 5 const keypoolSize = 5
w, err := NewWallet("banana wallet", "A wallet for testing.", w, err := NewStore("banana wallet", "A wallet for testing.",
[]byte("banana"), tstNetParams, &BlockStamp{}, keypoolSize) []byte("banana"), tstNetParams, &BlockStamp{}, keypoolSize)
if err != nil { if err != nil {
t.Error("Error creating new wallet: " + err.Error()) t.Error("Error creating new wallet: " + err.Error())
@ -397,7 +397,7 @@ func TestWalletPubkeyChaining(t *testing.T) {
t.Errorf("Error writing wallet with missing private key: %v", err) t.Errorf("Error writing wallet with missing private key: %v", err)
return return
} }
w2 := new(Wallet) w2 := new(Store)
_, err = w2.ReadFrom(serializedWallet) _, err = w2.ReadFrom(serializedWallet)
if err != nil { if err != nil {
t.Errorf("Error reading wallet with missing private key: %v", err) t.Errorf("Error reading wallet with missing private key: %v", err)
@ -507,7 +507,7 @@ func TestWalletPubkeyChaining(t *testing.T) {
func TestWatchingWalletExport(t *testing.T) { func TestWatchingWalletExport(t *testing.T) {
const keypoolSize = 10 const keypoolSize = 10
createdAt := &BlockStamp{} createdAt := &BlockStamp{}
w, err := NewWallet("banana wallet", "A wallet for testing.", w, err := NewStore("banana wallet", "A wallet for testing.",
[]byte("banana"), tstNetParams, createdAt, keypoolSize) []byte("banana"), tstNetParams, createdAt, keypoolSize)
if err != nil { if err != nil {
t.Error("Error creating new wallet: " + err.Error()) t.Error("Error creating new wallet: " + err.Error())
@ -681,7 +681,7 @@ func TestWatchingWalletExport(t *testing.T) {
t.Errorf("Cannot write watching wallet: %v", err) t.Errorf("Cannot write watching wallet: %v", err)
return return
} }
ww2 := new(Wallet) ww2 := new(Store)
_, err = ww2.ReadFrom(buf) _, err = ww2.ReadFrom(buf)
if err != nil { if err != nil {
t.Errorf("Cannot read watching wallet: %v", err) t.Errorf("Cannot read watching wallet: %v", err)
@ -695,11 +695,11 @@ func TestWatchingWalletExport(t *testing.T) {
} }
// Verify that nonsensical functions fail with correct error. // Verify that nonsensical functions fail with correct error.
if err := ww.Lock(); err != ErrWalletIsWatchingOnly { if err := ww.Lock(); err != ErrWatchingOnly {
t.Errorf("Nonsensical func Lock returned no or incorrect error: %v", err) t.Errorf("Nonsensical func Lock returned no or incorrect error: %v", err)
return return
} }
if err := ww.Unlock([]byte("banana")); err != ErrWalletIsWatchingOnly { if err := ww.Unlock([]byte("banana")); err != ErrWatchingOnly {
t.Errorf("Nonsensical func Unlock returned no or incorrect error: %v", err) t.Errorf("Nonsensical func Unlock returned no or incorrect error: %v", err)
return return
} }
@ -708,11 +708,11 @@ func TestWatchingWalletExport(t *testing.T) {
t.Errorf("generator isnt' present in wallet") t.Errorf("generator isnt' present in wallet")
} }
gpk := generator.(PubKeyAddress) gpk := generator.(PubKeyAddress)
if _, err := gpk.PrivKey(); err != ErrWalletIsWatchingOnly { if _, err := gpk.PrivKey(); err != ErrWatchingOnly {
t.Errorf("Nonsensical func AddressKey returned no or incorrect error: %v", err) t.Errorf("Nonsensical func AddressKey returned no or incorrect error: %v", err)
return return
} }
if _, err := ww.ExportWatchingWallet(); err != ErrWalletIsWatchingOnly { if _, err := ww.ExportWatchingWallet(); err != ErrWatchingOnly {
t.Errorf("Nonsensical func ExportWatchingWallet returned no or incorrect error: %v", err) t.Errorf("Nonsensical func ExportWatchingWallet returned no or incorrect error: %v", err)
return return
} }
@ -721,7 +721,7 @@ func TestWatchingWalletExport(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if _, err := ww.ImportPrivateKey(wif, createdAt); err != ErrWalletIsWatchingOnly { if _, err := ww.ImportPrivateKey(wif, createdAt); err != ErrWatchingOnly {
t.Errorf("Nonsensical func ImportPrivateKey returned no or incorrect error: %v", err) t.Errorf("Nonsensical func ImportPrivateKey returned no or incorrect error: %v", err)
return return
} }
@ -731,7 +731,7 @@ func TestImportPrivateKey(t *testing.T) {
const keypoolSize = 10 const keypoolSize = 10
createHeight := int32(100) createHeight := int32(100)
createdAt := &BlockStamp{Height: createHeight} createdAt := &BlockStamp{Height: createHeight}
w, err := NewWallet("banana wallet", "A wallet for testing.", w, err := NewStore("banana wallet", "A wallet for testing.",
[]byte("banana"), tstNetParams, createdAt, keypoolSize) []byte("banana"), tstNetParams, createdAt, keypoolSize)
if err != nil { if err != nil {
t.Error("Error creating new wallet: " + err.Error()) t.Error("Error creating new wallet: " + err.Error())
@ -802,7 +802,7 @@ func TestImportPrivateKey(t *testing.T) {
t.Errorf("Cannot write wallet: %v", err) t.Errorf("Cannot write wallet: %v", err)
return return
} }
w2 := new(Wallet) w2 := new(Store)
_, err = w2.ReadFrom(buf) _, err = w2.ReadFrom(buf)
if err != nil { if err != nil {
t.Errorf("Cannot read wallet: %v", err) t.Errorf("Cannot read wallet: %v", err)
@ -834,7 +834,7 @@ func TestImportPrivateKey(t *testing.T) {
t.Errorf("Cannot write wallet: %v", err) t.Errorf("Cannot write wallet: %v", err)
return return
} }
w3 := new(Wallet) w3 := new(Store)
_, err = w3.ReadFrom(buf) _, err = w3.ReadFrom(buf)
if err != nil { if err != nil {
t.Errorf("Cannot read wallet: %v", err) t.Errorf("Cannot read wallet: %v", err)
@ -901,7 +901,7 @@ func TestImportScript(t *testing.T) {
const keypoolSize = 10 const keypoolSize = 10
createHeight := int32(100) createHeight := int32(100)
createdAt := &BlockStamp{Height: createHeight} createdAt := &BlockStamp{Height: createHeight}
w, err := NewWallet("banana wallet", "A wallet for testing.", w, err := NewStore("banana wallet", "A wallet for testing.",
[]byte("banana"), tstNetParams, createdAt, keypoolSize) []byte("banana"), tstNetParams, createdAt, keypoolSize)
if err != nil { if err != nil {
t.Error("Error creating new wallet: " + err.Error()) t.Error("Error creating new wallet: " + err.Error())
@ -1020,7 +1020,7 @@ func TestImportScript(t *testing.T) {
t.Errorf("Cannot write wallet: %v", err) t.Errorf("Cannot write wallet: %v", err)
return return
} }
w2 := new(Wallet) w2 := new(Store)
_, err = w2.ReadFrom(buf) _, err = w2.ReadFrom(buf)
if err != nil { if err != nil {
t.Errorf("Cannot read wallet: %v", err) t.Errorf("Cannot read wallet: %v", err)
@ -1137,7 +1137,7 @@ func TestImportScript(t *testing.T) {
t.Errorf("Cannot write wallet: %v", err) t.Errorf("Cannot write wallet: %v", err)
return return
} }
w3 := new(Wallet) w3 := new(Store)
_, err = w3.ReadFrom(buf) _, err = w3.ReadFrom(buf)
if err != nil { if err != nil {
t.Errorf("Cannot read wallet: %v", err) t.Errorf("Cannot read wallet: %v", err)
@ -1183,7 +1183,7 @@ func TestImportScript(t *testing.T) {
func TestChangePassphrase(t *testing.T) { func TestChangePassphrase(t *testing.T) {
const keypoolSize = 10 const keypoolSize = 10
createdAt := &BlockStamp{} createdAt := &BlockStamp{}
w, err := NewWallet("banana wallet", "A wallet for testing.", w, err := NewStore("banana wallet", "A wallet for testing.",
[]byte("banana"), tstNetParams, createdAt, keypoolSize) []byte("banana"), tstNetParams, createdAt, keypoolSize)
if err != nil { if err != nil {
t.Error("Error creating new wallet: " + err.Error()) t.Error("Error creating new wallet: " + err.Error())
@ -1191,7 +1191,7 @@ func TestChangePassphrase(t *testing.T) {
} }
// Changing the passphrase with a locked wallet must fail with ErrWalletLocked. // Changing the passphrase with a locked wallet must fail with ErrWalletLocked.
if err := w.ChangePassphrase([]byte("potato")); err != ErrWalletLocked { if err := w.ChangePassphrase([]byte("potato")); err != ErrLocked {
t.Errorf("Changing passphrase on a locked wallet did not fail correctly: %v", err) t.Errorf("Changing passphrase on a locked wallet did not fail correctly: %v", err)
return return
} }

View file

@ -25,8 +25,8 @@ import (
"github.com/conformal/btcrpcclient" "github.com/conformal/btcrpcclient"
"github.com/conformal/btcscript" "github.com/conformal/btcscript"
"github.com/conformal/btcutil" "github.com/conformal/btcutil"
"github.com/conformal/btcwallet/keystore"
"github.com/conformal/btcwallet/txstore" "github.com/conformal/btcwallet/txstore"
"github.com/conformal/btcwallet/wallet"
"github.com/conformal/btcwire" "github.com/conformal/btcwire"
"github.com/conformal/btcws" "github.com/conformal/btcws"
) )
@ -87,7 +87,7 @@ type (
func (n blockConnected) handleNotification(c *rpcClient) error { func (n blockConnected) handleNotification(c *rpcClient) error {
// Update the blockstamp for the newly-connected block. // Update the blockstamp for the newly-connected block.
bs := wallet.BlockStamp{ bs := keystore.BlockStamp{
Height: n.height, Height: n.height,
Hash: *n.hash, Hash: *n.hash,
} }
@ -220,11 +220,12 @@ func (n recvTx) handleNotification(c *rpcClient) error {
return err return err
} }
AcctMgr.ds.ScheduleTxStoreWrite(a) AcctMgr.ds.ScheduleTxStoreWrite(a)
ltr, err := cred.ToJSON(a.Name(), bs.Height, a.Wallet.Net()) ltr, err := cred.ToJSON(a.KeyStore.Name(), bs.Height,
a.KeyStore.Net())
if err != nil { if err != nil {
return err return err
} }
server.NotifyNewTxDetails(a.Name(), ltr) server.NotifyNewTxDetails(a.KeyStore.Name(), ltr)
break // check whether next txout is a wallet txout break // check whether next txout is a wallet txout
} }
} }
@ -260,7 +261,7 @@ type rpcClient struct {
*btcrpcclient.Client // client to btcd *btcrpcclient.Client // client to btcd
mtx sync.Mutex mtx sync.Mutex
blockStamp wallet.BlockStamp blockStamp keystore.BlockStamp
enqueueNotification chan notification enqueueNotification chan notification
dequeueNotification chan notification dequeueNotification chan notification
@ -271,7 +272,7 @@ type rpcClient struct {
func newRPCClient(certs []byte) (*rpcClient, error) { func newRPCClient(certs []byte) (*rpcClient, error) {
client := rpcClient{ client := rpcClient{
blockStamp: wallet.BlockStamp{ blockStamp: keystore.BlockStamp{
Height: int32(btcutil.BlockHeightUnknown), Height: int32(btcutil.BlockHeightUnknown),
}, },
enqueueNotification: make(chan notification), enqueueNotification: make(chan notification),
@ -433,7 +434,7 @@ func (c *rpcClient) handleNotifications() {
// block from the RPC client. If no blocks have been seen (the height is -1), // block from the RPC client. If no blocks have been seen (the height is -1),
// the chain server is queried for the block and the result is saved for future // the chain server is queried for the block and the result is saved for future
// calls, or an error is returned if the RPC is unsuccessful. // calls, or an error is returned if the RPC is unsuccessful.
func (c *rpcClient) BlockStamp() (wallet.BlockStamp, error) { func (c *rpcClient) BlockStamp() (keystore.BlockStamp, error) {
c.mtx.Lock() c.mtx.Lock()
defer c.mtx.Unlock() defer c.mtx.Unlock()
@ -443,9 +444,9 @@ func (c *rpcClient) BlockStamp() (wallet.BlockStamp, error) {
hash, height, err := c.GetBestBlock() hash, height, err := c.GetBestBlock()
if err != nil { if err != nil {
return wallet.BlockStamp{}, err return keystore.BlockStamp{}, err
} }
bs := wallet.BlockStamp{ bs := keystore.BlockStamp{
Hash: *hash, Hash: *hash,
Height: height, Height: height,
} }
@ -503,7 +504,7 @@ func (c *rpcClient) Handshake() error {
// Check that there was not any reorgs done since last connection. // Check that there was not any reorgs done since last connection.
// If so, rollback and rescan to catch up. // If so, rollback and rescan to catch up.
it := a.Wallet.NewIterateRecentBlocks() it := a.KeyStore.NewIterateRecentBlocks()
for cont := it != nil; cont; cont = it.Prev() { for cont := it != nil; cont; cont = it.Prev() {
bs := it.BlockStamp() bs := it.BlockStamp()
log.Debugf("Checking for previous saved block with height %v hash %v", log.Debugf("Checking for previous saved block with height %v hash %v",
@ -530,7 +531,7 @@ func (c *rpcClient) Handshake() error {
// Set default account to be marked in sync with the current // Set default account to be marked in sync with the current
// blockstamp. This invalidates the iterator. // blockstamp. This invalidates the iterator.
a.Wallet.SetSyncedWith(bs) a.KeyStore.SetSyncedWith(bs)
// Begin tracking wallets against this btcd instance. // Begin tracking wallets against this btcd instance.
AcctMgr.Track() AcctMgr.Track()

View file

@ -43,8 +43,8 @@ import (
"github.com/conformal/btcrpcclient" "github.com/conformal/btcrpcclient"
"github.com/conformal/btcscript" "github.com/conformal/btcscript"
"github.com/conformal/btcutil" "github.com/conformal/btcutil"
"github.com/conformal/btcwallet/keystore"
"github.com/conformal/btcwallet/txstore" "github.com/conformal/btcwallet/txstore"
"github.com/conformal/btcwallet/wallet"
"github.com/conformal/btcwire" "github.com/conformal/btcwire"
"github.com/conformal/btcws" "github.com/conformal/btcws"
"github.com/conformal/websocket" "github.com/conformal/websocket"
@ -1123,7 +1123,7 @@ func makeMultiSigScript(keys []string, nRequired int) ([]byte, error) {
return nil, err return nil, err
} }
apkinfo := ainfo.(wallet.PubKeyAddress) apkinfo := ainfo.(keystore.PubKeyAddress)
// This will be an addresspubkey // This will be an addresspubkey
a, err := btcutil.DecodeAddress(apkinfo.ExportPubKey(), a, err := btcutil.DecodeAddress(apkinfo.ExportPubKey(),
@ -1164,7 +1164,8 @@ func AddMultiSigAddress(icmd btcjson.Cmd) (interface{}, error) {
} }
// TODO(oga) blockstamp current block? // TODO(oga) blockstamp current block?
address, err := acct.ImportScript(script, &wallet.BlockStamp{}) address, err := acct.KeyStore.ImportScript(script,
&keystore.BlockStamp{})
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1222,7 +1223,7 @@ func DumpPrivKey(icmd btcjson.Cmd) (interface{}, error) {
} }
key, err := AcctMgr.DumpWIFPrivateKey(addr) key, err := AcctMgr.DumpWIFPrivateKey(addr)
if err == wallet.ErrWalletLocked { if err == keystore.ErrLocked {
// Address was found, but the private key isn't // Address was found, but the private key isn't
// accessible. // accessible.
return nil, btcjson.ErrWalletUnlockNeeded return nil, btcjson.ErrWalletUnlockNeeded
@ -1241,7 +1242,7 @@ func DumpWallet(icmd btcjson.Cmd) (interface{}, error) {
} }
keys, err := AcctMgr.DumpKeys() keys, err := AcctMgr.DumpKeys()
if err == wallet.ErrWalletLocked { if err == keystore.ErrLocked {
// Address was found, but the private key isn't // Address was found, but the private key isn't
// accessible. // accessible.
return nil, btcjson.ErrWalletUnlockNeeded return nil, btcjson.ErrWalletUnlockNeeded
@ -1348,7 +1349,7 @@ func GetInfo(icmd btcjson.Cmd) (interface{}, error) {
feeIncr = a.FeeIncrement feeIncr = a.FeeIncrement
} }
} }
info.WalletVersion = int32(wallet.VersCurrent.Uint32()) info.WalletVersion = int32(keystore.VersCurrent.Uint32())
info.Balance = balance.ToUnit(btcutil.AmountBTC) info.Balance = balance.ToUnit(btcutil.AmountBTC)
// Keypool times are not tracked. set to current time. // Keypool times are not tracked. set to current time.
info.KeypoolOldest = time.Now().Unix() info.KeypoolOldest = time.Now().Unix()
@ -1385,7 +1386,7 @@ func GetAccount(icmd btcjson.Cmd) (interface{}, error) {
} }
return nil, err return nil, err
} }
return acct.Name(), nil return acct.KeyStore.Name(), nil
} }
// GetAccountAddress handles a getaccountaddress by returning the most // GetAccountAddress handles a getaccountaddress by returning the most
@ -1412,7 +1413,7 @@ func GetAccountAddress(icmd btcjson.Cmd) (interface{}, error) {
addr, err := a.CurrentAddress() addr, err := a.CurrentAddress()
if err != nil { if err != nil {
if err == wallet.ErrWalletLocked { if err == keystore.ErrLocked {
return nil, btcjson.ErrWalletKeypoolRanOut return nil, btcjson.ErrWalletKeypoolRanOut
} }
return nil, err return nil, err
@ -1501,13 +1502,13 @@ func ImportPrivKey(icmd btcjson.Cmd) (interface{}, error) {
} }
// Import the private key, handling any errors. // Import the private key, handling any errors.
bs := wallet.BlockStamp{} bs := keystore.BlockStamp{}
if _, err := a.ImportPrivateKey(wif, &bs, cmd.Rescan); err != nil { if _, err := a.ImportPrivateKey(wif, &bs, cmd.Rescan); err != nil {
switch err { switch err {
case wallet.ErrDuplicate: case keystore.ErrDuplicate:
// Do not return duplicate key errors to the client. // Do not return duplicate key errors to the client.
return nil, nil return nil, nil
case wallet.ErrWalletLocked: case keystore.ErrLocked:
return nil, btcjson.ErrWalletUnlockNeeded return nil, btcjson.ErrWalletUnlockNeeded
default: default:
return nil, err return nil, err
@ -1527,7 +1528,7 @@ func KeypoolRefill(icmd btcjson.Cmd) (interface{}, error) {
// NotifyNewBlockChainHeight notifies all websocket clients of a new // NotifyNewBlockChainHeight notifies all websocket clients of a new
// blockchain height. This sends the same notification as // blockchain height. This sends the same notification as
// btcd, so this can probably be removed. // btcd, so this can probably be removed.
func (s *rpcServer) NotifyNewBlockChainHeight(bs *wallet.BlockStamp) { func (s *rpcServer) NotifyNewBlockChainHeight(bs *keystore.BlockStamp) {
ntfn := btcws.NewBlockConnectedNtfn(bs.Hash.String(), bs.Height) ntfn := btcws.NewBlockConnectedNtfn(bs.Hash.String(), bs.Height)
mntfn, err := ntfn.MarshalJSON() mntfn, err := ntfn.MarshalJSON()
// btcws notifications must always marshal without error. // btcws notifications must always marshal without error.
@ -2117,7 +2118,7 @@ func sendPairs(icmd btcjson.Cmd, account string, amounts map[string]btcutil.Amou
switch err { switch err {
case ErrNonPositiveAmount: case ErrNonPositiveAmount:
return nil, ErrNeedPositiveAmount return nil, ErrNeedPositiveAmount
case wallet.ErrWalletLocked: case keystore.ErrLocked:
return nil, btcjson.ErrWalletUnlockNeeded return nil, btcjson.ErrWalletUnlockNeeded
default: default:
return nil, err return nil, err
@ -2245,13 +2246,14 @@ func handleSendRawTxReply(icmd btcjson.Cmd, txSha *btcwire.ShaHash, a *Account,
return err return err
} }
if bs, err := rpcc.BlockStamp(); err == nil { if bs, err := rpcc.BlockStamp(); err == nil {
ltr, err := debits.ToJSON(a.Name(), bs.Height, a.Net()) ltr, err := debits.ToJSON(a.KeyStore.Name(), bs.Height,
a.KeyStore.Net())
if err != nil { if err != nil {
log.Errorf("Error adding sent tx history: %v", err) log.Errorf("Error adding sent tx history: %v", err)
return btcjson.ErrInternal return btcjson.ErrInternal
} }
for _, details := range ltr { for _, details := range ltr {
server.NotifyNewTxDetails(a.Name(), details) server.NotifyNewTxDetails(a.KeyStore.Name(), details)
} }
} }
@ -2342,7 +2344,7 @@ func SignMessage(icmd btcjson.Cmd) (interface{}, error) {
return nil, btcjson.ErrInvalidAddressOrKey return nil, btcjson.ErrInvalidAddressOrKey
} }
pka := ainfo.(wallet.PubKeyAddress) pka := ainfo.(keystore.PubKeyAddress)
privkey, err := pka.PrivKey() privkey, err := pka.PrivKey()
if err != nil { if err != nil {
return nil, err return nil, err
@ -2614,7 +2616,7 @@ func SignRawTransaction(icmd btcjson.Cmd) (interface{}, error) {
return nil, false, err return nil, false, err
} }
pka, ok := address.(wallet.PubKeyAddress) pka, ok := address.(keystore.PubKeyAddress)
if !ok { if !ok {
return nil, false, errors.New("address is not " + return nil, false, errors.New("address is not " +
"a pubkey address") "a pubkey address")
@ -2644,7 +2646,7 @@ func SignRawTransaction(icmd btcjson.Cmd) (interface{}, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
sa, ok := address.(wallet.ScriptAddress) sa, ok := address.(keystore.ScriptAddress)
if !ok { if !ok {
return nil, errors.New("address is not a script" + return nil, errors.New("address is not a script" +
" address") " address")
@ -2732,7 +2734,7 @@ func ValidateAddress(icmd btcjson.Cmd) (interface{}, error) {
if account, err := AcctMgr.AccountByAddress(addr); err == nil { if account, err := AcctMgr.AccountByAddress(addr); err == nil {
// The address must be handled by this account, so we expect // The address must be handled by this account, so we expect
// this call to succeed without error. // this call to succeed without error.
ainfo, err := account.Address(addr) ainfo, err := account.KeyStore.Address(addr)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -2740,11 +2742,11 @@ func ValidateAddress(icmd btcjson.Cmd) (interface{}, error) {
result.IsMine = true result.IsMine = true
result.Account = account.name result.Account = account.name
if pka, ok := ainfo.(wallet.PubKeyAddress); ok { if pka, ok := ainfo.(keystore.PubKeyAddress); ok {
result.IsCompressed = pka.Compressed() result.IsCompressed = pka.Compressed()
result.PubKey = pka.ExportPubKey() result.PubKey = pka.ExportPubKey()
} else if sa, ok := ainfo.(wallet.ScriptAddress); ok { } else if sa, ok := ainfo.(keystore.ScriptAddress); ok {
result.IsScript = true result.IsScript = true
addresses := sa.Addresses() addresses := sa.Addresses()
addrStrings := make([]string, len(addresses)) addrStrings := make([]string, len(addresses))
@ -2785,7 +2787,7 @@ func VerifyMessage(icmd btcjson.Cmd) (interface{}, error) {
return nil, btcjson.ErrInvalidAddressOrKey return nil, btcjson.ErrInvalidAddressOrKey
} }
pka := ainfo.(wallet.PubKeyAddress) pka := ainfo.(keystore.PubKeyAddress)
privkey, err := pka.PrivKey() privkey, err := pka.PrivKey()
if err != nil { if err != nil {
return nil, err return nil, err
@ -2856,7 +2858,7 @@ func WalletPassphraseChange(icmd btcjson.Cmd) (interface{}, error) {
err := AcctMgr.ChangePassphrase([]byte(cmd.OldPassphrase), err := AcctMgr.ChangePassphrase([]byte(cmd.OldPassphrase),
[]byte(cmd.NewPassphrase)) []byte(cmd.NewPassphrase))
if err == wallet.ErrWrongPassphrase { if err == keystore.ErrWrongPassphrase {
return nil, btcjson.ErrWalletPassphraseIncorrect return nil, btcjson.ErrWalletPassphraseIncorrect
} }
return nil, err return nil, err