|
18 | 18 | #include <key_io.h> |
19 | 19 | #include <merkleblock.h> |
20 | 20 | #include <net.h> |
| 21 | +#include <node/transaction.h> |
21 | 22 | #include <policy/policy.h> |
22 | 23 | #include <primitives/transaction.h> |
23 | 24 | #include <rpc/rawtransaction.h> |
|
42 | 43 | #include <llmq/quorums_commitment.h> |
43 | 44 | #include <llmq/quorums_instantsend.h> |
44 | 45 |
|
45 | | -#include <future> |
46 | 46 | #include <stdint.h> |
47 | 47 |
|
48 | 48 | #include <univalue.h> |
@@ -1097,76 +1097,16 @@ UniValue sendrawtransaction(const JSONRPCRequest& request) |
1097 | 1097 | + HelpExampleRpc("sendrawtransaction", "\"signedhex\"") |
1098 | 1098 | ); |
1099 | 1099 |
|
1100 | | - std::promise<void> promise; |
1101 | | - |
1102 | 1100 | RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL, UniValue::VBOOL}); |
1103 | 1101 |
|
1104 | 1102 | // parse hex string from parameter |
1105 | 1103 | CMutableTransaction mtx; |
1106 | 1104 | if (!DecodeHexTx(mtx, request.params[0].get_str())) |
1107 | 1105 | throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); |
1108 | 1106 | CTransactionRef tx(MakeTransactionRef(std::move(mtx))); |
1109 | | - const uint256& hashTx = tx->GetHash(); |
1110 | | - |
1111 | | - CAmount nMaxRawTxFee = maxTxFee; |
1112 | | - if (!request.params[1].isNull() && request.params[1].get_bool()) |
1113 | | - nMaxRawTxFee = 0; |
1114 | | - |
1115 | | - bool fBypassLimits = false; |
1116 | | - if (!request.params[3].isNull()) |
1117 | | - fBypassLimits = request.params[3].get_bool(); |
1118 | | - |
1119 | | - { // cs_main scope |
1120 | | - LOCK(cs_main); |
1121 | | - CCoinsViewCache &view = *pcoinsTip; |
1122 | | - bool fHaveChain = false; |
1123 | | - for (size_t o = 0; !fHaveChain && o < tx->vout.size(); o++) { |
1124 | | - const Coin& existingCoin = view.AccessCoin(COutPoint(hashTx, o)); |
1125 | | - fHaveChain = !existingCoin.IsSpent(); |
1126 | | - } |
1127 | | - bool fHaveMempool = mempool.exists(hashTx); |
1128 | | - if (!fHaveMempool && !fHaveChain) { |
1129 | | - // push to local node and sync with wallets |
1130 | | - CValidationState state; |
1131 | | - bool fMissingInputs; |
1132 | | - if (!AcceptToMemoryPool(mempool, state, std::move(tx), &fMissingInputs, |
1133 | | - fBypassLimits /* bypass_limits */, nMaxRawTxFee)) { |
1134 | | - if (state.IsInvalid()) { |
1135 | | - throw JSONRPCError(RPC_TRANSACTION_REJECTED, FormatStateMessage(state)); |
1136 | | - } else { |
1137 | | - if (fMissingInputs) { |
1138 | | - throw JSONRPCError(RPC_TRANSACTION_ERROR, "Missing inputs"); |
1139 | | - } |
1140 | | - throw JSONRPCError(RPC_TRANSACTION_ERROR, FormatStateMessage(state)); |
1141 | | - } |
1142 | | - } else { |
1143 | | - // If wallet is enabled, ensure that the wallet has been made aware |
1144 | | - // of the new transaction prior to returning. This prevents a race |
1145 | | - // where a user might call sendrawtransaction with a transaction |
1146 | | - // to/from their wallet, immediately call some wallet RPC, and get |
1147 | | - // a stale result because callbacks have not yet been processed. |
1148 | | - CallFunctionInValidationInterfaceQueue([&promise] { |
1149 | | - promise.set_value(); |
1150 | | - }); |
1151 | | - } |
1152 | | - } else if (fHaveChain) { |
1153 | | - throw JSONRPCError(RPC_TRANSACTION_ALREADY_IN_CHAIN, "transaction already in block chain"); |
1154 | | - } else { |
1155 | | - // Make sure we don't block forever if re-sending |
1156 | | - // a transaction already in mempool. |
1157 | | - promise.set_value(); |
1158 | | - } |
1159 | | - |
1160 | | - } // cs_main |
1161 | | - |
1162 | | - promise.get_future().wait(); |
1163 | | - |
1164 | | - if(!g_connman) |
1165 | | - throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); |
1166 | | - |
1167 | | - g_connman->RelayTransaction(*tx); |
1168 | | - |
1169 | | - return hashTx.GetHex(); |
| 1107 | + bool allowhighfees = false; |
| 1108 | + if (!request.params[1].isNull()) allowhighfees = request.params[1].get_bool(); |
| 1109 | + return BroadcastTransaction(tx, allowhighfees).GetHex(); |
1170 | 1110 | } |
1171 | 1111 |
|
1172 | 1112 | static UniValue testmempoolaccept(const JSONRPCRequest& request) |
|
0 commit comments