mirror of
https://github.com/LBRYFoundation/lbcwallet.git
synced 2025-08-23 17:47:29 +00:00
wallet/loader: feed birthday+recovery window to wallet
This commit is contained in:
parent
d652e7dd04
commit
d26cf062fe
1 changed files with 26 additions and 15 deletions
|
@ -9,6 +9,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/roasbeef/btcd/chaincfg"
|
"github.com/roasbeef/btcd/chaincfg"
|
||||||
"github.com/roasbeef/btcwallet/internal/prompt"
|
"github.com/roasbeef/btcwallet/internal/prompt"
|
||||||
|
@ -36,25 +37,31 @@ var (
|
||||||
|
|
||||||
// Loader implements the creating of new and opening of existing wallets, while
|
// Loader implements the creating of new and opening of existing wallets, while
|
||||||
// providing a callback system for other subsystems to handle the loading of a
|
// providing a callback system for other subsystems to handle the loading of a
|
||||||
// wallet. This is primarely intended for use by the RPC servers, to enable
|
// wallet. This is primarily intended for use by the RPC servers, to enable
|
||||||
// methods and services which require the wallet when the wallet is loaded by
|
// methods and services which require the wallet when the wallet is loaded by
|
||||||
// another subsystem.
|
// another subsystem.
|
||||||
//
|
//
|
||||||
// Loader is safe for concurrent access.
|
// Loader is safe for concurrent access.
|
||||||
type Loader struct {
|
type Loader struct {
|
||||||
callbacks []func(*Wallet)
|
callbacks []func(*Wallet)
|
||||||
chainParams *chaincfg.Params
|
chainParams *chaincfg.Params
|
||||||
dbDirPath string
|
dbDirPath string
|
||||||
wallet *Wallet
|
recoveryWindow uint32
|
||||||
db walletdb.DB
|
wallet *Wallet
|
||||||
mu sync.Mutex
|
db walletdb.DB
|
||||||
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLoader constructs a Loader.
|
// NewLoader constructs a Loader with an optional recovery window. If the
|
||||||
func NewLoader(chainParams *chaincfg.Params, dbDirPath string) *Loader {
|
// recovery window is non-zero, the wallet will attempt to recovery addresses
|
||||||
|
// starting from the last SyncedTo height.
|
||||||
|
func NewLoader(chainParams *chaincfg.Params, dbDirPath string,
|
||||||
|
recoveryWindow uint32) *Loader {
|
||||||
|
|
||||||
return &Loader{
|
return &Loader{
|
||||||
chainParams: chainParams,
|
chainParams: chainParams,
|
||||||
dbDirPath: dbDirPath,
|
dbDirPath: dbDirPath,
|
||||||
|
recoveryWindow: recoveryWindow,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +95,9 @@ func (l *Loader) RunAfterLoad(fn func(*Wallet)) {
|
||||||
// CreateNewWallet creates a new wallet using the provided public and private
|
// CreateNewWallet creates a new wallet using the provided public and private
|
||||||
// passphrases. The seed is optional. If non-nil, addresses are derived from
|
// passphrases. The seed is optional. If non-nil, addresses are derived from
|
||||||
// this seed. If nil, a secure random seed is generated.
|
// this seed. If nil, a secure random seed is generated.
|
||||||
func (l *Loader) CreateNewWallet(pubPassphrase, privPassphrase, seed []byte) (*Wallet, error) {
|
func (l *Loader) CreateNewWallet(pubPassphrase, privPassphrase, seed []byte,
|
||||||
|
bday time.Time) (*Wallet, error) {
|
||||||
|
|
||||||
defer l.mu.Unlock()
|
defer l.mu.Unlock()
|
||||||
l.mu.Lock()
|
l.mu.Lock()
|
||||||
|
|
||||||
|
@ -116,13 +125,15 @@ func (l *Loader) CreateNewWallet(pubPassphrase, privPassphrase, seed []byte) (*W
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the newly created database for the wallet before opening.
|
// Initialize the newly created database for the wallet before opening.
|
||||||
err = Create(db, pubPassphrase, privPassphrase, seed, l.chainParams)
|
err = Create(
|
||||||
|
db, pubPassphrase, privPassphrase, seed, l.chainParams, bday,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open the newly-created wallet.
|
// Open the newly-created wallet.
|
||||||
w, err := Open(db, pubPassphrase, nil, l.chainParams)
|
w, err := Open(db, pubPassphrase, nil, l.chainParams, l.recoveryWindow)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -175,7 +186,7 @@ func (l *Loader) OpenExistingWallet(pubPassphrase []byte, canConsolePrompt bool)
|
||||||
ObtainPrivatePass: noConsole,
|
ObtainPrivatePass: noConsole,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
w, err := Open(db, pubPassphrase, cbs, l.chainParams)
|
w, err := Open(db, pubPassphrase, cbs, l.chainParams, l.recoveryWindow)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If opening the wallet fails (e.g. because of wrong
|
// If opening the wallet fails (e.g. because of wrong
|
||||||
// passphrase), we must close the backing database to
|
// passphrase), we must close the backing database to
|
||||||
|
|
Loading…
Add table
Reference in a new issue