* Call after CreateTransaction unless you want to abort */
| 3146 | * Call after CreateTransaction unless you want to abort |
| 3147 | */ |
| 3148 | bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, std::string strCommand) |
| 3149 | { |
| 3150 | { |
| 3151 | LOCK2(cs_main, cs_wallet); |
| 3152 | # if defined(DEBUG_DUMP_STAKING_INFO)&&defined(DEBUG_DUMP_CommitTransaction) |
| 3153 | DEBUG_DUMP_CommitTransaction(); |
| 3154 | # endif |
| 3155 | { |
| 3156 | // This is only to keep the database open to defeat the auto-flush for the |
| 3157 | // duration of this scope. This is the only place where this optimization |
| 3158 | // maybe makes sense; please don't do it anywhere else. |
| 3159 | CWalletDB* pwalletdb = fFileBacked ? new CWalletDB(strWalletFile, "r") : NULL; |
| 3160 | |
| 3161 | // Take key pair from key pool so it won't be used again |
| 3162 | reservekey.KeepKey(); |
| 3163 | |
| 3164 | // Add tx to wallet, because if it has change it's also ours, |
| 3165 | // otherwise just for transaction history. |
| 3166 | AddToWallet(wtxNew); |
| 3167 | |
| 3168 | // Notify that old coins are spent |
| 3169 | set<uint256> updated_hahes; |
| 3170 | for (const CTxIn& txin : wtxNew.vin) { |
| 3171 | // notify only once |
| 3172 | if (updated_hahes.find(txin.prevout.hash) != updated_hahes.end()) continue; |
| 3173 | |
| 3174 | CWalletTx& coin = mapWallet[txin.prevout.hash]; |
| 3175 | coin.BindWallet(this); |
| 3176 | NotifyTransactionChanged(this, txin.prevout.hash, CT_UPDATED); |
| 3177 | updated_hahes.insert(txin.prevout.hash); |
| 3178 | } |
| 3179 | if (fFileBacked) |
| 3180 | delete pwalletdb; |
| 3181 | } |
| 3182 | |
| 3183 | if (fBroadcastTransactions) { |
| 3184 | // Broadcast |
| 3185 | if (!wtxNew.AcceptToMemoryPool(false)) { |
| 3186 | // This must not fail. The transaction has already been signed and recorded. |
| 3187 | LogPrintf("CommitTransaction() : Error: Transaction not valid %s\n", strCommand.c_str()); |
| 3188 | return false; |
| 3189 | } |
| 3190 | wtxNew.RelayWalletTransaction(strCommand); |
| 3191 | } |
| 3192 | } |
| 3193 | return true; |
| 3194 | } |
| 3195 | |
| 3196 | bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, bool overrideEstimatedFeeRate, int& nChangePosInOut, std::string& strFailReason, |
| 3197 | bool lockUnspents, const std::set<int>& setSubtractFeeFromOutputs, CCoinControl* coinControl) |
no test coverage detected