@@ -57,14 +57,6 @@ const (
57
57
)
58
58
59
59
var (
60
- // waddrmgrNamespaceKey is the namespace key that the waddrmgr state is
61
- // stored within the top-level walletdb buckets of btcwallet.
62
- waddrmgrNamespaceKey = []byte ("waddrmgr" )
63
-
64
- // wtxmgrNamespaceKey is the namespace key that the wtxmgr state is
65
- // stored within the top-level waleltdb buckets of btcwallet.
66
- wtxmgrNamespaceKey = []byte ("wtxmgr" )
67
-
68
60
// lightningAddrSchema is the scope addr schema for all keys that we
69
61
// derive. We'll treat them all as p2wkh addresses, as atm we must
70
62
// specify a particular type.
@@ -350,18 +342,7 @@ func (b *BtcWallet) Start() error {
350
342
// it was added recently and older wallets don't know it
351
343
// yet. Let's add it now.
352
344
addrSchema := waddrmgr .ScopeAddrMap [scope ]
353
- err := walletdb .Update (
354
- b .db , func (tx walletdb.ReadWriteTx ) error {
355
- addrmgrNs := tx .ReadWriteBucket (
356
- waddrmgrNamespaceKey ,
357
- )
358
-
359
- _ , err := b .wallet .Manager .NewScopedKeyManager (
360
- addrmgrNs , scope , addrSchema ,
361
- )
362
- return err
363
- },
364
- )
345
+ _ , err := b .wallet .AddScopeManager (scope , addrSchema )
365
346
if err != nil {
366
347
return err
367
348
}
@@ -373,65 +354,27 @@ func (b *BtcWallet) Start() error {
373
354
// If the scope hasn't yet been created (it wouldn't been
374
355
// loaded by default if it was), then we'll manually create the
375
356
// scope for the first time ourselves.
376
- err := walletdb .Update (b .db , func (tx walletdb.ReadWriteTx ) error {
377
- addrmgrNs := tx .ReadWriteBucket (waddrmgrNamespaceKey )
378
-
379
- scope , err = b .wallet .Manager .NewScopedKeyManager (
380
- addrmgrNs , b .chainKeyScope , lightningAddrSchema ,
381
- )
382
- return err
383
- })
357
+ manager , err := b .wallet .AddScopeManager (
358
+ b .chainKeyScope , lightningAddrSchema ,
359
+ )
384
360
if err != nil {
385
361
return err
386
362
}
363
+
364
+ scope = manager
387
365
}
388
366
367
+ // If the wallet is not watch-only atm, and the user wants to migrate it
368
+ // to watch-only, we will set `convertToWatchOnly` to true so the wallet
369
+ // accounts are created and converted.
370
+ convertToWatchOnly := ! walletIsWatchOnly && b .cfg .WatchOnly &&
371
+ b .cfg .MigrateWatchOnly
372
+
389
373
// Now that the wallet is unlocked, we'll go ahead and make sure we
390
374
// create accounts for all the key families we're going to use. This
391
375
// will make it possible to list all the account/family xpubs in the
392
376
// wallet list RPC.
393
- err = walletdb .Update (b .db , func (tx walletdb.ReadWriteTx ) error {
394
- addrmgrNs := tx .ReadWriteBucket (waddrmgrNamespaceKey )
395
-
396
- // Generate all accounts that we could ever need. This includes
397
- // all lnd key families as well as some key families used in
398
- // external liquidity tools.
399
- for keyFam := uint32 (1 ); keyFam <= 255 ; keyFam ++ {
400
- // Otherwise, we'll check if the account already exists,
401
- // if so, we can once again bail early.
402
- _ , err := scope .AccountName (addrmgrNs , keyFam )
403
- if err == nil {
404
- continue
405
- }
406
-
407
- // If we reach this point, then the account hasn't yet
408
- // been created, so we'll need to create it before we
409
- // can proceed.
410
- err = scope .NewRawAccount (addrmgrNs , keyFam )
411
- if err != nil {
412
- return err
413
- }
414
- }
415
-
416
- // If this is the first startup with remote signing and wallet
417
- // migration turned on and the wallet wasn't previously
418
- // migrated, we can do that now that we made sure all accounts
419
- // that we need were derived correctly.
420
- if ! walletIsWatchOnly && b .cfg .WatchOnly &&
421
- b .cfg .MigrateWatchOnly {
422
-
423
- log .Infof ("Migrating wallet to watch-only mode, " +
424
- "purging all private key material" )
425
-
426
- ns := tx .ReadWriteBucket (waddrmgrNamespaceKey )
427
- err = b .wallet .Manager .ConvertToWatchingOnly (ns )
428
- if err != nil {
429
- return err
430
- }
431
- }
432
-
433
- return nil
434
- })
377
+ err = b .wallet .InitAccounts (scope , convertToWatchOnly , 255 )
435
378
if err != nil {
436
379
return err
437
380
}
@@ -769,29 +712,8 @@ func (b *BtcWallet) ListAddresses(name string,
769
712
770
713
for _ , accntDetails := range accounts {
771
714
accntScope := accntDetails .KeyScope
772
- scopedMgr , err := b .wallet .Manager .FetchScopedKeyManager (
773
- accntScope ,
774
- )
775
- if err != nil {
776
- return nil , err
777
- }
778
-
779
- var managedAddrs []waddrmgr.ManagedAddress
780
- err = walletdb .View (
781
- b .wallet .Database (), func (tx walletdb.ReadTx ) error {
782
- managedAddrs = nil
783
- addrmgrNs := tx .ReadBucket (waddrmgrNamespaceKey )
784
- return scopedMgr .ForEachAccountAddress (
785
- addrmgrNs , accntDetails .AccountNumber ,
786
- func (a waddrmgr.ManagedAddress ) error {
787
- managedAddrs = append (
788
- managedAddrs , a ,
789
- )
790
-
791
- return nil
792
- },
793
- )
794
- },
715
+ managedAddrs , err := b .wallet .AccountManagedAddresses (
716
+ accntDetails .KeyScope , accntDetails .AccountNumber ,
795
717
)
796
718
if err != nil {
797
719
return nil , err
@@ -1817,18 +1739,8 @@ func (b *BtcWallet) GetRecoveryInfo() (bool, float64, error) {
1817
1739
return isRecoveryMode , progress , nil
1818
1740
}
1819
1741
1820
- // Query the wallet's birthday block height from db.
1821
- var birthdayBlock waddrmgr.BlockStamp
1822
- err := walletdb .View (b .db , func (tx walletdb.ReadTx ) error {
1823
- var err error
1824
- addrmgrNs := tx .ReadBucket (waddrmgrNamespaceKey )
1825
- birthdayBlock , _ , err = b .wallet .Manager .BirthdayBlock (addrmgrNs )
1826
- if err != nil {
1827
- return err
1828
- }
1829
- return nil
1830
- })
1831
-
1742
+ // Query the wallet's birthday block from db.
1743
+ birthdayBlock , err := b .wallet .BirthdayBlock ()
1832
1744
if err != nil {
1833
1745
// The wallet won't start until the backend is synced, thus the birthday
1834
1746
// block won't be set and this particular error will be returned. We'll
@@ -1886,43 +1798,20 @@ func (b *BtcWallet) GetRecoveryInfo() (bool, float64, error) {
1886
1798
// by the passed transaction hash. If the transaction can't be found, then a
1887
1799
// nil pointer is returned.
1888
1800
func (b * BtcWallet ) FetchTx (txHash chainhash.Hash ) (* wire.MsgTx , error ) {
1889
- var targetTx * wtxmgr.TxDetails
1890
- err := walletdb .View (b .db , func (tx walletdb.ReadTx ) error {
1891
- wtxmgrNs := tx .ReadBucket (wtxmgrNamespaceKey )
1892
- txDetails , err := b .wallet .TxStore .TxDetails (wtxmgrNs , & txHash )
1893
- if err != nil {
1894
- return err
1895
- }
1896
-
1897
- targetTx = txDetails
1898
-
1899
- return nil
1900
- })
1801
+ tx , err := b .wallet .GetTransaction (txHash )
1901
1802
if err != nil {
1902
1803
return nil , err
1903
1804
}
1904
1805
1905
- if targetTx == nil {
1906
- return nil , nil
1907
- }
1908
-
1909
- return & targetTx .TxRecord .MsgTx , nil
1806
+ return tx .Summary .Tx , nil
1910
1807
}
1911
1808
1912
1809
// RemoveDescendants attempts to remove any transaction from the wallet's tx
1913
1810
// store (that may be unconfirmed) that spends outputs created by the passed
1914
1811
// transaction. This remove propagates recursively down the chain of descendent
1915
1812
// transactions.
1916
1813
func (b * BtcWallet ) RemoveDescendants (tx * wire.MsgTx ) error {
1917
- txRecord , err := wtxmgr .NewTxRecordFromMsgTx (tx , time .Now ())
1918
- if err != nil {
1919
- return err
1920
- }
1921
-
1922
- return walletdb .Update (b .db , func (tx walletdb.ReadWriteTx ) error {
1923
- wtxmgrNs := tx .ReadWriteBucket (wtxmgrNamespaceKey )
1924
- return b .wallet .TxStore .RemoveUnminedTx (wtxmgrNs , txRecord )
1925
- })
1814
+ return b .wallet .RemoveDescendants (tx )
1926
1815
}
1927
1816
1928
1817
// CheckMempoolAcceptance is a wrapper around `TestMempoolAccept` which checks
0 commit comments