From 01699fb283485918478017331872c75817b81bdb Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sat, 5 Aug 2017 13:48:37 -0400 Subject: [PATCH] Fix resendwallettransactions assert failure if -walletbroadcast=0 --- src/wallet/rpcwallet.cpp | 5 +++++ src/wallet/wallet.cpp | 1 + src/wallet/wallet.h | 2 ++ 3 files changed, 8 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a7c229fa7..27f84bfb7 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2589,6 +2589,7 @@ UniValue resendwallettransactions(const JSONRPCRequest& request) "Immediately re-broadcast unconfirmed wallet transactions to all peers.\n" "Intended only for testing; the wallet code periodically re-broadcasts\n" "automatically.\n" + "Returns an RPC error if -walletbroadcast is set to false.\n" "Returns array of transaction ids that were re-broadcast.\n" ); @@ -2597,6 +2598,10 @@ UniValue resendwallettransactions(const JSONRPCRequest& request) LOCK2(cs_main, pwallet->cs_wallet); + if (!pwallet->GetBroadcastTransactions()) { + throw JSONRPCError(RPC_INVALID_REQUEST, "Error: Wallet transaction broadcasting is disabled with -walletbroadcast"); + } + std::vector txids = pwallet->ResendWalletTransactionsBefore(GetTime(), g_connman.get()); UniValue result(UniValue::VARR); for (const uint256& txid : txids) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index d236b1de3..18cc3bd02 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1868,6 +1868,7 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime, CCon std::vector result; LOCK(cs_wallet); + // Sort them in chronological order std::multimap mapSorted; for (std::pair& item : mapWallet) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 7ef2e6f1d..3a02d1305 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -470,6 +470,7 @@ public: int64_t GetTxTime() const; int GetRequestCount() const; + // RelayWalletTransaction may only be called if fBroadcastTransactions! bool RelayWalletTransaction(CConnman* connman); std::set GetConflicts() const; @@ -937,6 +938,7 @@ public: CBlockIndex* ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false); void ReacceptWalletTransactions(); void ResendWalletTransactions(int64_t nBestBlockTime, CConnman* connman) override; + // ResendWalletTransactionsBefore may only be called if fBroadcastTransactions! std::vector ResendWalletTransactionsBefore(int64_t nTime, CConnman* connman); CAmount GetBalance() const; CAmount GetUnconfirmedBalance() const;