mirror of
https://github.com/LBRYFoundation/lbcwallet.git
synced 2025-09-02 18:25:16 +00:00
Merge pull request #764 from guggero/import-key-scope
wallet: watch-only account import improvements
This commit is contained in:
commit
d0868cb9dd
2 changed files with 58 additions and 6 deletions
|
@ -204,6 +204,30 @@ func (w *Wallet) ImportAccount(name string, accountPubKey *hdkeychain.ExtendedKe
|
||||||
return accountProps, err
|
return accountProps, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ImportAccountWithScope imports an account backed by an account extended
|
||||||
|
// public key for a specific key scope which is known in advance.
|
||||||
|
// The master key fingerprint denotes the fingerprint of the root key
|
||||||
|
// corresponding to the account public key (also known as the key with
|
||||||
|
// derivation path m/). This may be required by some hardware wallets for proper
|
||||||
|
// identification and signing.
|
||||||
|
func (w *Wallet) ImportAccountWithScope(name string,
|
||||||
|
accountPubKey *hdkeychain.ExtendedKey, masterKeyFingerprint uint32,
|
||||||
|
keyScope waddrmgr.KeyScope, addrSchema waddrmgr.ScopeAddrSchema) (
|
||||||
|
*waddrmgr.AccountProperties, error) {
|
||||||
|
|
||||||
|
var accountProps *waddrmgr.AccountProperties
|
||||||
|
err := walletdb.Update(w.db, func(tx walletdb.ReadWriteTx) error {
|
||||||
|
ns := tx.ReadWriteBucket(waddrmgrNamespaceKey)
|
||||||
|
var err error
|
||||||
|
accountProps, err = w.importAccountScope(
|
||||||
|
ns, name, accountPubKey, masterKeyFingerprint, keyScope,
|
||||||
|
&addrSchema,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
return accountProps, err
|
||||||
|
}
|
||||||
|
|
||||||
// importAccount is the internal implementation of ImportAccount -- one should
|
// importAccount is the internal implementation of ImportAccount -- one should
|
||||||
// reference its documentation for this method.
|
// reference its documentation for this method.
|
||||||
func (w *Wallet) importAccount(ns walletdb.ReadWriteBucket, name string,
|
func (w *Wallet) importAccount(ns walletdb.ReadWriteBucket, name string,
|
||||||
|
@ -221,9 +245,27 @@ func (w *Wallet) importAccount(ns walletdb.ReadWriteBucket, name string,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return w.importAccountScope(
|
||||||
|
ns, name, accountPubKey, masterKeyFingerprint, keyScope,
|
||||||
|
addrSchema,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// importAccountScope imports a watch-only account for a given scope.
|
||||||
|
func (w *Wallet) importAccountScope(ns walletdb.ReadWriteBucket, name string,
|
||||||
|
accountPubKey *hdkeychain.ExtendedKey, masterKeyFingerprint uint32,
|
||||||
|
keyScope waddrmgr.KeyScope, addrSchema *waddrmgr.ScopeAddrSchema) (
|
||||||
|
*waddrmgr.AccountProperties, error) {
|
||||||
|
|
||||||
scopedMgr, err := w.Manager.FetchScopedKeyManager(keyScope)
|
scopedMgr, err := w.Manager.FetchScopedKeyManager(keyScope)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
scopedMgr, err = w.Manager.NewScopedKeyManager(
|
||||||
|
ns, keyScope, *addrSchema,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
account, err := scopedMgr.NewAccountWatchingOnly(
|
account, err := scopedMgr.NewAccountWatchingOnly(
|
||||||
|
|
|
@ -1169,17 +1169,27 @@ out:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case txr := <-w.createTxRequests:
|
case txr := <-w.createTxRequests:
|
||||||
heldUnlock, err := w.holdUnlock()
|
// If the wallet can be locked because it contains
|
||||||
if err != nil {
|
// private key material, we need to prevent it from
|
||||||
txr.resp <- createTxResponse{nil, err}
|
// doing so while we are assembling the transaction.
|
||||||
continue
|
release := func() {}
|
||||||
|
if !w.Manager.WatchOnly() {
|
||||||
|
heldUnlock, err := w.holdUnlock()
|
||||||
|
if err != nil {
|
||||||
|
txr.resp <- createTxResponse{nil, err}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
release = heldUnlock.release
|
||||||
}
|
}
|
||||||
|
|
||||||
tx, err := w.txToOutputs(
|
tx, err := w.txToOutputs(
|
||||||
txr.outputs, txr.keyScope, txr.account,
|
txr.outputs, txr.keyScope, txr.account,
|
||||||
txr.minconf, txr.feeSatPerKB,
|
txr.minconf, txr.feeSatPerKB,
|
||||||
txr.coinSelectionStrategy, txr.dryRun,
|
txr.coinSelectionStrategy, txr.dryRun,
|
||||||
)
|
)
|
||||||
heldUnlock.release()
|
|
||||||
|
release()
|
||||||
txr.resp <- createTxResponse{tx, err}
|
txr.resp <- createTxResponse{tx, err}
|
||||||
case <-quit:
|
case <-quit:
|
||||||
break out
|
break out
|
||||||
|
|
Loading…
Add table
Reference in a new issue