diff --git a/cmd.go b/cmd.go index 5811b9c..c5f39e3 100644 --- a/cmd.go +++ b/cmd.go @@ -64,13 +64,11 @@ func main() { */ // Open wallet - btcw, err := OpenWallet(cfg, "") + w, err := OpenWallet(cfg, "") if err != nil { log.Info(err.Error()) } else { - wallets.Lock() - wallets.m[""] = btcw - wallets.Unlock() + w.Track() } // Start HTTP server to listen and send messages to frontend and btcd @@ -179,10 +177,14 @@ func OpenWallet(cfg *config, account string) (*BtcWallet, error) { TxStore: txs, } - // Associate this wallet with default account. - wallets.Lock() - wallets.m[account] = w - wallets.Unlock() - return w, nil } + +func (w *BtcWallet) Track() { + wallets.Lock() + name := w.Name() + if wallets.m[name] == nil { + wallets.m[name] = w + } + wallets.Unlock() +} diff --git a/wallet/wallet.go b/wallet/wallet.go index 06f2fd7..2af2ed0 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -421,6 +421,10 @@ func NewWallet(name, desc string, passphrase []byte) (*Wallet, error) { return w, nil } +func (w *Wallet) Name() string { + return string(w.name[:]) +} + // ReadFrom reads data from a io.Reader and saves it to a Wallet, // returning the number of bytes read and any errors encountered. func (w *Wallet) ReadFrom(r io.Reader) (n int64, err error) {