MCPcopy Create free account
hub / github.com/ElementsProject/elements / CommitTransaction

Method CommitTransaction

src/wallet/wallet.cpp:2288–2339  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2286}
2287
2288void CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector<std::pair<std::string, std::string>> orderForm, const BlindDetails* blind_details)
2289{
2290 LOCK(cs_wallet);
2291 WalletLogPrintf("CommitTransaction:\n%s", tx->ToString()); /* Continued */
2292
2293 // Add tx to wallet, because if it has change it's also ours,
2294 // otherwise just for transaction history.
2295 AddToWallet(tx, TxStateInactive{}, [&](CWalletTx& wtx, bool new_tx) {
2296 CHECK_NONFATAL(wtx.mapValue.empty());
2297 CHECK_NONFATAL(wtx.vOrderForm.empty());
2298 wtx.mapValue = std::move(mapValue);
2299 wtx.vOrderForm = std::move(orderForm);
2300 wtx.fTimeReceivedIsTxTime = true;
2301 wtx.fFromMe = true;
2302 // ELEMENTS: Write down blinding information
2303 if (blind_details) {
2304 assert(blind_details->o_amounts.size() == wtx.tx->vout.size());
2305 assert(blind_details->o_asset_blinds.size() == wtx.tx->vout.size());
2306 assert(blind_details->o_amount_blinds.size() == wtx.tx->vout.size());
2307 for (unsigned int i = 0; i < blind_details->o_amounts.size(); i++) {
2308 wtx.SetBlindingData(i, blind_details->o_pubkeys[i], blind_details->o_amounts[i], blind_details->o_amount_blinds[i], blind_details->o_assets[i], blind_details->o_asset_blinds[i]);
2309 }
2310 }
2311 return true;
2312 });
2313
2314 // Notify that old coins are spent
2315 for (const CTxIn& txin : tx->vin) {
2316 // ELEMENTS: Pegins are not in our UTXO set.
2317 if (txin.m_is_pegin)
2318 continue;
2319
2320 CWalletTx &coin = mapWallet.at(txin.prevout.hash);
2321 coin.MarkDirty(*this);
2322 NotifyTransactionChanged(coin.GetHash(), CT_UPDATED);
2323 }
2324
2325 // Get the inserted-CWalletTx from mapWallet so that the
2326 // wtx cached mempool state is updated correctly
2327 CWalletTx& wtx = mapWallet.at(tx->GetHash());
2328
2329 if (!fBroadcastTransactions) {
2330 // Don't submit tx to the mempool
2331 return;
2332 }
2333
2334 std::string err_string;
2335 if (!SubmitTxMemoryPoolAndRelay(wtx, err_string, true)) {
2336 WalletLogPrintf("CommitTransaction(): Transaction cannot be broadcast immediately, %s\n", err_string);
2337 // TODO: if we expect the failure to be long term or permanent, instead delete wtx from the wallet and return failure.
2338 }
2339}
2340
2341DBErrors CWallet::LoadWallet()
2342{

Callers 7

CommitTransactionFunction · 0.80
commitTransactionMethod · 0.80
SendMoneyFunction · 0.80
sendFunction · 0.80
claimpeginFunction · 0.80

Calls 7

NotifyTransactionChangedFunction · 0.85
SetBlindingDataMethod · 0.80
ToStringMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
MarkDirtyMethod · 0.45
GetHashMethod · 0.45

Tested by

no test coverage detected