File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed
BDKSwiftExampleWallet/Service/BDK Service Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -562,10 +562,6 @@ final class BDKService {
562562 throw WalletError . sweepEsploraOnly
563563 }
564564
565- let destinationAddress = try getAddress ( )
566- let destinationScript = try Address ( address: destinationAddress, network: self . network)
567- . scriptPubkey ( )
568-
569565 let candidates = [
570566 " pkh( \( wif) ) " ,
571567 " wpkh( \( wif) ) " ,
@@ -575,6 +571,9 @@ final class BDKService {
575571
576572 var sweptTxids : [ Txid ] = [ ]
577573 var lastWIFOperationError : Error ?
574+
575+ var destinationScript : Script ?
576+
578577 for descriptorString in candidates {
579578 guard
580579 let descriptor = try ? Descriptor (
@@ -607,6 +606,16 @@ final class BDKService {
607606 continue
608607 }
609608
609+ if destinationScript == nil {
610+ let destinationAddress = try getAddress ( )
611+ destinationScript = try Address ( address: destinationAddress, network: self . network)
612+ . scriptPubkey ( )
613+ }
614+
615+ guard let destinationScript else {
616+ throw WalletError . noSweepableFunds
617+ }
618+
610619 do {
611620 let psbt = try TxBuilder ( )
612621 . drainTo ( script: destinationScript)
You can’t perform that action at this time.
0 commit comments