mirror of
https://github.com/LBRYFoundation/lbcwallet.git
synced 2025-08-23 17:47:29 +00:00
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
|
// Open wallet
|
||||||
btcw, err := OpenWallet(cfg, "")
|
w, err := OpenWallet(cfg, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info(err.Error())
|
log.Info(err.Error())
|
||||||
} else {
|
} else {
|
||||||
wallets.Lock()
|
w.Track()
|
||||||
wallets.m[""] = btcw
|
|
||||||
wallets.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start HTTP server to listen and send messages to frontend and btcd
|
// 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,
|
TxStore: txs,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Associate this wallet with default account.
|
|
||||||
wallets.Lock()
|
|
||||||
wallets.m[account] = w
|
|
||||||
wallets.Unlock()
|
|
||||||
|
|
||||||
return w, nil
|
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
|
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,
|
// ReadFrom reads data from a io.Reader and saves it to a Wallet,
|
||||||
// returning the number of bytes read and any errors encountered.
|
// returning the number of bytes read and any errors encountered.
|
||||||
func (w *Wallet) ReadFrom(r io.Reader) (n int64, err error) {
|
func (w *Wallet) ReadFrom(r io.Reader) (n int64, err error) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue