@@ -65,6 +65,12 @@ public FaucetController(IOptions<BitcoinSettings> bitcoinSettings, IIndexerServi
65
65
_indexerService = indexerService ?? throw new ArgumentNullException ( nameof ( indexerService ) , "IndexerService is not provided." ) ;
66
66
}
67
67
68
+ [ HttpGet ( "send/{address}/{address2}/{amount?}" ) ]
69
+ public async Task < IActionResult > SendFunds ( string address , string address2 , long ? amount )
70
+ {
71
+ return await SendFunds ( new SendRequest { ToAddress = address , Amount = amount ?? 20 , ToAddress2 = address2 , Amount2 = amount ?? 20 } ) ;
72
+ }
73
+
68
74
[ HttpGet ( "send/{address}/{amount?}" ) ]
69
75
public async Task < IActionResult > SendFunds ( string address , long ? amount )
70
76
{
@@ -83,6 +89,9 @@ public async Task<IActionResult> SendFunds([FromBody] SendRequest request)
83
89
var toAddress = BitcoinAddress . Create ( request . ToAddress , _network ) ;
84
90
var amount = Money . Coins ( request . Amount ) ;
85
91
92
+ BitcoinAddress ? toAddress2 = ! string . IsNullOrEmpty ( request . ToAddress2 ) ? BitcoinAddress . Create ( request . ToAddress2 , _network ) : null ;
93
+ Money amount2 = Money . Coins ( request . Amount2 > 0 ? request . Amount2 : request . Amount ) ;
94
+
86
95
var keyPath = new KeyPath ( $ "m/84'/1'/0'/0/{ _bitcoinSettings . ChangeAddressIndex } ") ;
87
96
var privateKey = _masterKey . Derive ( keyPath ) . PrivateKey ;
88
97
var fromAddress = privateKey . PubKey . GetAddress ( ScriptPubKeyType . Segwit , _network ) ;
@@ -100,14 +109,18 @@ public async Task<IActionResult> SendFunds([FromBody] SendRequest request)
100
109
} ) . Take ( 2 ) . ToList ( ) ;
101
110
102
111
var txBuilder = _network . CreateTransactionBuilder ( ) ;
103
- var tx = txBuilder
112
+ var txbuilder = txBuilder
104
113
. AddCoins ( coins )
105
114
. AddKeys ( privateKey )
106
115
. Send ( toAddress , amount )
107
- . Send ( toAddress , amount )
108
116
. SetChange ( fromAddress )
109
- . SendFees ( Money . Satoshis ( _bitcoinSettings . FeeRate ) )
110
- . BuildTransaction ( true ) ;
117
+ . SendFees ( Money . Satoshis ( _bitcoinSettings . FeeRate ) ) ;
118
+
119
+
120
+ if ( toAddress2 != null )
121
+ txbuilder . Send ( toAddress2 , amount2 ) ;
122
+
123
+ var tx = txbuilder . BuildTransaction ( true ) ;
111
124
112
125
if ( ! txBuilder . Verify ( tx ) )
113
126
{
@@ -207,7 +220,9 @@ public async Task<IActionResult> CheckNetworkStatus()
207
220
public class SendRequest
208
221
{
209
222
public string ToAddress { get ; set ; }
223
+ public string ToAddress2 { get ; set ; }
210
224
public decimal Amount { get ; set ; }
225
+ public decimal Amount2 { get ; set ; }
211
226
}
212
227
}
213
228
}
0 commit comments