Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/rawtransaction.cpp
Show First 20 Lines • Show All 768 Lines • ▼ Show 20 Lines | UniValue combinerawtransaction(const Config &config, | ||||
// starts as a clone of the rawtx: | // starts as a clone of the rawtx: | ||||
CMutableTransaction mergedTx(txVariants[0]); | CMutableTransaction mergedTx(txVariants[0]); | ||||
// Fetch previous transactions (inputs): | // Fetch previous transactions (inputs): | ||||
CCoinsView viewDummy; | CCoinsView viewDummy; | ||||
CCoinsViewCache view(&viewDummy); | CCoinsViewCache view(&viewDummy); | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
LOCK(mempool.cs); | LOCK(g_mempool.cs); | ||||
CCoinsViewCache &viewChain = *pcoinsTip; | CCoinsViewCache &viewChain = *pcoinsTip; | ||||
CCoinsViewMemPool viewMempool(&viewChain, mempool); | CCoinsViewMemPool viewMempool(&viewChain, g_mempool); | ||||
// temporarily switch cache backend to db+mempool view | // temporarily switch cache backend to db+mempool view | ||||
view.SetBackend(viewMempool); | view.SetBackend(viewMempool); | ||||
for (const CTxIn &txin : mergedTx.vin) { | for (const CTxIn &txin : mergedTx.vin) { | ||||
// Load entries from viewChain into view; can fail. | // Load entries from viewChain into view; can fail. | ||||
view.AccessCoin(txin.prevout); | view.AccessCoin(txin.prevout); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | #endif | ||||
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"); | ||||
} | } | ||||
// Fetch previous transactions (inputs): | // Fetch previous transactions (inputs): | ||||
CCoinsView viewDummy; | CCoinsView viewDummy; | ||||
CCoinsViewCache view(&viewDummy); | CCoinsViewCache view(&viewDummy); | ||||
{ | { | ||||
LOCK(mempool.cs); | LOCK(g_mempool.cs); | ||||
CCoinsViewCache &viewChain = *pcoinsTip; | CCoinsViewCache &viewChain = *pcoinsTip; | ||||
CCoinsViewMemPool viewMempool(&viewChain, mempool); | CCoinsViewMemPool viewMempool(&viewChain, g_mempool); | ||||
// Temporarily switch cache backend to db+mempool view. | // Temporarily switch cache backend to db+mempool view. | ||||
view.SetBackend(viewMempool); | view.SetBackend(viewMempool); | ||||
for (const CTxIn &txin : mtx.vin) { | for (const CTxIn &txin : mtx.vin) { | ||||
// Load entries from viewChain into view; can fail. | // Load entries from viewChain into view; can fail. | ||||
view.AccessCoin(txin.prevout); | view.AccessCoin(txin.prevout); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 261 Lines • ▼ Show 20 Lines | static UniValue sendrawtransaction(const Config &config, | ||||
CCoinsViewCache &view = *pcoinsTip; | CCoinsViewCache &view = *pcoinsTip; | ||||
bool fHaveChain = false; | bool fHaveChain = false; | ||||
for (size_t o = 0; !fHaveChain && o < tx->vout.size(); o++) { | for (size_t o = 0; !fHaveChain && o < tx->vout.size(); o++) { | ||||
const Coin &existingCoin = view.AccessCoin(COutPoint(txid, o)); | const Coin &existingCoin = view.AccessCoin(COutPoint(txid, o)); | ||||
fHaveChain = !existingCoin.IsSpent(); | fHaveChain = !existingCoin.IsSpent(); | ||||
} | } | ||||
bool fHaveMempool = mempool.exists(txid); | bool fHaveMempool = g_mempool.exists(txid); | ||||
if (!fHaveMempool && !fHaveChain) { | if (!fHaveMempool && !fHaveChain) { | ||||
// Push to local node and sync with wallets. | // Push to local node and sync with wallets. | ||||
CValidationState state; | CValidationState state; | ||||
bool fMissingInputs; | bool fMissingInputs; | ||||
if (!AcceptToMemoryPool(config, mempool, state, std::move(tx), | if (!AcceptToMemoryPool(config, g_mempool, state, std::move(tx), | ||||
fLimitFree, &fMissingInputs, false, | fLimitFree, &fMissingInputs, false, | ||||
nMaxRawTxFee)) { | nMaxRawTxFee)) { | ||||
if (state.IsInvalid()) { | if (state.IsInvalid()) { | ||||
throw JSONRPCError(RPC_TRANSACTION_REJECTED, | throw JSONRPCError(RPC_TRANSACTION_REJECTED, | ||||
strprintf("%i: %s", state.GetRejectCode(), | strprintf("%i: %s", state.GetRejectCode(), | ||||
state.GetRejectReason())); | state.GetRejectReason())); | ||||
} else { | } else { | ||||
if (fMissingInputs) { | if (fMissingInputs) { | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |