Skip to content

Commit 0dcb888

Browse files
committed
Merge #9016: Return useful error message on ATMP failure
169bdab Return useful error message on ATMP failure (instagibbs)
2 parents fea5e05 + 169bdab commit 0dcb888

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

src/qt/walletmodel.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "walletmodel.h"
66

77
#include "addresstablemodel.h"
8+
#include "consensus/validation.h"
89
#include "guiconstants.h"
910
#include "guiutil.h"
1011
#include "paymentserver.h"
@@ -328,7 +329,8 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction &tran
328329
}
329330

330331
CReserveKey *keyChange = transaction.getPossibleKeyChange();
331-
if(!wallet->CommitTransaction(*newTx, *keyChange, g_connman.get()))
332+
CValidationState state;
333+
if(!wallet->CommitTransaction(*newTx, *keyChange, g_connman.get(), state))
332334
return TransactionCommitFailed;
333335

334336
CTransaction* t = (CTransaction*)newTx;

src/wallet/rpcwallet.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "amount.h"
77
#include "base58.h"
88
#include "chain.h"
9+
#include "consensus/validation.h"
910
#include "core_io.h"
1011
#include "init.h"
1112
#include "main.h"
@@ -365,8 +366,11 @@ static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtr
365366
strError = strprintf("Error: This transaction requires a transaction fee of at least %s", FormatMoney(nFeeRequired));
366367
throw JSONRPCError(RPC_WALLET_ERROR, strError);
367368
}
368-
if (!pwalletMain->CommitTransaction(wtxNew, reservekey, g_connman.get()))
369-
throw JSONRPCError(RPC_WALLET_ERROR, "Error: The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of the wallet and coins were spent in the copy but not marked as spent here.");
369+
CValidationState state;
370+
if (!pwalletMain->CommitTransaction(wtxNew, reservekey, g_connman.get(), state)) {
371+
strError = strprintf("Error: The transaction was rejected! Reason given: %s", state.GetRejectReason());
372+
throw JSONRPCError(RPC_WALLET_ERROR, strError);
373+
}
370374
}
371375

372376
UniValue sendtoaddress(const JSONRPCRequest& request)
@@ -959,8 +963,11 @@ UniValue sendmany(const JSONRPCRequest& request)
959963
bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, nChangePosRet, strFailReason);
960964
if (!fCreated)
961965
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason);
962-
if (!pwalletMain->CommitTransaction(wtx, keyChange, g_connman.get()))
963-
throw JSONRPCError(RPC_WALLET_ERROR, "Transaction commit failed");
966+
CValidationState state;
967+
if (!pwalletMain->CommitTransaction(wtx, keyChange, g_connman.get(), state)) {
968+
strFailReason = strprintf("Transaction commit failed:: %s", state.GetRejectReason());
969+
throw JSONRPCError(RPC_WALLET_ERROR, strFailReason);
970+
}
964971

965972
return wtx.GetHash().GetHex();
966973
}

src/wallet/wallet.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,8 @@ void CWallet::ReacceptWalletTransactions()
14631463
CWalletTx& wtx = *(item.second);
14641464

14651465
LOCK(mempool.cs);
1466-
wtx.AcceptToMemoryPool(maxTxFee);
1466+
CValidationState state;
1467+
wtx.AcceptToMemoryPool(maxTxFee, state);
14671468
}
14681469
}
14691470

@@ -2474,7 +2475,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
24742475
/**
24752476
* Call after CreateTransaction unless you want to abort
24762477
*/
2477-
bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CConnman* connman)
2478+
bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CConnman* connman, CValidationState& state)
24782479
{
24792480
{
24802481
LOCK2(cs_main, cs_wallet);
@@ -2502,9 +2503,9 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CCon
25022503
if (fBroadcastTransactions)
25032504
{
25042505
// Broadcast
2505-
if (!wtxNew.AcceptToMemoryPool(maxTxFee)) {
2506+
if (!wtxNew.AcceptToMemoryPool(maxTxFee, state)) {
25062507
// This must not fail. The transaction has already been signed and recorded.
2507-
LogPrintf("CommitTransaction(): Error: Transaction not valid\n");
2508+
LogPrintf("CommitTransaction(): Error: Transaction not valid, %s\n", state.GetRejectReason());
25082509
return false;
25092510
}
25102511
wtxNew.RelayWalletTransaction(connman);
@@ -3649,8 +3650,7 @@ int CMerkleTx::GetBlocksToMaturity() const
36493650
}
36503651

36513652

3652-
bool CMerkleTx::AcceptToMemoryPool(const CAmount& nAbsurdFee)
3653+
bool CMerkleTx::AcceptToMemoryPool(const CAmount& nAbsurdFee, CValidationState& state)
36533654
{
3654-
CValidationState state;
36553655
return ::AcceptToMemoryPool(mempool, state, *this, true, NULL, false, nAbsurdFee);
36563656
}

src/wallet/wallet.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class CMerkleTx : public CTransaction
215215
bool IsInMainChain() const { const CBlockIndex *pindexRet; return GetDepthInMainChain(pindexRet) > 0; }
216216
int GetBlocksToMaturity() const;
217217
/** Pass this transaction to the mempool. Fails if absolute fee exceeds absurd fee. */
218-
bool AcceptToMemoryPool(const CAmount& nAbsurdFee);
218+
bool AcceptToMemoryPool(const CAmount& nAbsurdFee, CValidationState& state);
219219
bool hashUnset() const { return (hashBlock.IsNull() || hashBlock == ABANDON_HASH); }
220220
bool isAbandoned() const { return (hashBlock == ABANDON_HASH); }
221221
void setAbandoned() { hashBlock = ABANDON_HASH; }
@@ -774,7 +774,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
774774
*/
775775
bool CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, int& nChangePosInOut,
776776
std::string& strFailReason, const CCoinControl *coinControl = NULL, bool sign = true);
777-
bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CConnman* connman);
777+
bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CConnman* connman, CValidationState& state);
778778

779779
void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& entries);
780780
bool AddAccountingEntry(const CAccountingEntry&);

0 commit comments

Comments
 (0)