From 47a13774bbdab445087f51d5b7ac6ed79246bbe0 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Wed, 8 Sep 2021 13:52:06 +0200 Subject: [PATCH] wallet: don't hold unlock in watch-only mode If we're running in watch-only mode, there is no unlock possible. Therefore, we also don't need to prevent any unlocks from happening when doing coin selection in that mode. --- wallet/wallet.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/wallet/wallet.go b/wallet/wallet.go index a0e9fc2..beac81e 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -1169,17 +1169,27 @@ out: for { select { case txr := <-w.createTxRequests: - heldUnlock, err := w.holdUnlock() - if err != nil { - txr.resp <- createTxResponse{nil, err} - continue + // If the wallet can be locked because it contains + // private key material, we need to prevent it from + // doing so while we are assembling the transaction. + 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( txr.outputs, txr.keyScope, txr.account, txr.minconf, txr.feeSatPerKB, txr.coinSelectionStrategy, txr.dryRun, ) - heldUnlock.release() + + release() txr.resp <- createTxResponse{tx, err} case <-quit: break out