Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/rawtransaction.cpp
Show First 20 Lines • Show All 982 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
"\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, | ||||
// VNUM or VSTR, checked inside AmountFromValue() | // VNUM or VSTR, checked inside Amount::Amount(UniValue T) | ||||
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))); | ||||
const CFeeRate max_raw_tx_fee_rate = | const CFeeRate max_raw_tx_fee_rate = request.params[1].isNull() | ||||
request.params[1].isNull() | |||||
? DEFAULT_MAX_RAW_TX_FEE_RATE | ? DEFAULT_MAX_RAW_TX_FEE_RATE | ||||
: CFeeRate(AmountFromValue(request.params[1])); | : CFeeRate(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 67 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
"\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, | ||||
// VNUM or VSTR, checked inside AmountFromValue() | // VNUM or VSTR, checked inside Amount::Amount(UniValue T) | ||||
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(); | ||||
const CFeeRate max_raw_tx_fee_rate = | const CFeeRate max_raw_tx_fee_rate = request.params[1].isNull() | ||||
request.params[1].isNull() | |||||
? DEFAULT_MAX_RAW_TX_FEE_RATE | ? DEFAULT_MAX_RAW_TX_FEE_RATE | ||||
: CFeeRate(AmountFromValue(request.params[1])); | : CFeeRate(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,060 Lines • Show Last 20 Lines |