@@ -1134,6 +1134,87 @@ UniValue sendrawtransaction(const JSONRPCRequest& request)
1134
1134
return hashTx.GetHex ();
1135
1135
}
1136
1136
1137
+ UniValue testmempoolaccept (const JSONRPCRequest& request)
1138
+ {
1139
+ if (request.fHelp || request.params .size () < 1 || request.params .size () > 2 ) {
1140
+ throw std::runtime_error (
1141
+ // clang-format off
1142
+ " testmempoolaccept [\" rawtxs\" ] ( allowhighfees )\n "
1143
+ " \n Returns if raw transaction (serialized, hex-encoded) would be accepted by mempool.\n "
1144
+ " \n This checks if the transaction violates the consensus or policy rules.\n "
1145
+ " \n See sendrawtransaction call.\n "
1146
+ " \n Arguments:\n "
1147
+ " 1. [\" rawtxs\" ] (array, required) An array of hex strings of raw transactions.\n "
1148
+ " Length must be one for now.\n "
1149
+ " 2. allowhighfees (boolean, optional, default=false) Allow high fees\n "
1150
+ " \n Result:\n "
1151
+ " [ (array) The result of the mempool acceptance test for each raw transaction in the input array.\n "
1152
+ " Length is exactly one for now.\n "
1153
+ " {\n "
1154
+ " \" txid\" (string) The transaction hash in hex\n "
1155
+ " \" allowed\" (boolean) If the mempool allows this tx to be inserted\n "
1156
+ " \" reject-reason\" (string) Rejection string (only present when 'allowed' is false)\n "
1157
+ " }\n "
1158
+ " ]\n "
1159
+ " \n Examples:\n "
1160
+ " \n Create a transaction\n "
1161
+ + HelpExampleCli (" createrawtransaction" , " \" [{\\\" txid\\\" : \\\" mytxid\\\" ,\\\" vout\\\" :0}]\" \" {\\\" myaddress\\\" :0.01}\" " ) +
1162
+ " Sign the transaction, and get back the hex\n "
1163
+ + HelpExampleCli (" signrawtransaction" , " \" myhex\" " ) +
1164
+ " \n Test acceptance of the transaction (signed hex)\n "
1165
+ + HelpExampleCli (" testmempoolaccept" , " \" signedhex\" " ) +
1166
+ " \n As a json rpc call\n "
1167
+ + HelpExampleRpc (" testmempoolaccept" , " [\" signedhex\" ]" )
1168
+ // clang-format on
1169
+ );
1170
+ }
1171
+
1172
+ ObserveSafeMode ();
1173
+
1174
+ RPCTypeCheck (request.params , {UniValue::VARR, UniValue::VBOOL});
1175
+ if (request.params [0 ].get_array ().size () != 1 ) {
1176
+ throw JSONRPCError (RPC_INVALID_PARAMETER, " Array must contain exactly one raw transaction for now" );
1177
+ }
1178
+
1179
+ CMutableTransaction mtx;
1180
+ if (!DecodeHexTx (mtx, request.params [0 ].get_array ()[0 ].get_str ())) {
1181
+ throw JSONRPCError (RPC_DESERIALIZATION_ERROR, " TX decode failed" );
1182
+ }
1183
+ CTransactionRef tx (MakeTransactionRef (std::move (mtx)));
1184
+ const uint256& tx_hash = tx->GetHash ();
1185
+
1186
+ CAmount max_raw_tx_fee = ::maxTxFee;
1187
+ if (!request.params [1 ].isNull () && request.params [1 ].get_bool ()) {
1188
+ max_raw_tx_fee = 0 ;
1189
+ }
1190
+
1191
+ UniValue result (UniValue::VARR);
1192
+ UniValue result_0 (UniValue::VOBJ);
1193
+ result_0.pushKV (" txid" , tx_hash.GetHex ());
1194
+
1195
+ CValidationState state;
1196
+ bool missing_inputs;
1197
+ bool test_accept_res;
1198
+ {
1199
+ LOCK (cs_main);
1200
+ test_accept_res = AcceptToMemoryPool (mempool, state, std::move (tx), &missing_inputs,
1201
+ nullptr /* plTxnReplaced */ , false /* bypass_limits */ , max_raw_tx_fee, /* test_accpet */ true );
1202
+ }
1203
+ result_0.pushKV (" allowed" , test_accept_res);
1204
+ if (!test_accept_res) {
1205
+ if (state.IsInvalid ()) {
1206
+ result_0.pushKV (" reject-reason" , strprintf (" %i: %s" , state.GetRejectCode (), state.GetRejectReason ()));
1207
+ } else if (missing_inputs) {
1208
+ result_0.pushKV (" reject-reason" , " missing-inputs" );
1209
+ } else {
1210
+ result_0.pushKV (" reject-reason" , state.GetRejectReason ());
1211
+ }
1212
+ }
1213
+
1214
+ result.push_back (std::move (result_0));
1215
+ return result;
1216
+ }
1217
+
1137
1218
static const CRPCCommand commands[] =
1138
1219
{ // category name actor (function) argNames
1139
1220
// --------------------- ------------------------ ----------------------- ----------
@@ -1145,6 +1226,7 @@ static const CRPCCommand commands[] =
1145
1226
{ " rawtransactions" , " combinerawtransaction" , &combinerawtransaction, {" txs" } },
1146
1227
{ " rawtransactions" , " signrawtransaction" , &signrawtransaction, {" hexstring" ," prevtxs" ," privkeys" ," sighashtype" } }, /* uses wallet if enabled */
1147
1228
{ " rawtransactions" , " signrawtransactionwithkey" , &signrawtransactionwithkey, {" hexstring" ," privkeys" ," prevtxs" ," sighashtype" } },
1229
+ { " rawtransactions" , " testmempoolaccept" , &testmempoolaccept, {" rawtxs" ," allowhighfees" } },
1148
1230
1149
1231
{ " blockchain" , " gettxoutproof" , &gettxoutproof, {" txids" , " blockhash" } },
1150
1232
{ " blockchain" , " verifytxoutproof" , &verifytxoutproof, {" proof" } },
0 commit comments