multi: support sync freelist option within btcwallet

This commit is contained in:
Wilmer Paulino
2019-10-04 11:10:49 -04:00
parent 6765b8668a
commit 194a9dea81
12 changed files with 49 additions and 32 deletions

View File

@@ -96,13 +96,14 @@ type UnlockerService struct {
// sent.
UnlockMsgs chan *WalletUnlockMsg
chainDir string
netParams *chaincfg.Params
macaroonFiles []string
chainDir string
noFreelistSync bool
netParams *chaincfg.Params
macaroonFiles []string
}
// New creates and returns a new UnlockerService.
func New(chainDir string, params *chaincfg.Params,
func New(chainDir string, params *chaincfg.Params, noFreelistSync bool,
macaroonFiles []string) *UnlockerService {
return &UnlockerService{
@@ -128,7 +129,7 @@ func (u *UnlockerService) GenSeed(ctx context.Context,
// Before we start, we'll ensure that the wallet hasn't already created
// so we don't show a *new* seed to the user if one already exists.
netDir := btcwallet.NetworkDir(u.chainDir, u.netParams)
loader := wallet.NewLoader(u.netParams, netDir, 0)
loader := wallet.NewLoader(u.netParams, netDir, u.noFreelistSync, 0)
walletExists, err := loader.WalletExists()
if err != nil {
return nil, err
@@ -257,7 +258,9 @@ func (u *UnlockerService) InitWallet(ctx context.Context,
// We'll then open up the directory that will be used to store the
// wallet's files so we can check if the wallet already exists.
netDir := btcwallet.NetworkDir(u.chainDir, u.netParams)
loader := wallet.NewLoader(u.netParams, netDir, uint32(recoveryWindow))
loader := wallet.NewLoader(
u.netParams, netDir, u.noFreelistSync, uint32(recoveryWindow),
)
walletExists, err := loader.WalletExists()
if err != nil {
@@ -314,7 +317,9 @@ func (u *UnlockerService) UnlockWallet(ctx context.Context,
recoveryWindow := uint32(in.RecoveryWindow)
netDir := btcwallet.NetworkDir(u.chainDir, u.netParams)
loader := wallet.NewLoader(u.netParams, netDir, recoveryWindow)
loader := wallet.NewLoader(
u.netParams, netDir, u.noFreelistSync, recoveryWindow,
)
// Check if wallet already exists.
walletExists, err := loader.WalletExists()
@@ -365,7 +370,7 @@ func (u *UnlockerService) ChangePassword(ctx context.Context,
in *lnrpc.ChangePasswordRequest) (*lnrpc.ChangePasswordResponse, error) {
netDir := btcwallet.NetworkDir(u.chainDir, u.netParams)
loader := wallet.NewLoader(u.netParams, netDir, 0)
loader := wallet.NewLoader(u.netParams, netDir, u.noFreelistSync, 0)
// First, we'll make sure the wallet exists for the specific chain and
// network.

View File

@@ -36,7 +36,7 @@ var (
func createTestWallet(t *testing.T, dir string, netParams *chaincfg.Params) {
netDir := btcwallet.NetworkDir(dir, netParams)
loader := wallet.NewLoader(netParams, netDir, 0)
loader := wallet.NewLoader(netParams, netDir, true, 0)
_, err := loader.CreateNewWallet(
testPassword, testPassword, testSeed, time.Time{},
)
@@ -62,7 +62,7 @@ func TestGenSeed(t *testing.T) {
}
defer os.RemoveAll(testDir)
service := walletunlocker.New(testDir, testNetParams, nil)
service := walletunlocker.New(testDir, testNetParams, true, nil)
// Now that the service has been created, we'll ask it to generate a
// new seed for us given a test passphrase.
@@ -103,7 +103,7 @@ func TestGenSeedGenerateEntropy(t *testing.T) {
defer func() {
os.RemoveAll(testDir)
}()
service := walletunlocker.New(testDir, testNetParams, nil)
service := walletunlocker.New(testDir, testNetParams, true, nil)
// Now that the service has been created, we'll ask it to generate a
// new seed for us given a test passphrase. Note that we don't actually
@@ -143,7 +143,7 @@ func TestGenSeedInvalidEntropy(t *testing.T) {
defer func() {
os.RemoveAll(testDir)
}()
service := walletunlocker.New(testDir, testNetParams, nil)
service := walletunlocker.New(testDir, testNetParams, true, nil)
// Now that the service has been created, we'll ask it to generate a
// new seed for us given a test passphrase. However, we'll be using an
@@ -181,7 +181,7 @@ func TestInitWallet(t *testing.T) {
}()
// Create new UnlockerService.
service := walletunlocker.New(testDir, testNetParams, nil)
service := walletunlocker.New(testDir, testNetParams, true, nil)
// Once we have the unlocker service created, we'll now instantiate a
// new cipher seed instance.
@@ -282,7 +282,7 @@ func TestCreateWalletInvalidEntropy(t *testing.T) {
}()
// Create new UnlockerService.
service := walletunlocker.New(testDir, testNetParams, nil)
service := walletunlocker.New(testDir, testNetParams, true, nil)
// We'll attempt to init the wallet with an invalid cipher seed and
// passphrase.
@@ -315,7 +315,7 @@ func TestUnlockWallet(t *testing.T) {
}()
// Create new UnlockerService.
service := walletunlocker.New(testDir, testNetParams, nil)
service := walletunlocker.New(testDir, testNetParams, true, nil)
ctx := context.Background()
req := &lnrpc.UnlockWalletRequest{
@@ -389,7 +389,7 @@ func TestChangeWalletPassword(t *testing.T) {
}
// Create a new UnlockerService with our temp files.
service := walletunlocker.New(testDir, testNetParams, tempFiles)
service := walletunlocker.New(testDir, testNetParams, true, tempFiles)
ctx := context.Background()
newPassword := []byte("hunter2???")