Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/rawtransaction.cpp
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | if (!hashBlock.IsNull()) { | ||||
} | } | ||||
} | } | ||||
} | } | ||||
static UniValue getrawtransaction(const Config &config, | static UniValue getrawtransaction(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() > 3) { | request.params.size() > 3) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"getrawtransaction", | "getrawtransaction", | ||||
"\nNOTE: By default this function only works for " | "\nNOTE: By default this function only works for " | ||||
"mempool transactions. If the -txindex option is\n" | "mempool transactions. If the -txindex option is\n" | ||||
"enabled, it also works for blockchain transactions. If " | "enabled, it also works for blockchain transactions. If " | ||||
"the block which contains the transaction\n" | "the block which contains the transaction\n" | ||||
"is known, its hash can be provided even for nodes " | "is known, its hash can be provided even for nodes " | ||||
"without -txindex. Note that if a blockhash is\n" | "without -txindex. Note that if a blockhash is\n" | ||||
"provided, only that block will be searched and if the " | "provided, only that block will be searched and if the " | ||||
"transaction is in the mempool or other\n" | "transaction is in the mempool or other\n" | ||||
"blocks, or if this node does not have the given block " | "blocks, or if this node does not have the given block " | ||||
"available, the transaction will not be found.\n" | "available, the transaction will not be found.\n" | ||||
"DEPRECATED: for now, it also works for transactions with " | "DEPRECATED: for now, it also works for transactions with " | ||||
"unspent outputs.\n" | "unspent outputs.\n" | ||||
"\nReturn the raw transaction data.\n" | "\nReturn the raw transaction data.\n" | ||||
"\nIf verbose is 'true', returns an Object with information " | "\nIf verbose is 'true', returns an Object with information " | ||||
"about 'txid'.\n" | "about 'txid'.\n" | ||||
"If verbose is 'false' or omitted, returns a string that is " | "If verbose is 'false' or omitted, returns a string that is " | ||||
"serialized, hex-encoded data for 'txid'.\n", | "serialized, hex-encoded data for 'txid'.\n", | ||||
{ | { | ||||
{"txid", RPCArg::Type::STR_HEX, /* opt */ false, | {"txid", RPCArg::Type::STR_HEX, /* opt */ false, | ||||
/* default_val */ "", "The transaction id"}, | /* default_val */ "", "The transaction id"}, | ||||
{"verbose", RPCArg::Type::BOOL, /* opt */ true, | {"verbose", RPCArg::Type::BOOL, /* opt */ true, | ||||
/* default_val */ "false", | /* default_val */ "false", | ||||
"If false, return a string, otherwise return a json " | "If false, return a string, otherwise return a json " | ||||
"object"}, | "object"}, | ||||
{"blockhash", RPCArg::Type::STR_HEX, /* opt */ true, | {"blockhash", RPCArg::Type::STR_HEX, /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"The block in which to look for the transaction"}, | "The block in which to look for the transaction"}, | ||||
}} | }, | ||||
.ToString() + | { | ||||
"\nResult (if verbose is not set or set to false):\n" | RPCResult{"if verbose is not set or set to false", | ||||
"\"data\" (string) The serialized, hex-encoded data for " | "\"data\" (string) The serialized, hex-encoded " | ||||
"'txid'\n" | "data for 'txid'\n"}, | ||||
RPCResult{ | |||||
"\nResult (if verbose is set to true):\n" | "if verbose is set to true", | ||||
"{\n" | "{\n" | ||||
" \"in_active_chain\": b, (bool) Whether specified block is in " | " \"in_active_chain\": b, (bool) Whether specified block " | ||||
"the active chain or not (only present with explicit \"blockhash\" " | "is in " | ||||
"the active chain or not (only present with explicit " | |||||
"\"blockhash\" " | |||||
"argument)\n" | "argument)\n" | ||||
" \"hex\" : \"data\", (string) The serialized, hex-encoded " | " \"hex\" : \"data\", (string) The serialized, " | ||||
"hex-encoded " | |||||
"data for 'txid'\n" | "data for 'txid'\n" | ||||
" \"txid\" : \"id\", (string) The transaction id (same as " | " \"txid\" : \"id\", (string) The transaction id " | ||||
"(same as " | |||||
"provided)\n" | "provided)\n" | ||||
" \"hash\" : \"id\", (string) The transaction hash " | " \"hash\" : \"id\", (string) The transaction hash " | ||||
"(differs from txid for witness transactions)\n" | "(differs from txid for witness transactions)\n" | ||||
" \"size\" : n, (numeric) The serialized transaction " | " \"size\" : n, (numeric) The serialized " | ||||
"transaction " | |||||
"size\n" | "size\n" | ||||
" \"version\" : n, (numeric) The version\n" | " \"version\" : n, (numeric) The version\n" | ||||
" \"locktime\" : ttt, (numeric) The lock time\n" | " \"locktime\" : ttt, (numeric) The lock time\n" | ||||
" \"vin\" : [ (array of json objects)\n" | " \"vin\" : [ (array of json objects)\n" | ||||
" {\n" | " {\n" | ||||
" \"txid\": \"id\", (string) The transaction id\n" | " \"txid\": \"id\", (string) The transaction id\n" | ||||
" \"vout\": n, (numeric) \n" | " \"vout\": n, (numeric) \n" | ||||
" \"scriptSig\": { (json object) The script\n" | " \"scriptSig\": { (json object) The script\n" | ||||
" \"asm\": \"asm\", (string) asm\n" | " \"asm\": \"asm\", (string) asm\n" | ||||
" \"hex\": \"hex\" (string) hex\n" | " \"hex\": \"hex\" (string) hex\n" | ||||
" },\n" | " },\n" | ||||
" \"sequence\": n (numeric) The script sequence number\n" | " \"sequence\": n (numeric) The script sequence " | ||||
"number\n" | |||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ],\n" | " ],\n" | ||||
" \"vout\" : [ (array of json objects)\n" | " \"vout\" : [ (array of json objects)\n" | ||||
" {\n" | " {\n" | ||||
" \"value\" : x.xxx, (numeric) The value in " + | " \"value\" : x.xxx, (numeric) The value " | ||||
"in " + | |||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
"\n" | "\n" | ||||
" \"n\" : n, (numeric) index\n" | " \"n\" : n, (numeric) index\n" | ||||
" \"scriptPubKey\" : { (json object)\n" | " \"scriptPubKey\" : { (json object)\n" | ||||
" \"asm\" : \"asm\", (string) the asm\n" | " \"asm\" : \"asm\", (string) the " | ||||
" \"hex\" : \"hex\", (string) the hex\n" | "asm\n" | ||||
" \"reqSigs\" : n, (numeric) The required sigs\n" | " \"hex\" : \"hex\", (string) the " | ||||
" \"type\" : \"pubkeyhash\", (string) The type, eg " | "hex\n" | ||||
" \"reqSigs\" : n, (numeric) The " | |||||
"required sigs\n" | |||||
" \"type\" : \"pubkeyhash\", (string) The " | |||||
"type, eg " | |||||
"'pubkeyhash'\n" | "'pubkeyhash'\n" | ||||
" \"addresses\" : [ (json array of string)\n" | " \"addresses\" : [ (json array of " | ||||
" \"address\" (string) bitcoin address\n" | "string)\n" | ||||
" \"address\" (string) bitcoin " | |||||
"address\n" | |||||
" ,...\n" | " ,...\n" | ||||
" ]\n" | " ]\n" | ||||
" }\n" | " }\n" | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ],\n" | " ],\n" | ||||
" \"blockhash\" : \"hash\", (string) the block hash\n" | " \"blockhash\" : \"hash\", (string) the block " | ||||
" \"confirmations\" : n, (numeric) The confirmations\n" | "hash\n" | ||||
" \"time\" : ttt, (numeric) The transaction time in " | " \"confirmations\" : n, (numeric) The " | ||||
"confirmations\n" | |||||
" \"time\" : ttt, (numeric) The " | |||||
"transaction time in " | |||||
"seconds since epoch (Jan 1 1970 GMT)\n" | "seconds since epoch (Jan 1 1970 GMT)\n" | ||||
" \"blocktime\" : ttt (numeric) The block time in seconds " | " \"blocktime\" : ttt (numeric) The block " | ||||
"time in seconds " | |||||
"since epoch (Jan 1 1970 GMT)\n" | "since epoch (Jan 1 1970 GMT)\n" | ||||
"}\n" | "}\n"}, | ||||
}, | |||||
"\nExamples:\n" + | RPCExamples{ | ||||
HelpExampleCli("getrawtransaction", "\"mytxid\"") + | HelpExampleCli("getrawtransaction", "\"mytxid\"") + | ||||
HelpExampleCli("getrawtransaction", "\"mytxid\" true") + | HelpExampleCli("getrawtransaction", "\"mytxid\" true") + | ||||
HelpExampleRpc("getrawtransaction", "\"mytxid\", true") + | HelpExampleRpc("getrawtransaction", "\"mytxid\", true") + | ||||
HelpExampleCli("getrawtransaction", | HelpExampleCli("getrawtransaction", | ||||
"\"mytxid\" false \"myblockhash\"") + | "\"mytxid\" false \"myblockhash\"") + | ||||
HelpExampleCli("getrawtransaction", | HelpExampleCli("getrawtransaction", | ||||
"\"mytxid\" true \"myblockhash\"")); | "\"mytxid\" true \"myblockhash\"")}, | ||||
} | |||||
.ToString()); | |||||
} | } | ||||
bool in_active_chain = true; | bool in_active_chain = true; | ||||
TxId txid = TxId(ParseHashV(request.params[0], "parameter 1")); | TxId txid = TxId(ParseHashV(request.params[0], "parameter 1")); | ||||
CBlockIndex *blockindex = nullptr; | CBlockIndex *blockindex = nullptr; | ||||
const CChainParams ¶ms = config.GetChainParams(); | const CChainParams ¶ms = config.GetChainParams(); | ||||
if (txid == params.GenesisBlock().hashMerkleRoot) { | if (txid == params.GenesisBlock().hashMerkleRoot) { | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | static UniValue getrawtransaction(const Config &config, | ||||
TxToJSON(*tx, hash_block, result); | TxToJSON(*tx, hash_block, result); | ||||
return result; | return result; | ||||
} | } | ||||
static UniValue gettxoutproof(const Config &config, | static UniValue gettxoutproof(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || | if (request.fHelp || | ||||
(request.params.size() != 1 && request.params.size() != 2)) { | (request.params.size() != 1 && request.params.size() != 2)) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"gettxoutproof", | "gettxoutproof", | ||||
"\nReturns a hex-encoded proof that \"txid\" was " | "\nReturns a hex-encoded proof that \"txid\" was " | ||||
"included in a block.\n" | "included in a block.\n" | ||||
"\nNOTE: By default this function only works sometimes. " | "\nNOTE: By default this function only works sometimes. " | ||||
"This is when there is an\n" | "This is when there is an\n" | ||||
"unspent output in the utxo for this transaction. To " | "unspent output in the utxo for this transaction. To " | ||||
"make it always work,\n" | "make it always work,\n" | ||||
"you need to maintain a transaction index, using the " | "you need to maintain a transaction index, using the " | ||||
"-txindex command line option or\n" | "-txindex command line option or\n" | ||||
"specify the block in which the transaction is included " | "specify the block in which the transaction is included " | ||||
"manually (by blockhash).\n", | "manually (by blockhash).\n", | ||||
{ | { | ||||
{ | { | ||||
"txids", | "txids", | ||||
RPCArg::Type::ARR, | RPCArg::Type::ARR, | ||||
/* opt */ false, | /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"A json array of txids to filter", | "A json array of txids to filter", | ||||
{ | { | ||||
{"txid", RPCArg::Type::STR_HEX, /* opt */ false, | {"txid", RPCArg::Type::STR_HEX, /* opt */ false, | ||||
/* default_val */ "", "A transaction hash"}, | /* default_val */ "", "A transaction hash"}, | ||||
}, | }, | ||||
}, | }, | ||||
{"blockhash", RPCArg::Type::STR_HEX, /* opt */ true, | {"blockhash", RPCArg::Type::STR_HEX, /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"If specified, looks for txid in the block with this " | "If specified, looks for txid in the block with this " | ||||
"hash"}, | "hash"}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{"\"data\" (string) A string that is a " | ||||
"\nResult:\n" | "serialized, hex-encoded data for the proof.\n"}, | ||||
"\"data\" (string) A string that is a serialized, " | RPCExamples{""}, | ||||
"hex-encoded data for the proof.\n"); | } | ||||
.ToString()); | |||||
} | } | ||||
std::set<TxId> setTxIds; | std::set<TxId> setTxIds; | ||||
TxId oneTxId; | TxId oneTxId; | ||||
UniValue txids = request.params[0].get_array(); | UniValue txids = request.params[0].get_array(); | ||||
for (unsigned int idx = 0; idx < txids.size(); idx++) { | for (unsigned int idx = 0; idx < txids.size(); idx++) { | ||||
const UniValue &utxid = txids[idx]; | const UniValue &utxid = txids[idx]; | ||||
TxId txid(ParseHashV(utxid, "txid")); | TxId txid(ParseHashV(utxid, "txid")); | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | static UniValue gettxoutproof(const Config &config, | ||||
ssMB << mb; | ssMB << mb; | ||||
std::string strHex = HexStr(ssMB.begin(), ssMB.end()); | std::string strHex = HexStr(ssMB.begin(), ssMB.end()); | ||||
return strHex; | return strHex; | ||||
} | } | ||||
static UniValue verifytxoutproof(const Config &config, | static UniValue verifytxoutproof(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"verifytxoutproof", | "verifytxoutproof", | ||||
"\nVerifies that a proof points to a transaction in a " | "\nVerifies that a proof points to a transaction in a " | ||||
"block, returning the transaction it commits to\n" | "block, returning the transaction it commits to\n" | ||||
"and throwing an RPC error if the block is not in our " | "and throwing an RPC error if the block is not in our " | ||||
"best chain\n", | "best chain\n", | ||||
{ | { | ||||
{"proof", RPCArg::Type::STR_HEX, /* opt */ false, | {"proof", RPCArg::Type::STR_HEX, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"The hex-encoded proof generated by gettxoutproof"}, | "The hex-encoded proof generated by gettxoutproof"}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{"[\"txid\"] (array, strings) The txid(s) which the " | ||||
"\nResult:\n" | "proof commits to, or empty array if the proof can not " | ||||
"[\"txid\"] (array, strings) The txid(s) which the proof " | "be validated.\n"}, | ||||
"commits to, or empty array if the proof can not be validated.\n"); | RPCExamples{""}, | ||||
} | |||||
.ToString()); | |||||
} | } | ||||
CDataStream ssMB(ParseHexV(request.params[0], "proof"), SER_NETWORK, | CDataStream ssMB(ParseHexV(request.params[0], "proof"), SER_NETWORK, | ||||
PROTOCOL_VERSION); | PROTOCOL_VERSION); | ||||
CMerkleBlock merkleBlock; | CMerkleBlock merkleBlock; | ||||
ssMB >> merkleBlock; | ssMB >> merkleBlock; | ||||
UniValue res(UniValue::VARR); | UniValue res(UniValue::VARR); | ||||
▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | CMutableTransaction ConstructTransaction(const CChainParams ¶ms, | ||||
return rawTx; | return rawTx; | ||||
} | } | ||||
static UniValue createrawtransaction(const Config &config, | static UniValue createrawtransaction(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() < 2 || | if (request.fHelp || request.params.size() < 2 || | ||||
request.params.size() > 3) { | request.params.size() > 3) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"createrawtransaction", | "createrawtransaction", | ||||
"\nCreate a transaction spending the given inputs and creating " | "\nCreate a transaction spending the given inputs and creating " | ||||
"new outputs.\n" | "new outputs.\n" | ||||
"Outputs can be addresses or data.\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 " | "it is not stored in the wallet or transmitted to the " | ||||
"network.\n", | "network.\n", | ||||
{ | { | ||||
{ | { | ||||
"inputs", | "inputs", | ||||
RPCArg::Type::ARR, | RPCArg::Type::ARR, | ||||
/* opt */ false, | /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"A json array of json objects", | "A json array of json objects", | ||||
{ | { | ||||
{ | { | ||||
"", | "", | ||||
RPCArg::Type::OBJ, | RPCArg::Type::OBJ, | ||||
/* opt */ false, | /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"", | "", | ||||
{ | { | ||||
{"txid", RPCArg::Type::STR_HEX, | {"txid", RPCArg::Type::STR_HEX, | ||||
/* opt */ false, /* default_val */ "", | /* opt */ false, /* default_val */ "", | ||||
"The transaction id"}, | "The transaction id"}, | ||||
{"vout", RPCArg::Type::NUM, /* opt */ false, | {"vout", RPCArg::Type::NUM, /* opt */ false, | ||||
/* default_val */ "", "The output number"}, | /* default_val */ "", "The output number"}, | ||||
{"sequence", RPCArg::Type::NUM, | {"sequence", RPCArg::Type::NUM, | ||||
/* opt */ true, /* default_val */ "", | /* opt */ true, /* default_val */ "", | ||||
"The sequence number"}, | "The sequence number"}, | ||||
}, | }, | ||||
}, | }, | ||||
}, | }, | ||||
}, | }, | ||||
{ | { | ||||
"outputs", | "outputs", | ||||
RPCArg::Type::ARR, | RPCArg::Type::ARR, | ||||
/* opt */ false, | /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"a json array with outputs (key-value pairs).\n" | "a json array with outputs (key-value pairs).\n" | ||||
"For compatibility reasons, a dictionary, which holds " | "For compatibility reasons, a dictionary, which holds " | ||||
"the key-value pairs directly, is also\n" | "the key-value pairs directly, is also\n" | ||||
" accepted as second " | " accepted as second " | ||||
"parameter.", | "parameter.", | ||||
{ | { | ||||
{ | { | ||||
"", | "", | ||||
RPCArg::Type::OBJ, | RPCArg::Type::OBJ, | ||||
/* opt */ true, | /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"", | "", | ||||
{ | { | ||||
{"address", RPCArg::Type::AMOUNT, | {"address", RPCArg::Type::AMOUNT, | ||||
/* opt */ false, /* default_val */ "", | /* opt */ false, /* default_val */ "", | ||||
"A key-value pair. The key (string) is " | "A key-value pair. The key (string) is " | ||||
"the bitcoin address, the value (float or " | "the bitcoin address, the value (float or " | ||||
"string) is the amount in " + | "string) is the amount in " + | ||||
CURRENCY_UNIT}, | CURRENCY_UNIT}, | ||||
}, | }, | ||||
}, | }, | ||||
{ | { | ||||
"", | "", | ||||
RPCArg::Type::OBJ, | RPCArg::Type::OBJ, | ||||
/* opt */ true, | /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"", | "", | ||||
{ | { | ||||
{"data", RPCArg::Type::STR_HEX, | {"data", RPCArg::Type::STR_HEX, | ||||
/* opt */ false, /* default_val */ "", | /* opt */ false, /* default_val */ "", | ||||
"A key-value pair. The key must be " | "A key-value pair. The key must be " | ||||
"\"data\", the value is hex-encoded data"}, | "\"data\", the value is hex-encoded data"}, | ||||
}, | }, | ||||
}, | }, | ||||
}, | }, | ||||
}, | }, | ||||
{"locktime", RPCArg::Type::NUM, /* opt */ true, | {"locktime", RPCArg::Type::NUM, /* opt */ true, | ||||
/* default_val */ "0", | /* default_val */ "0", | ||||
"Raw locktime. Non-0 value also locktime-activates " | "Raw locktime. Non-0 value also locktime-activates " | ||||
"inputs"}, | "inputs"}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{"\"transaction\" (string) hex string of the " | ||||
"\nResult:\n" | "transaction\n"}, | ||||
"\"transaction\" (string) hex string of the " | RPCExamples{ | ||||
"transaction\n" | |||||
"\nExamples:\n" + | |||||
HelpExampleCli("createrawtransaction", | HelpExampleCli("createrawtransaction", | ||||
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" " | "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]" | ||||
"\"[{\\\"address\\\":0.01}]\"") + | "\" \"[{\\\"address\\\":0.01}]\"") + | ||||
HelpExampleCli("createrawtransaction", | HelpExampleCli("createrawtransaction", | ||||
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" " | "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]" | ||||
"\"[{\\\"data\\\":\\\"00010203\\\"}]\"") + | "\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"") + | ||||
HelpExampleRpc("createrawtransaction", | HelpExampleRpc("createrawtransaction", | ||||
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", " | "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]" | ||||
"\"[{\\\"address\\\":0.01}]\"") + | "\", \"[{\\\"address\\\":0.01}]\"") + | ||||
HelpExampleRpc("createrawtransaction", | HelpExampleRpc("createrawtransaction", | ||||
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", " | "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]" | ||||
"\"[{\\\"data\\\":\\\"00010203\\\"}]\"")); | "\", \"[{\\\"data\\\":\\\"00010203\\\"}]\"")}, | ||||
} | |||||
.ToString()); | |||||
} | } | ||||
RPCTypeCheck(request.params, | RPCTypeCheck(request.params, | ||||
{UniValue::VARR, | {UniValue::VARR, | ||||
UniValueType(), // ARR or OBJ, checked later | UniValueType(), // ARR or OBJ, checked later | ||||
UniValue::VNUM}, | UniValue::VNUM}, | ||||
true); | true); | ||||
CMutableTransaction rawTx = | CMutableTransaction rawTx = | ||||
ConstructTransaction(config.GetChainParams(), request.params[0], | ConstructTransaction(config.GetChainParams(), request.params[0], | ||||
request.params[1], request.params[2]); | request.params[1], request.params[2]); | ||||
return EncodeHexTx(CTransaction(rawTx)); | return EncodeHexTx(CTransaction(rawTx)); | ||||
} | } | ||||
static UniValue decoderawtransaction(const Config &config, | static UniValue decoderawtransaction(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"decoderawtransaction", | "decoderawtransaction", | ||||
"\nReturn a JSON object representing the serialized, " | "\nReturn a JSON object representing the serialized, " | ||||
"hex-encoded transaction.\n", | "hex-encoded transaction.\n", | ||||
{ | { | ||||
{"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, | {"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, | ||||
/* default_val */ "", "The transaction hex string"}, | /* default_val */ "", "The transaction hex string"}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{ | ||||
"\nResult:\n" | |||||
"{\n" | "{\n" | ||||
" \"txid\" : \"id\", (string) The transaction id\n" | " \"txid\" : \"id\", (string) The transaction id\n" | ||||
" \"hash\" : \"id\", (string) The transaction hash " | " \"hash\" : \"id\", (string) The transaction hash " | ||||
"(differs from txid for witness transactions)\n" | "(differs from txid for witness transactions)\n" | ||||
" \"size\" : n, (numeric) The transaction size\n" | " \"size\" : n, (numeric) The transaction size\n" | ||||
" \"version\" : n, (numeric) The version\n" | " \"version\" : n, (numeric) The version\n" | ||||
" \"locktime\" : ttt, (numeric) The lock time\n" | " \"locktime\" : ttt, (numeric) The lock time\n" | ||||
" \"vin\" : [ (array of json objects)\n" | " \"vin\" : [ (array of json objects)\n" | ||||
" {\n" | " {\n" | ||||
" \"txid\": \"id\", (string) The transaction id\n" | " \"txid\": \"id\", (string) The transaction id\n" | ||||
" \"vout\": n, (numeric) The output number\n" | " \"vout\": n, (numeric) The output number\n" | ||||
" \"scriptSig\": { (json object) The script\n" | " \"scriptSig\": { (json object) The script\n" | ||||
" \"asm\": \"asm\", (string) asm\n" | " \"asm\": \"asm\", (string) asm\n" | ||||
" \"hex\": \"hex\" (string) hex\n" | " \"hex\": \"hex\" (string) hex\n" | ||||
" },\n" | " },\n" | ||||
" \"sequence\": n (numeric) The script sequence number\n" | " \"sequence\": n (numeric) The script sequence " | ||||
"number\n" | |||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ],\n" | " ],\n" | ||||
" \"vout\" : [ (array of json objects)\n" | " \"vout\" : [ (array of json objects)\n" | ||||
" {\n" | " {\n" | ||||
" \"value\" : x.xxx, (numeric) The value in " + | " \"value\" : x.xxx, (numeric) The value in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
"\n" | "\n" | ||||
" \"n\" : n, (numeric) index\n" | " \"n\" : n, (numeric) index\n" | ||||
" \"scriptPubKey\" : { (json object)\n" | " \"scriptPubKey\" : { (json object)\n" | ||||
" \"asm\" : \"asm\", (string) the asm\n" | " \"asm\" : \"asm\", (string) the asm\n" | ||||
" \"hex\" : \"hex\", (string) the hex\n" | " \"hex\" : \"hex\", (string) the hex\n" | ||||
" \"reqSigs\" : n, (numeric) The required sigs\n" | " \"reqSigs\" : n, (numeric) The required " | ||||
"sigs\n" | |||||
" \"type\" : \"pubkeyhash\", (string) The type, eg " | " \"type\" : \"pubkeyhash\", (string) The type, eg " | ||||
"'pubkeyhash'\n" | "'pubkeyhash'\n" | ||||
" \"addresses\" : [ (json array of string)\n" | " \"addresses\" : [ (json array of string)\n" | ||||
" \"12tvKAXCxZjSmdNbao16dKXC8tRWfcF5oc\" (string) " | " \"12tvKAXCxZjSmdNbao16dKXC8tRWfcF5oc\" (string) " | ||||
"bitcoin address\n" | "bitcoin address\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ]\n" | " ]\n" | ||||
" }\n" | " }\n" | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ],\n" | " ],\n" | ||||
"}\n" | "}\n"}, | ||||
RPCExamples{ | |||||
"\nExamples:\n" + | |||||
HelpExampleCli("decoderawtransaction", "\"hexstring\"") + | HelpExampleCli("decoderawtransaction", "\"hexstring\"") + | ||||
HelpExampleRpc("decoderawtransaction", "\"hexstring\"")); | HelpExampleRpc("decoderawtransaction", "\"hexstring\"")}, | ||||
} | |||||
.ToString()); | |||||
} | } | ||||
RPCTypeCheck(request.params, {UniValue::VSTR}); | RPCTypeCheck(request.params, {UniValue::VSTR}); | ||||
CMutableTransaction mtx; | CMutableTransaction mtx; | ||||
if (!DecodeHexTx(mtx, request.params[0].get_str())) { | if (!DecodeHexTx(mtx, request.params[0].get_str())) { | ||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); | throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); | ||||
} | } | ||||
UniValue result(UniValue::VOBJ); | UniValue result(UniValue::VOBJ); | ||||
TxToUniv(CTransaction(std::move(mtx)), uint256(), result, false); | TxToUniv(CTransaction(std::move(mtx)), uint256(), result, false); | ||||
return result; | return result; | ||||
} | } | ||||
static UniValue decodescript(const Config &config, | static UniValue decodescript(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"decodescript", | "decodescript", | ||||
"\nDecode a hex-encoded script.\n", | "\nDecode a hex-encoded script.\n", | ||||
{ | { | ||||
{"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, | {"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, | ||||
/* default_val */ "", "the hex-encoded script"}, | /* default_val */ "", "the hex-encoded script"}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{ | ||||
"\nResult:\n" | |||||
"{\n" | "{\n" | ||||
" \"asm\":\"asm\", (string) Script public key\n" | " \"asm\":\"asm\", (string) Script public key\n" | ||||
" \"hex\":\"hex\", (string) hex-encoded public key\n" | " \"hex\":\"hex\", (string) hex-encoded public key\n" | ||||
" \"type\":\"type\", (string) The output type\n" | " \"type\":\"type\", (string) The output type\n" | ||||
" \"reqSigs\": n, (numeric) The required signatures\n" | " \"reqSigs\": n, (numeric) The required signatures\n" | ||||
" \"addresses\": [ (json array of string)\n" | " \"addresses\": [ (json array of string)\n" | ||||
" \"address\" (string) bitcoin address\n" | " \"address\" (string) bitcoin address\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ],\n" | " ],\n" | ||||
" \"p2sh\",\"address\" (string) address of P2SH script wrapping " | " \"p2sh\",\"address\" (string) address of P2SH script " | ||||
"wrapping " | |||||
"this redeem script (not returned if the script is already a " | "this redeem script (not returned if the script is already a " | ||||
"P2SH).\n" | "P2SH).\n" | ||||
"}\n" | "}\n"}, | ||||
"\nExamples:\n" + | RPCExamples{HelpExampleCli("decodescript", "\"hexstring\"") + | ||||
HelpExampleCli("decodescript", "\"hexstring\"") + | HelpExampleRpc("decodescript", "\"hexstring\"")}, | ||||
HelpExampleRpc("decodescript", "\"hexstring\"")); | } | ||||
.ToString()); | |||||
} | } | ||||
RPCTypeCheck(request.params, {UniValue::VSTR}); | RPCTypeCheck(request.params, {UniValue::VSTR}); | ||||
UniValue r(UniValue::VOBJ); | UniValue r(UniValue::VOBJ); | ||||
CScript script; | CScript script; | ||||
if (request.params[0].get_str().size() > 0) { | if (request.params[0].get_str().size() > 0) { | ||||
std::vector<uint8_t> scriptData( | std::vector<uint8_t> scriptData( | ||||
Show All 30 Lines | static void TxInErrorToJSON(const CTxIn &txin, UniValue &vErrorsRet, | ||||
entry.pushKV("sequence", uint64_t(txin.nSequence)); | entry.pushKV("sequence", uint64_t(txin.nSequence)); | ||||
entry.pushKV("error", strMessage); | entry.pushKV("error", strMessage); | ||||
vErrorsRet.push_back(entry); | vErrorsRet.push_back(entry); | ||||
} | } | ||||
static UniValue combinerawtransaction(const Config &config, | static UniValue combinerawtransaction(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"combinerawtransaction", | "combinerawtransaction", | ||||
"\nCombine multiple partially signed transactions into " | "\nCombine multiple partially signed transactions into " | ||||
"one transaction.\n" | "one transaction.\n" | ||||
"The combined transaction may be another partially " | "The combined transaction may be another partially " | ||||
"signed transaction or a \n" | "signed transaction or a \n" | ||||
"fully signed transaction.", | "fully signed transaction.", | ||||
{ | { | ||||
{ | { | ||||
"txs", | "txs", | ||||
RPCArg::Type::ARR, | RPCArg::Type::ARR, | ||||
/* opt */ false, | /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"A json array of hex strings of partially " | "A json array of hex strings of partially " | ||||
"signed transactions", | "signed transactions", | ||||
{ | { | ||||
{"hexstring", RPCArg::Type::STR_HEX, | {"hexstring", RPCArg::Type::STR_HEX, | ||||
/* opt */ false, /* default_val */ "", | /* opt */ false, /* default_val */ "", | ||||
"A transaction hash"}, | "A transaction hash"}, | ||||
}, | }, | ||||
}, | }, | ||||
}} | }, | ||||
.ToString() + | RPCResult{"\"hex\" (string) The hex-encoded raw " | ||||
"\nResult:\n" | "transaction with signature(s)\n"}, | ||||
"\"hex\" (string) The hex-encoded raw transaction with " | RPCExamples{HelpExampleCli("combinerawtransaction", | ||||
"signature(s)\n" | "[\"myhex1\", \"myhex2\", \"myhex3\"]")}, | ||||
} | |||||
"\nExamples:\n" + | .ToString()); | ||||
HelpExampleCli("combinerawtransaction", | |||||
"[\"myhex1\", \"myhex2\", \"myhex3\"]")); | |||||
} | } | ||||
UniValue txs = request.params[0].get_array(); | UniValue txs = request.params[0].get_array(); | ||||
std::vector<CMutableTransaction> txVariants(txs.size()); | std::vector<CMutableTransaction> txVariants(txs.size()); | ||||
for (unsigned int idx = 0; idx < txs.size(); idx++) { | for (unsigned int idx = 0; idx < txs.size(); idx++) { | ||||
if (!DecodeHexTx(txVariants[idx], txs[idx].get_str())) { | if (!DecodeHexTx(txVariants[idx], txs[idx].get_str())) { | ||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, | throw JSONRPCError(RPC_DESERIALIZATION_ERROR, | ||||
▲ Show 20 Lines • Show All 232 Lines • ▼ Show 20 Lines | UniValue SignTransaction(interfaces::Chain &chain, CMutableTransaction &mtx, | ||||
return result; | return result; | ||||
} | } | ||||
static UniValue signrawtransactionwithkey(const Config &config, | static UniValue signrawtransactionwithkey(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() < 2 || | if (request.fHelp || request.params.size() < 2 || | ||||
request.params.size() > 4) { | request.params.size() > 4) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"signrawtransactionwithkey", | "signrawtransactionwithkey", | ||||
"\nSign inputs for raw transaction (serialized, hex-encoded).\n" | "\nSign inputs for raw transaction (serialized, hex-encoded).\n" | ||||
"The second argument is an array of base58-encoded private\n" | "The second argument is an array of base58-encoded private\n" | ||||
"keys that will be the only keys used to sign the " | "keys that will be the only keys used to sign the " | ||||
"transaction.\n" | "transaction.\n" | ||||
"The third optional argument (may be null) is an array of " | "The third optional argument (may be null) is an array of " | ||||
"previous transaction outputs that\n" | "previous transaction outputs that\n" | ||||
"this transaction depends on but may not yet be in the block " | "this transaction depends on but may not yet be in the block " | ||||
"chain.\n", | "chain.\n", | ||||
{ | { | ||||
{"hexstring", RPCArg::Type::STR, /* opt */ false, | {"hexstring", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", "The transaction hex string"}, | /* default_val */ "", "The transaction hex string"}, | ||||
{ | { | ||||
"privkeys", | "privkeys", | ||||
RPCArg::Type::ARR, | RPCArg::Type::ARR, | ||||
/* opt */ false, | /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"A json array of base58-encoded private keys for " | "A json array of base58-encoded private keys for " | ||||
"signing", | "signing", | ||||
{ | { | ||||
{"privatekey", RPCArg::Type::STR_HEX, | {"privatekey", RPCArg::Type::STR_HEX, | ||||
/* opt */ false, /* default_val */ "", | /* opt */ false, /* default_val */ "", | ||||
"private key in base58-encoding"}, | "private key in base58-encoding"}, | ||||
}, | }, | ||||
}, | }, | ||||
{ | { | ||||
"prevtxs", | "prevtxs", | ||||
RPCArg::Type::ARR, | RPCArg::Type::ARR, | ||||
/* opt */ true, | /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"A json array of previous dependent transaction " | "A json array of previous dependent transaction " | ||||
"outputs", | "outputs", | ||||
{ | { | ||||
{ | { | ||||
"", | "", | ||||
RPCArg::Type::OBJ, | RPCArg::Type::OBJ, | ||||
/* opt */ true, | /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"", | "", | ||||
{ | { | ||||
{"txid", RPCArg::Type::STR_HEX, | {"txid", RPCArg::Type::STR_HEX, | ||||
/* opt */ false, /* default_val */ "", | /* opt */ false, /* default_val */ "", | ||||
"The transaction id"}, | "The transaction id"}, | ||||
{"vout", RPCArg::Type::NUM, /* opt */ false, | {"vout", RPCArg::Type::NUM, /* opt */ false, | ||||
/* default_val */ "", "The output number"}, | /* default_val */ "", "The output number"}, | ||||
{"scriptPubKey", RPCArg::Type::STR_HEX, | {"scriptPubKey", RPCArg::Type::STR_HEX, | ||||
/* opt */ false, /* default_val */ "", | /* opt */ false, /* default_val */ "", | ||||
"script key"}, | "script key"}, | ||||
{"redeemScript", RPCArg::Type::STR_HEX, | {"redeemScript", RPCArg::Type::STR_HEX, | ||||
/* opt */ true, /* default_val */ "", | /* opt */ true, /* default_val */ "", | ||||
"(required for P2SH or P2WSH) redeem " | "(required for P2SH or P2WSH) redeem " | ||||
"script"}, | "script"}, | ||||
{"amount", RPCArg::Type::AMOUNT, | {"amount", RPCArg::Type::AMOUNT, | ||||
/* opt */ false, /* default_val */ "", | /* opt */ false, /* default_val */ "", | ||||
"The amount spent"}, | "The amount spent"}, | ||||
}, | }, | ||||
}, | }, | ||||
}, | }, | ||||
}, | }, | ||||
{"sighashtype", RPCArg::Type::STR, /* opt */ true, | {"sighashtype", RPCArg::Type::STR, /* opt */ true, | ||||
/* default_val */ "ALL|FORKID", | /* default_val */ "ALL|FORKID", | ||||
"The signature hash type. Must be one of:\n" | "The signature hash type. Must be one of:\n" | ||||
" \"ALL|FORKID\"\n" | " \"ALL|FORKID\"\n" | ||||
" \"NONE|FORKID\"\n" | " \"NONE|FORKID\"\n" | ||||
" \"SINGLE|FORKID\"\n" | " \"SINGLE|FORKID\"\n" | ||||
" \"ALL|FORKID|ANYONECANPAY\"\n" | " \"ALL|FORKID|ANYONECANPAY\"\n" | ||||
" \"NONE|FORKID|ANYONECANPAY\"\n" | " \"NONE|FORKID|ANYONECANPAY\"\n" | ||||
" \"SINGLE|FORKID|ANYONECANPAY\"\n"}, | " \"SINGLE|FORKID|ANYONECANPAY\"\n"}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{ | ||||
"\nResult:\n" | |||||
"{\n" | "{\n" | ||||
" \"hex\" : \"value\", (string) The hex-encoded " | " \"hex\" : \"value\", (string) The " | ||||
"hex-encoded " | |||||
"raw transaction with signature(s)\n" | "raw transaction with signature(s)\n" | ||||
" \"complete\" : true|false, (boolean) If the " | " \"complete\" : true|false, (boolean) If the " | ||||
"transaction has a complete set of signatures\n" | "transaction has a complete set of signatures\n" | ||||
" \"errors\" : [ (json array of objects) " | " \"errors\" : [ (json array of objects) " | ||||
"Script verification errors (if there are any)\n" | "Script verification errors (if there are any)\n" | ||||
" {\n" | " {\n" | ||||
" \"txid\" : \"hash\", (string) The hash of the " | " \"txid\" : \"hash\", (string) The hash of " | ||||
"the " | |||||
"referenced, previous transaction\n" | "referenced, previous transaction\n" | ||||
" \"vout\" : n, (numeric) The index of the " | " \"vout\" : n, (numeric) The index of " | ||||
"the " | |||||
"output to spent and used as input\n" | "output to spent and used as input\n" | ||||
" \"scriptSig\" : \"hex\", (string) The hex-encoded " | " \"scriptSig\" : \"hex\", (string) The " | ||||
"hex-encoded " | |||||
"signature script\n" | "signature script\n" | ||||
" \"sequence\" : n, (numeric) Script sequence " | " \"sequence\" : n, (numeric) Script " | ||||
"sequence " | |||||
"number\n" | "number\n" | ||||
" \"error\" : \"text\" (string) Verification or " | " \"error\" : \"text\" (string) Verification " | ||||
"or " | |||||
"signing error related to the input\n" | "signing error related to the input\n" | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ]\n" | " ]\n" | ||||
"}\n" | "}\n"}, | ||||
RPCExamples{ | |||||
"\nExamples:\n" + | |||||
HelpExampleCli("signrawtransactionwithkey", "\"myhex\"") + | HelpExampleCli("signrawtransactionwithkey", "\"myhex\"") + | ||||
HelpExampleRpc("signrawtransactionwithkey", "\"myhex\"")); | HelpExampleRpc("signrawtransactionwithkey", "\"myhex\"")}, | ||||
} | |||||
.ToString()); | |||||
} | } | ||||
RPCTypeCheck( | RPCTypeCheck( | ||||
request.params, | request.params, | ||||
{UniValue::VSTR, UniValue::VARR, UniValue::VARR, UniValue::VSTR}, true); | {UniValue::VSTR, UniValue::VARR, UniValue::VARR, UniValue::VSTR}, true); | ||||
CMutableTransaction mtx; | CMutableTransaction mtx; | ||||
if (!DecodeHexTx(mtx, request.params[0].get_str())) { | if (!DecodeHexTx(mtx, request.params[0].get_str())) { | ||||
Show All 15 Lines | static UniValue signrawtransactionwithkey(const Config &config, | ||||
return SignTransaction(*g_rpc_interfaces->chain, mtx, request.params[2], | return SignTransaction(*g_rpc_interfaces->chain, mtx, request.params[2], | ||||
&keystore, true, request.params[3]); | &keystore, true, request.params[3]); | ||||
} | } | ||||
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(RPCHelpMan{ | ||||
RPCHelpMan{"sendrawtransaction", | "sendrawtransaction", | ||||
"\nSubmits raw transaction (serialized, hex-encoded) to " | "\nSubmits raw transaction (serialized, hex-encoded) to " | ||||
"local node and network.\n" | "local node and network.\n" | ||||
"\nAlso see createrawtransaction and " | "\nAlso see createrawtransaction and " | ||||
"signrawtransactionwithkey calls.\n", | "signrawtransactionwithkey calls.\n", | ||||
{ | { | ||||
{"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, | {"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", "The hex string of the raw transaction"}, | ||||
"The hex string of the raw transaction"}, | |||||
{"allowhighfees", RPCArg::Type::BOOL, /* opt */ true, | {"allowhighfees", RPCArg::Type::BOOL, /* opt */ true, | ||||
/* default_val */ "false", "Allow high fees"}, | /* default_val */ "false", "Allow high fees"}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{ | ||||
"\nResult:\n" | "\"hex\" (string) The transaction hash in hex\n"}, | ||||
"\"hex\" (string) The transaction hash in hex\n" | RPCExamples{ | ||||
"\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("signrawtransactionwithwallet", "\"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\"")}, | ||||
} | |||||
.ToString()); | |||||
} | } | ||||
std::promise<void> promise; | std::promise<void> promise; | ||||
RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL}); | RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL}); | ||||
// parse hex string from parameter | // parse hex string from parameter | ||||
CMutableTransaction mtx; | CMutableTransaction mtx; | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | static UniValue sendrawtransaction(const Config &config, | ||||
return txid.GetHex(); | return txid.GetHex(); | ||||
} | } | ||||
static UniValue testmempoolaccept(const Config &config, | static UniValue testmempoolaccept(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(RPCHelpMan{ | ||||
RPCHelpMan{"testmempoolaccept", | "testmempoolaccept", | ||||
"\nReturns if raw transaction (serialized, hex-encoded) " | "\nReturns if raw transaction (serialized, hex-encoded) " | ||||
"would be accepted by mempool.\n" | "would be accepted by mempool.\n" | ||||
"\nThis checks if the transaction violates the " | "\nThis checks if the transaction violates the " | ||||
"consensus or policy rules.\n" | "consensus or policy rules.\n" | ||||
"\nSee sendrawtransaction call.\n", | "\nSee sendrawtransaction call.\n", | ||||
{ | { | ||||
{ | { | ||||
"rawtxs", | "rawtxs", | ||||
RPCArg::Type::ARR, | RPCArg::Type::ARR, | ||||
/* opt */ false, | /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"An array of hex strings of raw transactions.\n" | "An array of hex strings of raw transactions.\n" | ||||
" Length " | " Length " | ||||
"must be one for now.", | "must be one for now.", | ||||
{ | { | ||||
{"rawtx", RPCArg::Type::STR_HEX, | {"rawtx", RPCArg::Type::STR_HEX, | ||||
/* opt */ false, /* default_val */ "", ""}, | /* opt */ false, /* default_val */ "", ""}, | ||||
}, | }, | ||||
}, | }, | ||||
{"allowhighfees", RPCArg::Type::BOOL, /* opt */ true, | {"allowhighfees", RPCArg::Type::BOOL, /* opt */ true, | ||||
/* default_val */ "false", "Allow high fees"}, | /* default_val */ "false", "Allow high fees"}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{ | ||||
"\nResult:\n" | "[ (array) The result of the mempool " | ||||
"[ (array) The result of the mempool acceptance " | "acceptance test for each raw transaction in the input array.\n" | ||||
"test for each raw transaction in the input array.\n" | |||||
" Length is exactly one for now.\n" | " Length is exactly one for now.\n" | ||||
" {\n" | " {\n" | ||||
" \"txid\" (string) The transaction hash in hex\n" | " \"txid\" (string) The transaction hash in hex\n" | ||||
" \"allowed\" (boolean) If the mempool allows this tx to " | " \"allowed\" (boolean) If the mempool allows this tx " | ||||
"to " | |||||
"be inserted\n" | "be inserted\n" | ||||
" \"reject-reason\" (string) Rejection string (only present when " | " \"reject-reason\" (string) Rejection string (only present " | ||||
"when " | |||||
"'allowed' is false)\n" | "'allowed' is false)\n" | ||||
" }\n" | " }\n" | ||||
"]\n" | "]\n"}, | ||||
"\nExamples:\n" | RPCExamples{ | ||||
"\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("signrawtransactionwithwallet", "\"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\"]")}, | ||||
} | |||||
.ToString()); | |||||
} | } | ||||
RPCTypeCheck(request.params, {UniValue::VARR, UniValue::VBOOL}); | RPCTypeCheck(request.params, {UniValue::VARR, UniValue::VBOOL}); | ||||
if (request.params[0].get_array().size() != 1) { | if (request.params[0].get_array().size() != 1) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_INVALID_PARAMETER, | RPC_INVALID_PARAMETER, | ||||
"Array must contain exactly one raw transaction for now"); | "Array must contain exactly one raw transaction for now"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | for (uint32_t num : keypath) { | ||||
} | } | ||||
} | } | ||||
return keypath_str; | return keypath_str; | ||||
} | } | ||||
static UniValue decodepsbt(const Config &config, | static UniValue decodepsbt(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"decodepsbt", | "decodepsbt", | ||||
"\nReturn a JSON object representing the serialized, " | "\nReturn a JSON object representing the serialized, " | ||||
"base64-encoded partially signed Bitcoin transaction.\n", | "base64-encoded partially signed Bitcoin transaction.\n", | ||||
{ | { | ||||
{"psbt", RPCArg::Type::STR, /* opt */ false, | {"psbt", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", "The PSBT base64 string"}, | /* default_val */ "", "The PSBT base64 string"}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{ | ||||
"\nResult:\n" | |||||
"{\n" | "{\n" | ||||
" \"tx\" : { (json object) The decoded " | " \"tx\" : { (json object) The decoded " | ||||
"network-serialized unsigned transaction.\n" | "network-serialized unsigned transaction.\n" | ||||
" ... The layout is the " | " ... The layout is " | ||||
"the " | |||||
"same as the output of decoderawtransaction.\n" | "same as the output of decoderawtransaction.\n" | ||||
" },\n" | " },\n" | ||||
" \"unknown\" : { (json object) The unknown global " | " \"unknown\" : { (json object) The unknown " | ||||
"global " | |||||
"fields\n" | "fields\n" | ||||
" \"key\" : \"value\" (key-value pair) An unknown " | " \"key\" : \"value\" (key-value pair) An " | ||||
"unknown " | |||||
"key-value pair\n" | "key-value pair\n" | ||||
" ...\n" | " ...\n" | ||||
" },\n" | " },\n" | ||||
" \"inputs\" : [ (array of json objects)\n" | " \"inputs\" : [ (array of json objects)\n" | ||||
" {\n" | " {\n" | ||||
" \"utxo\" : { (json object, optional) Transaction " | " \"utxo\" : { (json object, optional) " | ||||
"Transaction " | |||||
"output for UTXOs\n" | "output for UTXOs\n" | ||||
" \"amount\" : x.xxx, (numeric) The value in " + | " \"amount\" : x.xxx, (numeric) The value " | ||||
"in " + | |||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
"\n" | "\n" | ||||
" \"scriptPubKey\" : { (json object)\n" | " \"scriptPubKey\" : { (json object)\n" | ||||
" \"asm\" : \"asm\", (string) The asm\n" | " \"asm\" : \"asm\", (string) The asm\n" | ||||
" \"hex\" : \"hex\", (string) The hex\n" | " \"hex\" : \"hex\", (string) The hex\n" | ||||
" \"type\" : \"pubkeyhash\", (string) The type, eg " | " \"type\" : \"pubkeyhash\", (string) The type, eg " | ||||
"'pubkeyhash'\n" | "'pubkeyhash'\n" | ||||
" \"address\" : \"address\" (string) Bitcoin address " | " \"address\" : \"address\" (string) Bitcoin " | ||||
"address " | |||||
"if there is one\n" | "if there is one\n" | ||||
" }\n" | " }\n" | ||||
" },\n" | " },\n" | ||||
" \"partial_signatures\" : { (json object, " | " \"partial_signatures\" : { (json object, " | ||||
"optional)\n" | "optional)\n" | ||||
" \"pubkey\" : \"signature\", (string) The public " | " \"pubkey\" : \"signature\", (string) The " | ||||
"public " | |||||
"key and signature that corresponds to it.\n" | "key and signature that corresponds to it.\n" | ||||
" ,...\n" | " ,...\n" | ||||
" }\n" | " }\n" | ||||
" \"sighash\" : \"type\", (string, optional) " | " \"sighash\" : \"type\", (string, " | ||||
"optional) " | |||||
"The sighash type to be used\n" | "The sighash type to be used\n" | ||||
" \"redeem_script\" : { (json object, optional)\n" | " \"redeem_script\" : { (json object, optional)\n" | ||||
" \"asm\" : \"asm\", (string) The asm\n" | " \"asm\" : \"asm\", (string) The asm\n" | ||||
" \"hex\" : \"hex\", (string) The hex\n" | " \"hex\" : \"hex\", (string) The hex\n" | ||||
" \"type\" : \"pubkeyhash\", (string) The type, eg " | " \"type\" : \"pubkeyhash\", (string) The type, eg " | ||||
"'pubkeyhash'\n" | "'pubkeyhash'\n" | ||||
" }\n" | " }\n" | ||||
" \"bip32_derivs\" : { (json object, optional)\n" | " \"bip32_derivs\" : { (json object, optional)\n" | ||||
" \"pubkey\" : { (json object, " | " \"pubkey\" : { (json object, " | ||||
"optional) The public key with the derivation path as the value.\n" | "optional) The public key with the derivation path as the " | ||||
" \"master_fingerprint\" : \"fingerprint\" (string) " | "value.\n" | ||||
" \"master_fingerprint\" : \"fingerprint\" " | |||||
"(string) " | |||||
"The fingerprint of the master key\n" | "The fingerprint of the master key\n" | ||||
" \"path\" : \"path\", (string) " | " \"path\" : \"path\", " | ||||
"(string) " | |||||
"The path\n" | "The path\n" | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
" }\n" | " }\n" | ||||
" \"final_scriptsig\" : { (json object, optional)\n" | " \"final_scriptsig\" : { (json object, optional)\n" | ||||
" \"asm\" : \"asm\", (string) The asm\n" | " \"asm\" : \"asm\", (string) The asm\n" | ||||
" \"hex\" : \"hex\", (string) The hex\n" | " \"hex\" : \"hex\", (string) The hex\n" | ||||
" }\n" | " }\n" | ||||
" \"unknown\" : { (json object) The unknown " | " \"unknown\" : { (json object) The " | ||||
"unknown " | |||||
"global fields\n" | "global fields\n" | ||||
" \"key\" : \"value\" (key-value pair) An " | " \"key\" : \"value\" (key-value pair) An " | ||||
"unknown key-value pair\n" | "unknown key-value pair\n" | ||||
" ...\n" | " ...\n" | ||||
" },\n" | " },\n" | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ]\n" | " ]\n" | ||||
" \"outputs\" : [ (array of json objects)\n" | " \"outputs\" : [ (array of json objects)\n" | ||||
" {\n" | " {\n" | ||||
" \"redeem_script\" : { (json object, optional)\n" | " \"redeem_script\" : { (json object, optional)\n" | ||||
" \"asm\" : \"asm\", (string) The asm\n" | " \"asm\" : \"asm\", (string) The asm\n" | ||||
" \"hex\" : \"hex\", (string) The hex\n" | " \"hex\" : \"hex\", (string) The hex\n" | ||||
" \"type\" : \"pubkeyhash\", (string) The type, eg " | " \"type\" : \"pubkeyhash\", (string) The type, eg " | ||||
"'pubkeyhash'\n" | "'pubkeyhash'\n" | ||||
" }\n" | " }\n" | ||||
" \"bip32_derivs\" : [ (array of json objects, " | " \"bip32_derivs\" : [ (array of json objects, " | ||||
"optional)\n" | "optional)\n" | ||||
" {\n" | " {\n" | ||||
" \"pubkey\" : \"pubkey\", (string) " | " \"pubkey\" : \"pubkey\", " | ||||
"(string) " | |||||
"The public key this path corresponds to\n" | "The public key this path corresponds to\n" | ||||
" \"master_fingerprint\" : \"fingerprint\" (string) " | " \"master_fingerprint\" : \"fingerprint\" " | ||||
"(string) " | |||||
"The fingerprint of the master key\n" | "The fingerprint of the master key\n" | ||||
" \"path\" : \"path\", (string) " | " \"path\" : \"path\", " | ||||
"(string) " | |||||
"The path\n" | "The path\n" | ||||
" }\n" | " }\n" | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ],\n" | " ],\n" | ||||
" \"unknown\" : { (json object) The unknown " | " \"unknown\" : { (json object) The " | ||||
"unknown " | |||||
"global fields\n" | "global fields\n" | ||||
" \"key\" : \"value\" (key-value pair) An " | " \"key\" : \"value\" (key-value pair) An " | ||||
"unknown key-value pair\n" | "unknown key-value pair\n" | ||||
" ...\n" | " ...\n" | ||||
" },\n" | " },\n" | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ]\n" | " ]\n" | ||||
" \"fee\" : fee (numeric, optional) The " | " \"fee\" : fee (numeric, optional) The " | ||||
"transaction fee paid if all UTXOs slots in the PSBT have been " | "transaction fee paid if all UTXOs slots in the PSBT have been " | ||||
"filled.\n" | "filled.\n" | ||||
"}\n" | "}\n"}, | ||||
RPCExamples{HelpExampleCli("decodepsbt", "\"psbt\"")}, | |||||
"\nExamples:\n" + | } | ||||
HelpExampleCli("decodepsbt", "\"psbt\"")); | .ToString()); | ||||
} | } | ||||
RPCTypeCheck(request.params, {UniValue::VSTR}); | RPCTypeCheck(request.params, {UniValue::VSTR}); | ||||
// Unserialize the transactions | // Unserialize the transactions | ||||
PartiallySignedTransaction psbtx; | PartiallySignedTransaction psbtx; | ||||
std::string error; | std::string error; | ||||
if (!DecodePSBT(psbtx, request.params[0].get_str(), error)) { | if (!DecodePSBT(psbtx, request.params[0].get_str(), error)) { | ||||
▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | static UniValue decodepsbt(const Config &config, | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
static UniValue combinepsbt(const Config &config, | static UniValue combinepsbt(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"combinepsbt", | "combinepsbt", | ||||
"\nCombine multiple partially signed Bitcoin transactions into " | "\nCombine multiple partially signed Bitcoin transactions into " | ||||
"one transaction.\n" | "one transaction.\n" | ||||
"Implements the Combiner role.\n", | "Implements the Combiner role.\n", | ||||
{ | { | ||||
{ | { | ||||
"txs", | "txs", | ||||
RPCArg::Type::ARR, | RPCArg::Type::ARR, | ||||
/* opt */ false, | /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"A json array of base64 strings of partially signed " | "A json array of base64 strings of partially signed " | ||||
"transactions", | "transactions", | ||||
{ | { | ||||
{"psbt", RPCArg::Type::STR, /* opt */ false, | {"psbt", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", "A base64 string of a PSBT"}, | /* default_val */ "", "A base64 string of a PSBT"}, | ||||
}, | }, | ||||
}, | }, | ||||
}} | }, | ||||
.ToString() + | RPCResult{" \"psbt\" (string) The base64-encoded " | ||||
"\nResult:\n" | "partially signed transaction\n"}, | ||||
" \"psbt\" (string) The base64-encoded partially signed " | RPCExamples{HelpExampleCli( | ||||
"transaction\n" | "combinepsbt", | ||||
"\nExamples:\n" + | "[\"mybase64_1\", \"mybase64_2\", \"mybase64_3\"]")}, | ||||
HelpExampleCli("combinepsbt", | } | ||||
"[\"mybase64_1\", \"mybase64_2\", \"mybase64_3\"]")); | .ToString()); | ||||
} | } | ||||
RPCTypeCheck(request.params, {UniValue::VARR}, true); | RPCTypeCheck(request.params, {UniValue::VARR}, true); | ||||
// Unserialize the transactions | // Unserialize the transactions | ||||
std::vector<PartiallySignedTransaction> psbtxs; | std::vector<PartiallySignedTransaction> psbtxs; | ||||
UniValue txs = request.params[0].get_array(); | UniValue txs = request.params[0].get_array(); | ||||
for (size_t i = 0; i < txs.size(); ++i) { | for (size_t i = 0; i < txs.size(); ++i) { | ||||
Show All 27 Lines | static UniValue combinepsbt(const Config &config, | ||||
ssTx << merged_psbt; | ssTx << merged_psbt; | ||||
return EncodeBase64((uint8_t *)ssTx.data(), ssTx.size()); | return EncodeBase64((uint8_t *)ssTx.data(), ssTx.size()); | ||||
} | } | ||||
static UniValue finalizepsbt(const Config &config, | static UniValue finalizepsbt(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(RPCHelpMan{ | ||||
RPCHelpMan{"finalizepsbt", | "finalizepsbt", | ||||
"Finalize the inputs of a PSBT. If the transaction is " | "Finalize the inputs of a PSBT. If the transaction is " | ||||
"fully signed, it will produce a\n" | "fully signed, it will produce a\n" | ||||
"network serialized transaction which can be broadcast " | "network serialized transaction which can be broadcast " | ||||
"with sendrawtransaction. Otherwise a PSBT will be\n" | "with sendrawtransaction. Otherwise a PSBT will be\n" | ||||
"created which has the final_scriptSigfields filled for " | "created which has the final_scriptSigfields filled for " | ||||
"inputs that are complete.\n" | "inputs that are complete.\n" | ||||
"Implements the Finalizer and Extractor roles.\n", | "Implements the Finalizer and Extractor roles.\n", | ||||
{ | { | ||||
{"psbt", RPCArg::Type::STR, /* opt */ false, | {"psbt", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", "A base64 string of a PSBT"}, | /* default_val */ "", "A base64 string of a PSBT"}, | ||||
{"extract", RPCArg::Type::BOOL, /* opt */ true, | {"extract", RPCArg::Type::BOOL, /* opt */ true, | ||||
/* default_val */ "true", | /* default_val */ "true", | ||||
"If true and the transaction is complete,\n" | "If true and the transaction is complete,\n" | ||||
" extract and return " | " extract and return " | ||||
"the complete transaction in normal network " | "the complete transaction in normal network " | ||||
"serialization instead of the PSBT."}, | "serialization instead of the PSBT."}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{ | ||||
"\nResult:\n" | |||||
"{\n" | "{\n" | ||||
" \"psbt\" : \"value\", (string) The base64-encoded " | " \"psbt\" : \"value\", (string) The base64-encoded " | ||||
"partially signed transaction if not extracted\n" | "partially signed transaction if not extracted\n" | ||||
" \"hex\" : \"value\", (string) The hex-encoded network " | " \"hex\" : \"value\", (string) The hex-encoded " | ||||
"network " | |||||
"transaction if extracted\n" | "transaction if extracted\n" | ||||
" \"complete\" : true|false, (boolean) If the transaction has a " | " \"complete\" : true|false, (boolean) If the transaction " | ||||
"has a " | |||||
"complete set of signatures\n" | "complete set of signatures\n" | ||||
" ]\n" | " ]\n" | ||||
"}\n" | "}\n"}, | ||||
RPCExamples{HelpExampleCli("finalizepsbt", "\"psbt\"")}, | |||||
"\nExamples:\n" + | } | ||||
HelpExampleCli("finalizepsbt", "\"psbt\"")); | .ToString()); | ||||
} | } | ||||
RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL}, true); | RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL}, true); | ||||
// Unserialize the transactions | // Unserialize the transactions | ||||
PartiallySignedTransaction psbtx; | PartiallySignedTransaction psbtx; | ||||
std::string error; | std::string error; | ||||
if (!DecodePSBT(psbtx, request.params[0].get_str(), error)) { | if (!DecodePSBT(psbtx, request.params[0].get_str(), error)) { | ||||
Show All 30 Lines | static UniValue finalizepsbt(const Config &config, | ||||
return result; | return result; | ||||
} | } | ||||
static UniValue createpsbt(const Config &config, | static UniValue createpsbt(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() < 2 || | if (request.fHelp || request.params.size() < 2 || | ||||
request.params.size() > 3) { | request.params.size() > 3) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"createpsbt", | "createpsbt", | ||||
"\nCreates a transaction in the Partially Signed " | "\nCreates a transaction in the Partially Signed " | ||||
"Transaction format.\n" | "Transaction format.\n" | ||||
"Implements the Creator role.\n", | "Implements the Creator role.\n", | ||||
{ | { | ||||
{ | { | ||||
"inputs", | "inputs", | ||||
RPCArg::Type::ARR, | RPCArg::Type::ARR, | ||||
/* opt */ false, | /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"A json array of json objects", | "A json array of json objects", | ||||
{ | { | ||||
{ | { | ||||
"", | "", | ||||
RPCArg::Type::OBJ, | RPCArg::Type::OBJ, | ||||
/* opt */ false, | /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"", | "", | ||||
{ | { | ||||
{"txid", RPCArg::Type::STR_HEX, | {"txid", RPCArg::Type::STR_HEX, | ||||
/* opt */ false, /* default_val */ "", | /* opt */ false, /* default_val */ "", | ||||
"The transaction id"}, | "The transaction id"}, | ||||
{"vout", RPCArg::Type::NUM, /* opt */ false, | {"vout", RPCArg::Type::NUM, /* opt */ false, | ||||
/* default_val */ "", "The output number"}, | /* default_val */ "", "The output number"}, | ||||
{"sequence", RPCArg::Type::NUM, | {"sequence", RPCArg::Type::NUM, | ||||
/* opt */ true, /* default_val */ "", | /* opt */ true, /* default_val */ "", | ||||
"The sequence number"}, | "The sequence number"}, | ||||
}, | }, | ||||
}, | }, | ||||
}, | }, | ||||
}, | }, | ||||
{ | { | ||||
"outputs", | "outputs", | ||||
RPCArg::Type::ARR, | RPCArg::Type::ARR, | ||||
/* opt */ false, | /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"a json array with outputs (key-value pairs).\n" | "a json array with outputs (key-value pairs).\n" | ||||
"For compatibility reasons, a dictionary, which holds " | "For compatibility reasons, a dictionary, which holds " | ||||
"the key-value pairs directly, is also\n" | "the key-value pairs directly, is also\n" | ||||
" accepted as second " | " accepted as second " | ||||
"parameter.", | "parameter.", | ||||
{ | { | ||||
{ | { | ||||
"", | "", | ||||
RPCArg::Type::OBJ, | RPCArg::Type::OBJ, | ||||
/* opt */ true, | /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"", | "", | ||||
{ | { | ||||
{"address", RPCArg::Type::AMOUNT, | {"address", RPCArg::Type::AMOUNT, | ||||
/* opt */ false, /* default_val */ "", | /* opt */ false, /* default_val */ "", | ||||
"A key-value pair. The key (string) is " | "A key-value pair. The key (string) is " | ||||
"the bitcoin address, the value (float or " | "the bitcoin address, the value (float or " | ||||
"string) is the amount in " + | "string) is the amount in " + | ||||
CURRENCY_UNIT}, | CURRENCY_UNIT}, | ||||
}, | }, | ||||
}, | }, | ||||
{ | { | ||||
"", | "", | ||||
RPCArg::Type::OBJ, | RPCArg::Type::OBJ, | ||||
/* opt */ true, | /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"", | "", | ||||
{ | { | ||||
{"data", RPCArg::Type::STR_HEX, | {"data", RPCArg::Type::STR_HEX, | ||||
/* opt */ false, /* default_val */ "", | /* opt */ false, /* default_val */ "", | ||||
"A key-value pair. The key must be " | "A key-value pair. The key must be " | ||||
"\"data\", the value is hex-encoded data"}, | "\"data\", the value is hex-encoded data"}, | ||||
}, | }, | ||||
}, | }, | ||||
}, | }, | ||||
}, | }, | ||||
{"locktime", RPCArg::Type::NUM, /* opt */ true, | {"locktime", RPCArg::Type::NUM, /* opt */ true, | ||||
/* default_val */ "0", | /* default_val */ "0", | ||||
"Raw locktime. Non-0 value also locktime-activates " | "Raw locktime. Non-0 value also locktime-activates " | ||||
"inputs"}, | "inputs"}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{" \"psbt\" (string) The resulting raw " | ||||
"\nResult:\n" | "transaction (base64-encoded string)\n"}, | ||||
" \"psbt\" (string) The resulting raw transaction " | RPCExamples{HelpExampleCli( | ||||
"(base64-encoded string)\n" | "createpsbt", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]" | ||||
"\nExamples:\n" + | "\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"")}, | ||||
HelpExampleCli("createpsbt", | } | ||||
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" " | .ToString()); | ||||
"\"[{\\\"data\\\":\\\"00010203\\\"}]\"")); | |||||
} | } | ||||
RPCTypeCheck(request.params, | RPCTypeCheck(request.params, | ||||
{ | { | ||||
UniValue::VARR, | UniValue::VARR, | ||||
UniValueType(), // ARR or OBJ, checked later | UniValueType(), // ARR or OBJ, checked later | ||||
UniValue::VNUM, | UniValue::VNUM, | ||||
}, | }, | ||||
Show All 19 Lines | static UniValue createpsbt(const Config &config, | ||||
return EncodeBase64((uint8_t *)ssTx.data(), ssTx.size()); | return EncodeBase64((uint8_t *)ssTx.data(), ssTx.size()); | ||||
} | } | ||||
static UniValue converttopsbt(const Config &config, | static UniValue converttopsbt(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(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"converttopsbt", | "converttopsbt", | ||||
"\nConverts a network serialized transaction to a PSBT. " | "\nConverts a network serialized transaction to a PSBT. " | ||||
"This should be used only with createrawtransaction and " | "This should be used only with createrawtransaction and " | ||||
"fundrawtransaction\n" | "fundrawtransaction\n" | ||||
"createpsbt and walletcreatefundedpsbt should be used " | "createpsbt and walletcreatefundedpsbt should be used " | ||||
"for new applications.\n", | "for new applications.\n", | ||||
{ | { | ||||
{"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, | {"hexstring", RPCArg::Type::STR_HEX, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", "The hex string of a raw transaction"}, | ||||
"The hex string of a raw transaction"}, | |||||
{"permitsigdata", RPCArg::Type::BOOL, /* opt */ true, | {"permitsigdata", RPCArg::Type::BOOL, /* opt */ true, | ||||
/* default_val */ "false", | /* default_val */ "false", | ||||
"If true, any signatures in the input will be discarded " | "If true, any signatures in the input will be discarded " | ||||
"and conversion.\n" | "and conversion.\n" | ||||
" will continue. If false, " | " will continue. If false, " | ||||
"RPC will fail if any signatures are present."}, | "RPC will fail if any signatures are present."}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{" \"psbt\" (string) The resulting raw " | ||||
"\nResult:\n" | "transaction (base64-encoded string)\n"}, | ||||
" \"psbt\" (string) The resulting raw transaction " | RPCExamples{ | ||||
"(base64-encoded string)\n" | |||||
"\nExamples:\n" | |||||
"\nCreate a transaction\n" + | "\nCreate a transaction\n" + | ||||
HelpExampleCli("createrawtransaction", | HelpExampleCli("createrawtransaction", | ||||
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" " | "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]" | ||||
"\"[{\\\"data\\\":\\\"00010203\\\"}]\"") + | "\" \"[{\\\"data\\\":\\\"00010203\\\"}]\"") + | ||||
"\nConvert the transaction to a PSBT\n" + | "\nConvert the transaction to a PSBT\n" + | ||||
HelpExampleCli("converttopsbt", "\"rawtransaction\"")); | HelpExampleCli("converttopsbt", "\"rawtransaction\"")}, | ||||
} | |||||
.ToString()); | |||||
} | } | ||||
RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL}, true); | RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL}, true); | ||||
// parse hex string from parameter | // parse hex string from parameter | ||||
CMutableTransaction tx; | CMutableTransaction tx; | ||||
if (!DecodeHexTx(tx, request.params[0].get_str())) { | if (!DecodeHexTx(tx, request.params[0].get_str())) { | ||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); | throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); | ||||
▲ Show 20 Lines • Show All 58 Lines • Show Last 20 Lines |