Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/rawtransaction.cpp
Show First 20 Lines • Show All 1,124 Lines • ▼ Show 20 Lines | for (size_t idx = 0; idx < keys.size(); ++idx) { | ||||
} | } | ||||
keystore.AddKey(key); | keystore.AddKey(key); | ||||
} | } | ||||
return SignTransaction(mtx, request.params[2], &keystore, true, | return SignTransaction(mtx, request.params[2], &keystore, true, | ||||
request.params[3]); | request.params[3]); | ||||
} | } | ||||
static UniValue signrawtransaction(const Config &config, | |||||
const JSONRPCRequest &request) { | |||||
#ifdef ENABLE_WALLET | |||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | |||||
#endif | |||||
if (request.fHelp || request.params.size() < 1 || | |||||
request.params.size() > 4) { | |||||
throw std::runtime_error( | |||||
"signrawtransaction \"hexstring\" ( " | |||||
"[{\"txid\":\"id\",\"vout\":n,\"scriptPubKey\":\"hex\"," | |||||
"\"redeemScript\":\"hex\"},...] [\"privatekey1\",...] sighashtype " | |||||
")\n" | |||||
"\nDEPRECATED.Sign inputs for raw transaction (serialized, " | |||||
"hex-encoded).\n" | |||||
"The second optional argument (may be null) is an array of " | |||||
"previous transaction outputs that\n" | |||||
"this transaction depends on but may not yet be in the block " | |||||
"chain.\n" | |||||
"The third optional argument (may be null) is an array of " | |||||
"base58-encoded private\n" | |||||
"keys that, if given, will be the only keys used to sign the " | |||||
"transaction.\n" | |||||
#ifdef ENABLE_WALLET | |||||
+ HelpRequiringPassphrase(pwallet) + | |||||
"\n" | |||||
#endif | |||||
"\nArguments:\n" | |||||
"1. \"hexstring\" (string, required) The transaction hex " | |||||
"string\n" | |||||
"2. \"prevtxs\" (string, optional) An json array of previous " | |||||
"dependent transaction outputs\n" | |||||
" [ (json array of json objects, or 'null' if " | |||||
"none provided)\n" | |||||
" {\n" | |||||
" \"txid\":\"id\", (string, required) The " | |||||
"transaction id\n" | |||||
" \"vout\":n, (numeric, required) The " | |||||
"output number\n" | |||||
" \"scriptPubKey\": \"hex\", (string, required) script " | |||||
"key\n" | |||||
" \"redeemScript\": \"hex\", (string, required for P2SH) " | |||||
"redeem script\n" | |||||
" \"amount\": value (numeric, required) The " | |||||
"amount spent\n" | |||||
" }\n" | |||||
" ,...\n" | |||||
" ]\n" | |||||
"3. \"privkeys\" (string, optional) A json array of " | |||||
"base58-encoded private keys for signing\n" | |||||
" [ (json array of strings, or 'null' if none " | |||||
"provided)\n" | |||||
" \"privatekey\" (string) private key in base58-encoding\n" | |||||
" ,...\n" | |||||
" ]\n" | |||||
"4. \"sighashtype\" (string, optional, default=ALL) The " | |||||
"signature hash type. Must be one of\n" | |||||
" \"ALL|FORKID\"\n" | |||||
" \"NONE|FORKID\"\n" | |||||
" \"SINGLE|FORKID\"\n" | |||||
" \"ALL|FORKID|ANYONECANPAY\"\n" | |||||
" \"NONE|FORKID|ANYONECANPAY\"\n" | |||||
" \"SINGLE|FORKID|ANYONECANPAY\"\n" | |||||
"\nResult:\n" | |||||
"{\n" | |||||
" \"hex\" : \"value\", (string) The hex-encoded raw " | |||||
"transaction with signature(s)\n" | |||||
" \"complete\" : true|false, (boolean) If the transaction has a " | |||||
"complete set of signatures\n" | |||||
" \"errors\" : [ (json array of objects) Script " | |||||
"verification errors (if there are any)\n" | |||||
" {\n" | |||||
" \"txid\" : \"hash\", (string) The hash of the " | |||||
"referenced, previous transaction\n" | |||||
" \"vout\" : n, (numeric) The index of the " | |||||
"output to spent and used as input\n" | |||||
" \"scriptSig\" : \"hex\", (string) The hex-encoded " | |||||
"signature script\n" | |||||
" \"sequence\" : n, (numeric) Script sequence " | |||||
"number\n" | |||||
" \"error\" : \"text\" (string) Verification or " | |||||
"signing error related to the input\n" | |||||
" }\n" | |||||
" ,...\n" | |||||
" ]\n" | |||||
"}\n" | |||||
"\nExamples:\n" + | |||||
HelpExampleCli("signrawtransaction", "\"myhex\"") + | |||||
HelpExampleRpc("signrawtransaction", "\"myhex\"")); | |||||
} | |||||
if (!IsDeprecatedRPCEnabled(gArgs, "signrawtransaction")) { | |||||
throw JSONRPCError( | |||||
RPC_METHOD_DEPRECATED, | |||||
"signrawtransaction is deprecated and will be fully removed in " | |||||
"v0.20. " | |||||
"To use signrawtransaction in v0.19, restart bitcoind with " | |||||
"-deprecatedrpc=signrawtransaction.\n" | |||||
"Projects should transition to using signrawtransactionwithkey and " | |||||
"signrawtransactionwithwallet before upgrading to v0.20"); | |||||
} | |||||
RPCTypeCheck( | |||||
request.params, | |||||
{UniValue::VSTR, UniValue::VARR, UniValue::VARR, UniValue::VSTR}, true); | |||||
// Make a JSONRPCRequest to pass on to the right signrawtransaction* command | |||||
JSONRPCRequest new_request; | |||||
new_request.id = request.id; | |||||
new_request.URI = std::move(request.URI); | |||||
new_request.params.setArray(); | |||||
// For signing with private keys | |||||
if (!request.params[2].isNull()) { | |||||
new_request.params.push_back(request.params[0]); | |||||
// Note: the prevtxs and privkeys are reversed for | |||||
// signrawtransactionwithkey | |||||
new_request.params.push_back(request.params[2]); | |||||
new_request.params.push_back(request.params[1]); | |||||
new_request.params.push_back(request.params[3]); | |||||
return signrawtransactionwithkey(config, new_request); | |||||
} else { | |||||
#ifdef ENABLE_WALLET | |||||
// Otherwise sign with the wallet which does not take a privkeys | |||||
// parameter | |||||
new_request.params.push_back(request.params[0]); | |||||
new_request.params.push_back(request.params[1]); | |||||
new_request.params.push_back(request.params[3]); | |||||
return signrawtransactionwithwallet(config, new_request); | |||||
#else | |||||
// If we have made it this far, then wallet is disabled and no private | |||||
// keys were given, so fail here. | |||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "No private keys available."); | |||||
#endif | |||||
} | |||||
} | |||||
static UniValue sendrawtransaction(const Config &config, | static UniValue sendrawtransaction(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"sendrawtransaction \"hexstring\" ( allowhighfees )\n" | "sendrawtransaction \"hexstring\" ( allowhighfees )\n" | ||||
"\nSubmits raw transaction (serialized, hex-encoded) to local node " | "\nSubmits raw transaction (serialized, hex-encoded) to local node " | ||||
"and network.\n" | "and network.\n" | ||||
"\nAlso see createrawtransaction and signrawtransaction calls.\n" | "\nAlso see createrawtransaction and signrawtransactionwithkey " | ||||
"calls.\n" | |||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"hexstring\" (string, required) The hex string of the raw " | "1. \"hexstring\" (string, required) The hex string of the raw " | ||||
"transaction)\n" | "transaction)\n" | ||||
"2. allowhighfees (boolean, optional, default=false) Allow high " | "2. allowhighfees (boolean, optional, default=false) Allow high " | ||||
"fees\n" | "fees\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"\"hex\" (string) The transaction hash in hex\n" | "\"hex\" (string) The transaction hash in hex\n" | ||||
"\nExamples:\n" | "\nExamples:\n" | ||||
"\nCreate a transaction\n" + | "\nCreate a transaction\n" + | ||||
HelpExampleCli( | HelpExampleCli( | ||||
"createrawtransaction", | "createrawtransaction", | ||||
"\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" " | "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" " | ||||
"\"{\\\"myaddress\\\":0.01}\"") + | "\"{\\\"myaddress\\\":0.01}\"") + | ||||
"Sign the transaction, and get back the hex\n" + | "Sign the transaction, and get back the hex\n" + | ||||
HelpExampleCli("signrawtransaction", "\"myhex\"") + | HelpExampleCli("signrawtransactionwithwallet", "\"myhex\"") + | ||||
"\nSend the transaction (signed hex)\n" + | "\nSend the transaction (signed hex)\n" + | ||||
HelpExampleCli("sendrawtransaction", "\"signedhex\"") + | HelpExampleCli("sendrawtransaction", "\"signedhex\"") + | ||||
"\nAs a json rpc call\n" + | "\nAs a json rpc call\n" + | ||||
HelpExampleRpc("sendrawtransaction", "\"signedhex\"")); | HelpExampleRpc("sendrawtransaction", "\"signedhex\"")); | ||||
} | } | ||||
std::promise<void> promise; | std::promise<void> promise; | ||||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 1 || | ||||
" \"allowed\" (boolean) If the mempool allows this tx to be inserted\n" | " \"allowed\" (boolean) If the mempool allows this tx to be inserted\n" | ||||
" \"reject-reason\" (string) Rejection string (only present when 'allowed' is false)\n" | " \"reject-reason\" (string) Rejection string (only present when 'allowed' is false)\n" | ||||
" }\n" | " }\n" | ||||
"]\n" | "]\n" | ||||
"\nExamples:\n" | "\nExamples:\n" | ||||
"\nCreate a transaction\n" | "\nCreate a transaction\n" | ||||
+ HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" \"{\\\"myaddress\\\":0.01}\"") + | + HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" \"{\\\"myaddress\\\":0.01}\"") + | ||||
"Sign the transaction, and get back the hex\n" | "Sign the transaction, and get back the hex\n" | ||||
+ HelpExampleCli("signrawtransaction", "\"myhex\"") + | + HelpExampleCli("signrawtransactionwithwallet", "\"myhex\"") + | ||||
"\nTest acceptance of the transaction (signed hex)\n" | "\nTest acceptance of the transaction (signed hex)\n" | ||||
+ HelpExampleCli("testmempoolaccept", "\"signedhex\"") + | + HelpExampleCli("testmempoolaccept", "\"signedhex\"") + | ||||
"\nAs a json rpc call\n" | "\nAs a json rpc call\n" | ||||
+ HelpExampleRpc("testmempoolaccept", "[\"signedhex\"]") | + HelpExampleRpc("testmempoolaccept", "[\"signedhex\"]") | ||||
// clang-format on | // clang-format on | ||||
); | ); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | static const ContextFreeRPCCommand commands[] = { | ||||
// category name actor (function) argNames | // category name actor (function) argNames | ||||
// ------------------- ------------------------ ---------------------- ---------- | // ------------------- ------------------------ ---------------------- ---------- | ||||
{ "rawtransactions", "getrawtransaction", getrawtransaction, {"txid","verbose","blockhash"} }, | { "rawtransactions", "getrawtransaction", getrawtransaction, {"txid","verbose","blockhash"} }, | ||||
{ "rawtransactions", "createrawtransaction", createrawtransaction, {"inputs","outputs","locktime"} }, | { "rawtransactions", "createrawtransaction", createrawtransaction, {"inputs","outputs","locktime"} }, | ||||
{ "rawtransactions", "decoderawtransaction", decoderawtransaction, {"hexstring"} }, | { "rawtransactions", "decoderawtransaction", decoderawtransaction, {"hexstring"} }, | ||||
{ "rawtransactions", "decodescript", decodescript, {"hexstring"} }, | { "rawtransactions", "decodescript", decodescript, {"hexstring"} }, | ||||
{ "rawtransactions", "sendrawtransaction", sendrawtransaction, {"hexstring","allowhighfees"} }, | { "rawtransactions", "sendrawtransaction", sendrawtransaction, {"hexstring","allowhighfees"} }, | ||||
{ "rawtransactions", "combinerawtransaction", combinerawtransaction, {"txs"} }, | { "rawtransactions", "combinerawtransaction", combinerawtransaction, {"txs"} }, | ||||
{ "rawtransactions", "signrawtransaction", signrawtransaction, {"hexstring","prevtxs","privkeys","sighashtype"} }, /* uses wallet if enabled */ | |||||
{ "rawtransactions", "signrawtransactionwithkey", signrawtransactionwithkey, {"hexstring","privkeys","prevtxs","sighashtype"} }, | { "rawtransactions", "signrawtransactionwithkey", signrawtransactionwithkey, {"hexstring","privkeys","prevtxs","sighashtype"} }, | ||||
{ "rawtransactions", "testmempoolaccept", testmempoolaccept, {"rawtxs","allowhighfees"} }, | { "rawtransactions", "testmempoolaccept", testmempoolaccept, {"rawtxs","allowhighfees"} }, | ||||
{ "blockchain", "gettxoutproof", gettxoutproof, {"txids", "blockhash"} }, | { "blockchain", "gettxoutproof", gettxoutproof, {"txids", "blockhash"} }, | ||||
{ "blockchain", "verifytxoutproof", verifytxoutproof, {"proof"} }, | { "blockchain", "verifytxoutproof", verifytxoutproof, {"proof"} }, | ||||
}; | }; | ||||
// clang-format on | // clang-format on | ||||
void RegisterRawTransactionRPCCommands(CRPCTable &t) { | void RegisterRawTransactionRPCCommands(CRPCTable &t) { | ||||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) { | for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) { | ||||
t.appendCommand(commands[vcidx].name, &commands[vcidx]); | t.appendCommand(commands[vcidx].name, &commands[vcidx]); | ||||
} | } | ||||
} | } |