@@ -335,66 +335,72 @@ public async Task<bool> IsRunning()
335335 //
336336 // }
337337
338- private PSBT CreatePsbtOutputTemplate ( int numberOfOutputs , string destinationAddress , long amountPerOutputSats , Network network )
339- {
340- if ( numberOfOutputs <= 0 || amountPerOutputSats <= 0 )
341- throw new ArgumentException ( "Number of outputs and amount per output must be greater than zero." ) ;
342-
343- BitcoinAddress address = BitcoinAddress . Create ( destinationAddress , network ) ;
344-
345- // Create a transaction
346- var tx = NBitcoin . Transaction . Create ( network ) ;
347-
348- // // Add dummy inputs
349- // tx.Inputs.Add(new TxIn(new OutPoint(uint256.Zero, 0)));
350-
351- // Add outputs
352- for ( int i = 0 ; i < numberOfOutputs ; i ++ )
353- {
354- tx . Outputs . Add ( new TxOut ( Money . Satoshis ( amountPerOutputSats ) , address ) ) ;
355- }
338+ // private PSBT CreatePsbtOutputTemplate(int numberOfOutputs, string destinationAddress, long amountPerOutputSats, Network network)
339+ // {
340+ // if (numberOfOutputs <= 0 || amountPerOutputSats <= 0)
341+ // throw new ArgumentException("Number of outputs and amount per output must be greater than zero.");
342+ //
343+ // BitcoinAddress address = BitcoinAddress.Create(destinationAddress, network);
344+ //
345+ // // Create a transaction
346+ // var tx = NBitcoin.Transaction.Create(network);
347+ //
348+ // // // Add dummy inputs
349+ // // tx.Inputs.Add(new TxIn(new OutPoint(uint256.Zero, 0)));
350+ //
351+ // // Add outputs
352+ // for (int i = 0; i < numberOfOutputs; i++)
353+ // {
354+ // tx.Outputs.Add(new TxOut(Money.Satoshis(amountPerOutputSats), address));
355+ // }
356+ //
357+ // // Create PSBT from the transaction
358+ // return PSBT.FromTransaction(tx, network);
359+ // }
356360
357- // Create PSBT from the transaction
358- return PSBT . FromTransaction ( tx , network ) ;
361+ private async Task < string > CreatePsbtOutputTemplateBitcoinRPC ( int numberOfOutputs , string destinationAddress , long amountPerOutputSats , Network network )
362+ {
363+ return await Builder . BitcoinRpcClient . CreateMultiOutputPsbt ( destinationAddress , amountPerOutputSats ,
364+ numberOfOutputs ) ;
359365 }
360-
361- [ TestCase ( 2 , "bcrt1pau9xpav22lr592a2fgldkqy65e42uz5gdgy8et6kgvkrtep5gkeq07uyla" , 1000 , "regtest" ) ]
366+
367+ [ TestCase ( 2 , "bcrt1pau9xpav22lr592a2fgldkqy65e42uz5gdgy8et6kgvkrtep5gkeq07uyla" , 1000 , "regtest" ) ]
362368 [ Category ( "PSBT" ) ]
363- public async Task PSBTFlow ( int numberOfOutputs , string depositAddress , int amountPerOutputSats , string network , ulong feeRate = 1 )
369+ public async Task PSBTFlow ( int numberOfOutputs , string depositAddress , int amountPerOutputSats , string network , ulong feeRate = 1 )
364370 {
365- var n = Network . GetNetwork ( network ) ;
366- var p = CreatePsbtOutputTemplate ( numberOfOutputs , depositAddress , amountPerOutputSats , n ) ;
371+ var networkChain = Network . GetNetwork ( network ) ;
372+ var psbtOutputTemplate = await CreatePsbtOutputTemplateBitcoinRPC ( numberOfOutputs , depositAddress , amountPerOutputSats , networkChain ) ;
367373 //This verifies is fundable, and leases outputs.
368374 var fundReq = new FundPsbtRequest ( )
369375 {
370- Psbt = ByteString . FromBase64 ( p . ToBase64 ( ) )
376+ Psbt = ByteString . FromBase64 ( psbtOutputTemplate )
371377 } ;
372378
373379 fundReq . SatPerVbyte = feeRate ;
374- var node = Builder . LNDNodePool . GetLNDNodeConnection ( ) ;
380+ var node = Builder . LNDNodePool . GetLNDNodeConnection ( ) ;
375381
376382 var fundedPsbt = node . WalletKitClient . FundPsbt ( fundReq ) ;
377-
383+
378384 //extract txId
379- var psbt = PSBT . Parse ( fundedPsbt . FundedPsbt . ToBase64 ( ) , n ) ;
385+ var psbt = PSBT . Parse ( fundedPsbt . FundedPsbt . ToBase64 ( ) , networkChain ) ;
380386 var txIdHexString = psbt . GetGlobalTransaction ( ) . GetHash ( ) . ToString ( ) ;
381387 Console . WriteLine ( $ "LoopStaticInDeposit: Generated funded TX: { txIdHexString } ") ;
382-
388+
383389 //Signs and returns raw tx to transmit
384390 var finalizedPsbt = node . WalletKitClient . FinalizePsbt ( new FinalizePsbtRequest ( )
385391 {
386392 FundedPsbt = fundedPsbt . FundedPsbt
387- } ) ;
393+ } ) ;
388394 Console . WriteLine ( $ "LoopStaticInDeposit: Finalized TX: { txIdHexString } ") ;
389-
395+
390396 //Publish
391397 var publicRes = node . WalletKitClient . PublishTransaction ( new Transaction ( )
392398 {
393399 Label = $ "Loop Static In Split",
394400 TxHex = finalizedPsbt . RawFinalTx
395- } ) ;
401+ } ) ;
396402 }
397-
403+
398404 [ Test ]
399405 [ Category ( "Payment" ) ]
400406 [ NonParallelizable ]
0 commit comments