@@ -395,27 +395,47 @@ static void MutateTxAddOutMultiSig(CMutableTransaction& tx, const std::string& s
395395static void MutateTxAddOutData (CMutableTransaction& tx, const std::string& strInput)
396396{
397397 CAmount value = 0 ;
398+
399+ // separate [VALUE:]DATA[:ASSET] in string
400+ std::vector<std::string> vStrInputParts;
401+ boost::split (vStrInputParts, strInput, boost::is_any_of (" :" ));
398402
399- // separate [VALUE:]DATA in string
400- size_t pos = strInput.find (' :' );
401-
402- if (pos==0 )
403+ // Check that there are enough parameters
404+ if (vStrInputParts[0 ].empty ())
403405 throw std::runtime_error (" TX output value not specified" );
404406
405- if (pos != std::string::npos) {
406- // Extract and validate VALUE
407- value = ExtractAndValidateValue (strInput.substr (0 , pos));
408- }
409-
410- // extract and validate DATA
411- std::string strData = strInput.substr (pos + 1 , std::string::npos);
412-
413- if (!IsHex (strData))
414- throw std::runtime_error (" invalid TX output data" );
407+ if (vStrInputParts.size ()>3 )
408+ throw std::runtime_error (" too many separators" );
409+
410+ std::vector<unsigned char > data;
411+ CAsset asset (Params ().GetConsensus ().pegged_asset );
412+
413+ if (vStrInputParts.size ()==1 ) {
414+ std::string strData = vStrInputParts[0 ];
415+ if (!IsHex (strData))
416+ throw std::runtime_error (" invalid TX output data" );
417+ data = ParseHex (strData);
415418
416- std::vector<unsigned char > data = ParseHex (strData);
419+ } else {
420+ value = ExtractAndValidateValue (vStrInputParts[0 ]);
421+ std::string strData = vStrInputParts[1 ];
422+ if (!IsHex (strData))
423+ throw std::runtime_error (" invalid TX output data" );
424+ data = ParseHex (strData);
425+
426+ if (vStrInputParts.size ()==3 ) {
427+ std::string strAsset = vStrInputParts[2 ];
428+ if (!IsHex (strAsset))
429+ throw std::runtime_error (" invalid TX output asset type" );
430+
431+ asset.SetHex (strAsset);
432+ if (asset.IsNull ()) {
433+ throw std::runtime_error (" invalid TX output asset type" );
434+ }
435+ }
436+ }
417437
418- CTxOut txout (Params (). GetConsensus (). pegged_asset , value, CScript () << OP_RETURN << data);
438+ CTxOut txout (asset , value, CScript () << OP_RETURN << data);
419439 tx.vout .push_back (txout);
420440}
421441
0 commit comments