@@ -79,7 +79,9 @@ static int AppInitRawTx(int argc, char* argv[])
79
79
strUsage += HelpMessageOpt (" nversion=N" , _ (" Set TX version to N" ));
80
80
strUsage += HelpMessageOpt (" outaddr=VALUE:ADDRESS" , _ (" Add address-based output to TX" ));
81
81
strUsage += HelpMessageOpt (" outdata=[VALUE:]DATA" , _ (" Add data-based output to TX" ));
82
- strUsage += HelpMessageOpt (" outscript=VALUE:SCRIPT" , _ (" Add raw script output to TX" ));
82
+ strUsage += HelpMessageOpt (" outscript=VALUE:SCRIPT(:\" SEGWIT\" )(:\" P2SH\" )" , _ (" Add raw script output to TX" ) + " . " +
83
+ _ (" Optionally add the \" SEGWIT\" flag to produce a segwit output" ) + " . " +
84
+ _ (" Optionally add the \" P2SH\" flag to wrap the script in a P2SH output." ));
83
85
strUsage += HelpMessageOpt (" sign=SIGHASH-FLAGS" , _ (" Add zero or more signatures to transaction" ) + " . " +
84
86
_ (" This command requires JSON registers:" ) +
85
87
_ (" prevtxs=JSON object" ) + " , " +
@@ -280,22 +282,30 @@ static void MutateTxAddOutData(CMutableTransaction& tx, const std::string& strIn
280
282
281
283
static void MutateTxAddOutScript (CMutableTransaction& tx, const std::string& strInput)
282
284
{
283
- // separate VALUE:SCRIPT in string
284
- size_t pos = strInput. find ( ' : ' ) ;
285
- if ((pos == std::string::npos) ||
286
- (pos == 0 ) )
287
- throw std ::runtime_error (" TX output missing separator" );
285
+ // separate VALUE:SCRIPT(:SEGWIT)(:P2SH)
286
+ std::vector<std::string> vStrInput ;
287
+ boost::split (vStrInput, strInput, boost::is_any_of ( " : " ));
288
+ if (vStrInput. size () < 2 )
289
+ throw srd ::runtime_error (" TX output missing separator" );
288
290
289
291
// extract and validate VALUE
290
- std::string strValue = strInput. substr ( 0 , pos) ;
292
+ std::string strValue = vStrInput[ 0 ] ;
291
293
CAmount value;
292
294
if (!ParseMoney (strValue, value))
293
295
throw std::runtime_error (" invalid TX output value" );
294
296
295
297
// extract and validate script
296
- std::string strScript = strInput. substr (pos + 1 , std::string::npos) ;
298
+ std::string strScript = vStrInput[ 1 ] ;
297
299
CScript scriptPubKey = ParseScript (strScript); // throws on err
298
300
301
+ if (std::find (vStrInput.begin (), vStrInput.end (), " SEGWIT" ) != vStrInput.end ()) {
302
+ scriptPubKey = GetScriptForWitness (scriptPubKey);
303
+ }
304
+ if (std::find (vStrInput.begin (), vStrInput.end (), " P2SH" ) != vStrInput.end ()) {
305
+ CBitcoinAddress addr (scriptPubKey);
306
+ scriptPubKey = GetScriptForDestination (addr.Get ());
307
+ }
308
+
299
309
// construct TxOut, append to transaction output list
300
310
CTxOut txout (value, scriptPubKey);
301
311
tx.vout .push_back (txout);
0 commit comments