Abstract out wallet tracking function.
This will soon be used to also implement tracking of utxo and txs for address in this wallet.
This commit is contained in:
parent
42274b143f
commit
85425c2c80
2 changed files with 15 additions and 9 deletions
20
cmd.go
20
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()
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue