|
|
@ -318,8 +318,9 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (fHelp || params.size() != 2) |
|
|
|
if (fHelp || params.size() != 2) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
|
"createrawtransaction [{\"txid\":\"id\",\"vout\":n},...] {\"address\":amount,...}\n" |
|
|
|
"createrawtransaction [{\"txid\":\"id\",\"vout\":n},...] {\"address\":amount,\"data\":\"hex\",...}\n" |
|
|
|
"\nCreate a transaction spending the given inputs and sending to the given addresses.\n" |
|
|
|
"\nCreate a transaction spending the given inputs and creating new outputs.\n" |
|
|
|
|
|
|
|
"Outputs can be addresses or data.\n" |
|
|
|
"Returns hex-encoded raw transaction.\n" |
|
|
|
"Returns hex-encoded raw transaction.\n" |
|
|
|
"Note that the transaction's inputs are not signed, and\n" |
|
|
|
"Note that the transaction's inputs are not signed, and\n" |
|
|
|
"it is not stored in the wallet or transmitted to the network.\n" |
|
|
|
"it is not stored in the wallet or transmitted to the network.\n" |
|
|
@ -328,23 +329,25 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp) |
|
|
|
"1. \"transactions\" (string, required) A json array of json objects\n" |
|
|
|
"1. \"transactions\" (string, required) A json array of json objects\n" |
|
|
|
" [\n" |
|
|
|
" [\n" |
|
|
|
" {\n" |
|
|
|
" {\n" |
|
|
|
" \"txid\":\"id\", (string, required) The transaction id\n" |
|
|
|
" \"txid\":\"id\", (string, required) The transaction id\n" |
|
|
|
" \"vout\":n (numeric, required) The output number\n" |
|
|
|
" \"vout\":n (numeric, required) The output number\n" |
|
|
|
" }\n" |
|
|
|
" }\n" |
|
|
|
" ,...\n" |
|
|
|
" ,...\n" |
|
|
|
" ]\n" |
|
|
|
" ]\n" |
|
|
|
"2. \"addresses\" (string, required) a json object with addresses as keys and amounts as values\n" |
|
|
|
"2. \"outputs\" (string, required) a json object with outputs\n" |
|
|
|
" {\n" |
|
|
|
" {\n" |
|
|
|
" \"address\": x.xxx (numeric, required) The key is the bitcoin address, the value is the " + CURRENCY_UNIT + " amount\n" |
|
|
|
" \"address\": x.xxx (numeric, required) The key is the bitcoin address, the value is the " + CURRENCY_UNIT + " amount\n" |
|
|
|
" ,...\n" |
|
|
|
" \"data\": \"hex\", (string, required) The key is \"data\", the value is hex encoded data\n" |
|
|
|
|
|
|
|
" ...\n" |
|
|
|
" }\n" |
|
|
|
" }\n" |
|
|
|
|
|
|
|
|
|
|
|
"\nResult:\n" |
|
|
|
"\nResult:\n" |
|
|
|
"\"transaction\" (string) hex string of the transaction\n" |
|
|
|
"\"transaction\" (string) hex string of the transaction\n" |
|
|
|
|
|
|
|
|
|
|
|
"\nExamples\n" |
|
|
|
"\nExamples\n" |
|
|
|
+ HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"{\\\"address\\\":0.01}\"") |
|
|
|
+ HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"{\\\"address\\\":0.01}\"") |
|
|
|
|
|
|
|
+ HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"{\\\"data\\\":\\\"00010203\\\"}\"") |
|
|
|
+ HelpExampleRpc("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"address\\\":0.01}\"") |
|
|
|
+ HelpExampleRpc("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"address\\\":0.01}\"") |
|
|
|
|
|
|
|
+ HelpExampleRpc("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"data\\\":\\\"00010203\\\"}\"") |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
LOCK(cs_main); |
|
|
|
LOCK(cs_main); |
|
|
@ -375,19 +378,27 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp) |
|
|
|
set<CBitcoinAddress> setAddress; |
|
|
|
set<CBitcoinAddress> setAddress; |
|
|
|
vector<string> addrList = sendTo.getKeys(); |
|
|
|
vector<string> addrList = sendTo.getKeys(); |
|
|
|
BOOST_FOREACH(const string& name_, addrList) { |
|
|
|
BOOST_FOREACH(const string& name_, addrList) { |
|
|
|
CBitcoinAddress address(name_); |
|
|
|
|
|
|
|
if (!address.IsValid()) |
|
|
|
|
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Bitcoin address: ")+name_); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (setAddress.count(address)) |
|
|
|
if (name_ == "data") { |
|
|
|
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+name_); |
|
|
|
std::vector<unsigned char> data = ParseHexV(sendTo[name_].getValStr(),"Data"); |
|
|
|
setAddress.insert(address); |
|
|
|
|
|
|
|
|
|
|
|
CTxOut out(0, CScript() << OP_RETURN << data); |
|
|
|
|
|
|
|
rawTx.vout.push_back(out); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
CBitcoinAddress address(name_); |
|
|
|
|
|
|
|
if (!address.IsValid()) |
|
|
|
|
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Bitcoin address: ")+name_); |
|
|
|
|
|
|
|
|
|
|
|
CScript scriptPubKey = GetScriptForDestination(address.Get()); |
|
|
|
if (setAddress.count(address)) |
|
|
|
CAmount nAmount = AmountFromValue(sendTo[name_]); |
|
|
|
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+name_); |
|
|
|
|
|
|
|
setAddress.insert(address); |
|
|
|
|
|
|
|
|
|
|
|
CTxOut out(nAmount, scriptPubKey); |
|
|
|
CScript scriptPubKey = GetScriptForDestination(address.Get()); |
|
|
|
rawTx.vout.push_back(out); |
|
|
|
CAmount nAmount = AmountFromValue(sendTo[name_]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CTxOut out(nAmount, scriptPubKey); |
|
|
|
|
|
|
|
rawTx.vout.push_back(out); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return EncodeHexTx(rawTx); |
|
|
|
return EncodeHexTx(rawTx); |
|
|
|