@@ -318,8 +318,9 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
318318{
319319 if (fHelp || params.size () != 2 )
320320 throw runtime_error (
321- " createrawtransaction [{\" txid\" :\" id\" ,\" vout\" :n},...] {\" address\" :amount,...}\n "
322- " \n Create a transaction spending the given inputs and sending to the given addresses.\n "
321+ " createrawtransaction [{\" txid\" :\" id\" ,\" vout\" :n},...] {\" address\" :amount,\" data\" :\" hex\" ,...}\n "
322+ " \n Create a transaction spending the given inputs and creating new outputs.\n "
323+ " Outputs can be addresses or data.\n "
323324 " Returns hex-encoded raw transaction.\n "
324325 " Note that the transaction's inputs are not signed, and\n "
325326 " it is not stored in the wallet or transmitted to the network.\n "
@@ -328,23 +329,25 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
328329 " 1. \" transactions\" (string, required) A json array of json objects\n "
329330 " [\n "
330331 " {\n "
331- " \" txid\" :\" id\" , (string, required) The transaction id\n "
332+ " \" txid\" :\" id\" , (string, required) The transaction id\n "
332333 " \" vout\" :n (numeric, required) The output number\n "
333334 " }\n "
334335 " ,...\n "
335336 " ]\n "
336- " 2. \" addresses \" (string, required) a json object with addresses as keys and amounts as values \n "
337+ " 2. \" outputs \" (string, required) a json object with outputs \n "
337338 " {\n "
338339 " \" address\" : x.xxx (numeric, required) The key is the bitcoin address, the value is the " + CURRENCY_UNIT + " amount\n "
339- " ,...\n "
340+ " \" data\" : \" hex\" , (string, required) The key is \" data\" , the value is hex encoded data\n "
341+ " ...\n "
340342 " }\n "
341-
342343 " \n Result:\n "
343344 " \" transaction\" (string) hex string of the transaction\n "
344345
345346 " \n Examples\n "
346347 + HelpExampleCli (" createrawtransaction" , " \" [{\\\" txid\\\" :\\\" myid\\\" ,\\\" vout\\\" :0}]\" \" {\\\" address\\\" :0.01}\" " )
348+ + HelpExampleCli (" createrawtransaction" , " \" [{\\\" txid\\\" :\\\" myid\\\" ,\\\" vout\\\" :0}]\" \" {\\\" data\\\" :\\\" 00010203\\\" }\" " )
347349 + HelpExampleRpc (" createrawtransaction" , " \" [{\\\" txid\\\" :\\\" myid\\\" ,\\\" vout\\\" :0}]\" , \" {\\\" address\\\" :0.01}\" " )
350+ + HelpExampleRpc (" createrawtransaction" , " \" [{\\\" txid\\\" :\\\" myid\\\" ,\\\" vout\\\" :0}]\" , \" {\\\" data\\\" :\\\" 00010203\\\" }\" " )
348351 );
349352
350353 LOCK (cs_main);
@@ -375,19 +378,27 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
375378 set<CBitcoinAddress> setAddress;
376379 vector<string> addrList = sendTo.getKeys ();
377380 BOOST_FOREACH (const string& name_, addrList) {
378- CBitcoinAddress address (name_);
379- if (!address.IsValid ())
380- throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, string (" Invalid Bitcoin address: " )+name_);
381381
382- if (setAddress.count (address))
383- throw JSONRPCError (RPC_INVALID_PARAMETER, string (" Invalid parameter, duplicated address: " )+name_);
384- setAddress.insert (address);
382+ if (name_ == " data" ) {
383+ std::vector<unsigned char > data = ParseHexV (sendTo[name_].getValStr ()," Data" );
384+
385+ CTxOut out (0 , CScript () << OP_RETURN << data);
386+ rawTx.vout .push_back (out);
387+ } else {
388+ CBitcoinAddress address (name_);
389+ if (!address.IsValid ())
390+ throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, string (" Invalid Bitcoin address: " )+name_);
385391
386- CScript scriptPubKey = GetScriptForDestination (address.Get ());
387- CAmount nAmount = AmountFromValue (sendTo[name_]);
392+ if (setAddress.count (address))
393+ throw JSONRPCError (RPC_INVALID_PARAMETER, string (" Invalid parameter, duplicated address: " )+name_);
394+ setAddress.insert (address);
388395
389- CTxOut out (nAmount, scriptPubKey);
390- rawTx.vout .push_back (out);
396+ CScript scriptPubKey = GetScriptForDestination (address.Get ());
397+ CAmount nAmount = AmountFromValue (sendTo[name_]);
398+
399+ CTxOut out (nAmount, scriptPubKey);
400+ rawTx.vout .push_back (out);
401+ }
391402 }
392403
393404 return EncodeHexTx (rawTx);
0 commit comments