@@ -226,30 +226,35 @@ static void MutateTxAddInput(CMutableTransaction& tx, const string& strInput)
226226
227227static void MutateTxAddOutAddr (CMutableTransaction& tx, const string& strInput)
228228{
229- // separate VALUE:ADDRESS in string
230- size_t pos = strInput.find (' :' );
231- if ((pos == string::npos) ||
232- (pos == 0 ) ||
233- (pos == (strInput.size () - 1 )))
229+ // separate VALUE:ADDRESS:ASSET in string
230+ std::vector<std::string> vStrOutAddrParts;
231+ boost::split (vStrOutAddrParts, strInput, boost::is_any_of (" :" ));
232+ if (vStrOutAddrParts.size ()<3 )
234233 throw runtime_error (" TX output missing separator" );
235234
236235 // extract and validate VALUE
237- string strValue = strInput. substr ( 0 , pos) ;
236+ string strValue = vStrOutAddrParts[ 0 ] ;
238237 CAmount value;
239238 if (!ParseMoney (strValue, value))
240239 throw runtime_error (" invalid TX output value" );
241240
242241 // extract and validate ADDRESS
243- string strAddr = strInput. substr (pos + 1 , string::npos) ;
242+ string strAddr = vStrOutAddrParts[ 1 ] ;
244243 CBitcoinAddress addr (strAddr);
245244 if (!addr.IsValid ())
246245 throw runtime_error (" invalid TX output address" );
247246
247+ // extract and validate ASSET
248+ string strAsset = vStrOutAddrParts[2 ];
249+ CAssetID asset = uint256S (strAsset);
250+ if (asset == CAssetID ())
251+ throw runtime_error (" invalid TX output asset type" );
252+
248253 // build standard output script via GetScriptForDestination()
249254 CScript scriptPubKey = GetScriptForDestination (addr.Get ());
250255
251256 // construct TxOut, append to transaction output list
252- CTxOut txout (BITCOINID , value, scriptPubKey);
257+ CTxOut txout (asset , value, scriptPubKey);
253258 if (addr.IsBlinded ()) {
254259 CPubKey pubkey = addr.GetBlindingKey ();
255260 txout.nValue .vchNonceCommitment = std::vector<unsigned char >(pubkey.begin (), pubkey.end ());
@@ -353,24 +358,28 @@ static void MutateTxBlind(CMutableTransaction& tx, const string& strInput)
353358
354359static void MutateTxAddOutScript (CMutableTransaction& tx, const string& strInput)
355360{
356- // separate VALUE:SCRIPT in string
357- size_t pos = strInput. find ( ' : ' ) ;
358- if ((pos == string::npos) ||
359- (pos == 0 ) )
360- throw runtime_error (" TX output missing separator" );
361+ // separate VALUE:SCRIPT:ASSET in string
362+ std::vector<std::string> vStrOutScriptParts ;
363+ boost::split (vStrOutScriptParts, strInput, boost::is_any_of ( " : " ));
364+ if (vStrOutScriptParts. size ()< 3 )
365+ throw runtime_error (" TX out script missing separator" );
361366
362367 // extract and validate VALUE
363- string strValue = strInput. substr ( 0 , pos) ;
368+ string strValue = vStrOutScriptParts[ 0 ] ;
364369 CAmount value;
365370 if (!ParseMoney (strValue, value))
366371 throw runtime_error (" invalid TX output value" );
367372
368373 // extract and validate script
369- string strScript = strInput. substr (pos + 1 , string::npos) ;
374+ string strScript = vStrOutScriptParts[ 1 ] ;
370375 CScript scriptPubKey = ParseScript (strScript); // throws on err
371376
377+ // extract and validate asset
378+ string strAsset = vStrOutScriptParts[2 ];
379+ CAssetID asset = uint256S (strAsset);
380+
372381 // construct TxOut, append to transaction output list
373- CTxOut txout (BITCOINID , value, scriptPubKey);
382+ CTxOut txout (asset , value, scriptPubKey);
374383 tx.vout .push_back (txout);
375384}
376385
0 commit comments