@@ -105,8 +105,8 @@ func (c *doubleSpendInputs) Execute(_ *cobra.Command, _ []string) error {
105105	privKeys  :=  make ([]* secp256k1.PrivateKey , 0 , len (c .InputOutpoints ))
106106
107107	// Get the addresses for the inputs. 
108- 	for  _ , input  :=  range  c .InputOutpoints  {
109- 		addrString , err  :=  api .Address (input )
108+ 	for  _ , inputOutpoint  :=  range  c .InputOutpoints  {
109+ 		addrString , err  :=  api .Address (inputOutpoint )
110110		if  err  !=  nil  {
111111			return  err 
112112		}
@@ -118,12 +118,12 @@ func (c *doubleSpendInputs) Execute(_ *cobra.Command, _ []string) error {
118118
119119		addresses  =  append (addresses , addr )
120120
121- 		txHash , err  :=  chainhash .NewHashFromStr (input [:64 ])
121+ 		txHash , err  :=  chainhash .NewHashFromStr (inputOutpoint [:64 ])
122122		if  err  !=  nil  {
123123			return  err 
124124		}
125125
126- 		vout , err  :=  strconv .Atoi (input [65 :])
126+ 		vout , err  :=  strconv .Atoi (inputOutpoint [65 :])
127127		if  err  !=  nil  {
128128			return  err 
129129		}
@@ -144,7 +144,13 @@ func (c *doubleSpendInputs) Execute(_ *cobra.Command, _ []string) error {
144144	}
145145
146146	// Start with the txweight estimator. 
147- 	estimator  :=  input.TxWeightEstimator {}
147+ 	var  estimator  input.TxWeightEstimator 
148+ 	sweepScript , err  :=  lnd .PrepareWalletAddress (
149+ 		c .SweepAddr , chainParams , & estimator , extendedKey , "sweep" ,
150+ 	)
151+ 	if  err  !=  nil  {
152+ 		return  err 
153+ 	}
148154
149155	// Find the key for the given addresses and add their 
150156	// output weight to the tx estimator. 
@@ -169,7 +175,9 @@ func (c *doubleSpendInputs) Execute(_ *cobra.Command, _ []string) error {
169175				return  err 
170176			}
171177
172- 			estimator .AddTaprootKeySpendInput (txscript .SigHashDefault )
178+ 			estimator .AddTaprootKeySpendInput (
179+ 				txscript .SigHashDefault ,
180+ 			)
173181
174182		default :
175183			return  fmt .Errorf ("address type %T not supported" , addr )
@@ -189,47 +197,32 @@ func (c *doubleSpendInputs) Execute(_ *cobra.Command, _ []string) error {
189197
190198	// Next get the full value of the inputs. 
191199	var  totalInput  btcutil.Amount 
192- 	for  _ , input  :=  range  outpoints  {
200+ 	for  _ , outpoint  :=  range  outpoints  {
193201		// Get the transaction. 
194- 		tx , err  :=  api .Transaction (input .Hash .String ())
202+ 		tx , err  :=  api .Transaction (outpoint .Hash .String ())
195203		if  err  !=  nil  {
196204			return  err 
197205		}
198206
199- 		value  :=  tx .Vout [input .Index ].Value 
207+ 		value  :=  tx .Vout [outpoint .Index ].Value 
200208
201209		// Get the output index. 
202210		totalInput  +=  btcutil .Amount (value )
203211
204- 		scriptPubkey , err  :=  hex .DecodeString (tx .Vout [input .Index ].ScriptPubkey )
212+ 		scriptPubkey , err  :=  hex .DecodeString (
213+ 			tx .Vout [outpoint .Index ].ScriptPubkey ,
214+ 		)
205215		if  err  !=  nil  {
206216			return  err 
207217		}
208218
209219		// Add the output to the map. 
210- 		prevOuts [* input ] =  & wire.TxOut {
220+ 		prevOuts [* outpoint ] =  & wire.TxOut {
211221			Value :    int64 (value ),
212222			PkScript : scriptPubkey ,
213223		}
214224	}
215225
216- 	// Calculate the fee. 
217- 	sweepAddr , err  :=  btcutil .DecodeAddress (c .SweepAddr , chainParams )
218- 	if  err  !=  nil  {
219- 		return  err 
220- 	}
221- 
222- 	switch  sweepAddr .(type ) {
223- 	case  * btcutil.AddressWitnessPubKeyHash :
224- 		estimator .AddP2WKHOutput ()
225- 
226- 	case  * btcutil.AddressTaproot :
227- 		estimator .AddP2TROutput ()
228- 
229- 	default :
230- 		return  fmt .Errorf ("address type %T not supported" , sweepAddr )
231- 	}
232- 
233226	// Calculate the fee. 
234227	feeRateKWeight  :=  chainfee .SatPerKVByte (1000  *  c .FeeRate ).FeePerKWeight ()
235228	totalFee  :=  feeRateKWeight .FeeForWeight (int64 (estimator .Weight ()))
@@ -238,14 +231,8 @@ func (c *doubleSpendInputs) Execute(_ *cobra.Command, _ []string) error {
238231	tx  :=  wire .NewMsgTx (2 )
239232
240233	// Add the inputs. 
241- 	for  _ , input  :=  range  outpoints  {
242- 		tx .AddTxIn (wire .NewTxIn (input , nil , nil ))
243- 	}
244- 
245- 	// Add the output. 
246- 	sweepScript , err  :=  txscript .PayToAddrScript (sweepAddr )
247- 	if  err  !=  nil  {
248- 		return  err 
234+ 	for  _ , outpoint  :=  range  outpoints  {
235+ 		tx .AddTxIn (wire .NewTxIn (outpoint , nil , nil ))
249236	}
250237
251238	tx .AddTxOut (wire .NewTxOut (int64 (totalInput - totalFee ), sweepScript ))
@@ -285,7 +272,8 @@ func (c *doubleSpendInputs) Execute(_ *cobra.Command, _ []string) error {
285272			}
286273
287274		default :
288- 			return  fmt .Errorf ("address type %T not supported" , addresses [i ])
275+ 			return  fmt .Errorf ("address type %T not supported" ,
276+ 				addresses [i ])
289277		}
290278	}
291279
@@ -296,7 +284,7 @@ func (c *doubleSpendInputs) Execute(_ *cobra.Command, _ []string) error {
296284	}
297285
298286	// Print the transaction. 
299- 	fmt .Printf ("Sweeping transaction:\n %s \n " , hex . EncodeToString ( txBuf .Bytes () ))
287+ 	fmt .Printf ("Sweeping transaction:\n %x \n " , txBuf .Bytes ())
300288
301289	// Publish the transaction. 
302290	if  c .Publish  {
0 commit comments