misc: add ability to store the wallet in the remote DB

This commit is contained in:
Andras Banki-Horvath
2021-03-04 23:13:06 +01:00
parent 08be03367a
commit b6a620e6b2
7 changed files with 203 additions and 57 deletions

View File

@@ -137,12 +137,16 @@ type UnlockerService struct {
// resetWalletTransactions indicates that the wallet state should be
// reset on unlock to force a full chain rescan.
resetWalletTransactions bool
// LoaderOpts holds the functional options for the wallet loader.
loaderOpts []btcwallet.LoaderOption
}
// New creates and returns a new UnlockerService.
func New(chainDir string, params *chaincfg.Params, noFreelistSync bool,
macaroonFiles []string, dbTimeout time.Duration,
resetWalletTransactions bool) *UnlockerService {
resetWalletTransactions bool,
loaderOpts []btcwallet.LoaderOption) *UnlockerService {
return &UnlockerService{
InitMsgs: make(chan *WalletInitMsg, 1),
@@ -157,17 +161,16 @@ func New(chainDir string, params *chaincfg.Params, noFreelistSync bool,
dbTimeout: dbTimeout,
noFreelistSync: noFreelistSync,
resetWalletTransactions: resetWalletTransactions,
loaderOpts: loaderOpts,
}
}
func (u *UnlockerService) newLoader(recoveryWindow uint32) (*wallet.Loader,
error) {
netDir := btcwallet.NetworkDir(u.chainDir, u.netParams)
return wallet.NewLoader(
u.netParams, netDir, u.noFreelistSync, u.dbTimeout,
recoveryWindow,
), nil
return btcwallet.NewWalletLoader(
u.netParams, recoveryWindow, u.loaderOpts...,
)
}
// WalletExists returns whether a wallet exists on the file path the

View File

@@ -48,6 +48,13 @@ var (
)
)
func testLoaderOpts(testDir string) []btcwallet.LoaderOption {
dbDir := btcwallet.NetworkDir(testDir, testNetParams)
return []btcwallet.LoaderOption{
btcwallet.LoaderWithLocalWalletDB(dbDir, true, time.Minute),
}
}
func createTestWallet(t *testing.T, dir string, netParams *chaincfg.Params) {
createTestWalletWithPw(t, testPassword, testPassword, dir, netParams)
}
@@ -148,7 +155,7 @@ func TestGenSeed(t *testing.T) {
service := walletunlocker.New(
testDir, testNetParams, true, nil, kvdb.DefaultDBTimeout,
false,
false, testLoaderOpts(testDir),
)
// Now that the service has been created, we'll ask it to generate a
@@ -186,7 +193,7 @@ func TestGenSeedGenerateEntropy(t *testing.T) {
}()
service := walletunlocker.New(
testDir, testNetParams, true, nil, kvdb.DefaultDBTimeout,
false,
false, testLoaderOpts(testDir),
)
// Now that the service has been created, we'll ask it to generate a
@@ -223,7 +230,7 @@ func TestGenSeedInvalidEntropy(t *testing.T) {
}()
service := walletunlocker.New(
testDir, testNetParams, true, nil, kvdb.DefaultDBTimeout,
false,
false, testLoaderOpts(testDir),
)
// Now that the service has been created, we'll ask it to generate a
@@ -257,7 +264,7 @@ func TestInitWallet(t *testing.T) {
// Create new UnlockerService.
service := walletunlocker.New(
testDir, testNetParams, true, nil, kvdb.DefaultDBTimeout,
false,
false, testLoaderOpts(testDir),
)
// Once we have the unlocker service created, we'll now instantiate a
@@ -346,7 +353,7 @@ func TestCreateWalletInvalidEntropy(t *testing.T) {
// Create new UnlockerService.
service := walletunlocker.New(
testDir, testNetParams, true, nil, kvdb.DefaultDBTimeout,
false,
false, testLoaderOpts(testDir),
)
// We'll attempt to init the wallet with an invalid cipher seed and
@@ -379,7 +386,7 @@ func TestUnlockWallet(t *testing.T) {
// unlock.
service := walletunlocker.New(
testDir, testNetParams, true, nil, kvdb.DefaultDBTimeout,
true,
true, testLoaderOpts(testDir),
)
ctx := context.Background()
@@ -471,7 +478,7 @@ func TestChangeWalletPasswordNewRootkey(t *testing.T) {
// Create a new UnlockerService with our temp files.
service := walletunlocker.New(
testDir, testNetParams, true, tempFiles, kvdb.DefaultDBTimeout,
false,
false, testLoaderOpts(testDir),
)
ctx := context.Background()
@@ -583,7 +590,7 @@ func TestChangeWalletPasswordStateless(t *testing.T) {
service := walletunlocker.New(
testDir, testNetParams, true, []string{
tempMacFile, nonExistingFile,
}, kvdb.DefaultDBTimeout, false,
}, kvdb.DefaultDBTimeout, false, testLoaderOpts(testDir),
)
// Create a wallet we can try to unlock. We use the default password