Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/rawtransaction.cpp
Show First 20 Lines • Show All 981 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
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\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
RPCTypeCheck(request.params, { | RPCTypeCheck(request.params, | ||||
{ | |||||
UniValue::VSTR, | UniValue::VSTR, | ||||
// NUM or BOOL, checked later | // VNUM or VSTR, checked inside AmountFromValue() | ||||
UniValueType(), | UniValueType(), | ||||
}); | }); | ||||
// parse hex string from parameter | // parse hex string from parameter | ||||
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"); | ||||
} | } | ||||
CTransactionRef tx(MakeTransactionRef(std::move(mtx))); | CTransactionRef tx(MakeTransactionRef(std::move(mtx))); | ||||
CFeeRate max_raw_tx_fee_rate = DEFAULT_MAX_RAW_TX_FEE_RATE; | const CFeeRate max_raw_tx_fee_rate = | ||||
// TODO: temporary migration code for old clients. Remove in v0.22 | request.params[1].isNull() | ||||
if (request.params[1].isBool()) { | ? DEFAULT_MAX_RAW_TX_FEE_RATE | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | : CFeeRate(AmountFromValue(request.params[1])); | ||||
"Second argument must be numeric (maxfeerate) and " | |||||
"no longer supports a boolean. To allow a " | |||||
"transaction with high fees, set maxfeerate to 0."); | |||||
} else if (!request.params[1].isNull()) { | |||||
max_raw_tx_fee_rate = CFeeRate(AmountFromValue(request.params[1])); | |||||
} | |||||
int64_t virtual_size = GetVirtualTransactionSize(*tx); | int64_t virtual_size = GetVirtualTransactionSize(*tx); | ||||
Amount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size); | Amount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size); | ||||
std::string err_string; | std::string err_string; | ||||
AssertLockNotHeld(cs_main); | AssertLockNotHeld(cs_main); | ||||
NodeContext &node = EnsureNodeContext(request.context); | NodeContext &node = EnsureNodeContext(request.context); | ||||
const TransactionError err = BroadcastTransaction( | const TransactionError err = BroadcastTransaction( | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
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\"]")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
RPCTypeCheck(request.params, { | RPCTypeCheck(request.params, | ||||
{ | |||||
UniValue::VARR, | UniValue::VARR, | ||||
// NUM or BOOL, checked later | // VNUM or VSTR, checked inside AmountFromValue() | ||||
UniValueType(), | UniValueType(), | ||||
}); | }); | ||||
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"); | ||||
} | } | ||||
CMutableTransaction mtx; | CMutableTransaction mtx; | ||||
if (!DecodeHexTx(mtx, request.params[0].get_array()[0].get_str())) { | if (!DecodeHexTx(mtx, request.params[0].get_array()[0].get_str())) { | ||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); | throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); | ||||
} | } | ||||
CTransactionRef tx(MakeTransactionRef(std::move(mtx))); | CTransactionRef tx(MakeTransactionRef(std::move(mtx))); | ||||
const TxId &txid = tx->GetId(); | const TxId &txid = tx->GetId(); | ||||
CFeeRate max_raw_tx_fee_rate = DEFAULT_MAX_RAW_TX_FEE_RATE; | const CFeeRate max_raw_tx_fee_rate = | ||||
// TODO: temporary migration code for old clients. Remove in v0.22 | request.params[1].isNull() | ||||
if (request.params[1].isBool()) { | ? DEFAULT_MAX_RAW_TX_FEE_RATE | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | : CFeeRate(AmountFromValue(request.params[1])); | ||||
"Second argument must be numeric (maxfeerate) and " | |||||
"no longer supports a boolean. To allow a " | |||||
"transaction with high fees, set maxfeerate to 0."); | |||||
} else if (!request.params[1].isNull()) { | |||||
max_raw_tx_fee_rate = CFeeRate(AmountFromValue(request.params[1])); | |||||
} | |||||
CTxMemPool &mempool = EnsureMemPool(request.context); | CTxMemPool &mempool = EnsureMemPool(request.context); | ||||
int64_t virtual_size = GetVirtualTransactionSize(*tx); | int64_t virtual_size = GetVirtualTransactionSize(*tx); | ||||
Amount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size); | Amount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size); | ||||
UniValue result(UniValue::VARR); | UniValue result(UniValue::VARR); | ||||
UniValue result_0(UniValue::VOBJ); | UniValue result_0(UniValue::VOBJ); | ||||
result_0.pushKV("txid", txid.GetHex()); | result_0.pushKV("txid", txid.GetHex()); | ||||
▲ Show 20 Lines • Show All 1,031 Lines • ▼ Show 20 Lines | void RegisterRawTransactionRPCCommands(CRPCTable &t) { | ||||
// clang-format off | // clang-format off | ||||
static const CRPCCommand commands[] = { | static const CRPCCommand 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|maxfeerate"} }, | { "rawtransactions", "sendrawtransaction", sendrawtransaction, {"hexstring","maxfeerate"} }, | ||||
{ "rawtransactions", "combinerawtransaction", combinerawtransaction, {"txs"} }, | { "rawtransactions", "combinerawtransaction", combinerawtransaction, {"txs"} }, | ||||
{ "rawtransactions", "signrawtransactionwithkey", signrawtransactionwithkey, {"hexstring","privkeys","prevtxs","sighashtype"} }, | { "rawtransactions", "signrawtransactionwithkey", signrawtransactionwithkey, {"hexstring","privkeys","prevtxs","sighashtype"} }, | ||||
{ "rawtransactions", "testmempoolaccept", testmempoolaccept, {"rawtxs","allowhighfees|maxfeerate"} }, | { "rawtransactions", "testmempoolaccept", testmempoolaccept, {"rawtxs","maxfeerate"} }, | ||||
{ "rawtransactions", "decodepsbt", decodepsbt, {"psbt"} }, | { "rawtransactions", "decodepsbt", decodepsbt, {"psbt"} }, | ||||
{ "rawtransactions", "combinepsbt", combinepsbt, {"txs"} }, | { "rawtransactions", "combinepsbt", combinepsbt, {"txs"} }, | ||||
{ "rawtransactions", "finalizepsbt", finalizepsbt, {"psbt", "extract"} }, | { "rawtransactions", "finalizepsbt", finalizepsbt, {"psbt", "extract"} }, | ||||
{ "rawtransactions", "createpsbt", createpsbt, {"inputs","outputs","locktime"} }, | { "rawtransactions", "createpsbt", createpsbt, {"inputs","outputs","locktime"} }, | ||||
{ "rawtransactions", "converttopsbt", converttopsbt, {"hexstring","permitsigdata"} }, | { "rawtransactions", "converttopsbt", converttopsbt, {"hexstring","permitsigdata"} }, | ||||
{ "rawtransactions", "utxoupdatepsbt", utxoupdatepsbt, {"psbt", "descriptors"} }, | { "rawtransactions", "utxoupdatepsbt", utxoupdatepsbt, {"psbt", "descriptors"} }, | ||||
{ "rawtransactions", "joinpsbts", joinpsbts, {"txs"} }, | { "rawtransactions", "joinpsbts", joinpsbts, {"txs"} }, | ||||
{ "rawtransactions", "analyzepsbt", analyzepsbt, {"psbt"} }, | { "rawtransactions", "analyzepsbt", analyzepsbt, {"psbt"} }, | ||||
Show All 9 Lines |