Skip to content

Commit 7762b97

Browse files
committed
net: Pass CConnection to wallet rather than using the global
1 parent 00591b8 commit 7762b97

File tree

10 files changed

+32
-27
lines changed

10 files changed

+32
-27
lines changed

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4228,7 +4228,7 @@ bool ProcessNewBlock(CValidationState& state, CNode* pfrom, const CBlock* pblock
42284228

42294229
// If turned on Auto Combine will scan wallet for dust to combine
42304230
if (pwalletMain->fCombineDust)
4231-
pwalletMain->AutoCombineDust();
4231+
pwalletMain->AutoCombineDust(connman);
42324232
}
42334233

42344234
LogPrintf("%s : ACCEPTED Block %ld in %ld milliseconds with size=%d\n", __func__, GetHeight(), GetTimeMillis() - nStartTime,
@@ -6258,7 +6258,7 @@ bool SendMessages(CNode* pto, CConnman& connman)
62586258
// Except during reindex, importing and IBD, when old wallet
62596259
// transactions become unconfirmed and spams other nodes.
62606260
if (!fReindex && !fImporting && !IsInitialBlockDownload()) {
6261-
GetMainSignals().Broadcast();
6261+
GetMainSignals().Broadcast(&connman);
62626262
}
62636263

62646264
//

src/masternode-budget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void CBudgetManager::SubmitFinalBudget()
213213
// Get our change address
214214
CReserveKey reservekey(pwalletMain);
215215
// Send the tx to the network. Do NOT use SwiftTx, locking might need too much time to propagate, especially for testnet
216-
const CWallet::CommitResult& res = pwalletMain->CommitTransaction(wtx, reservekey, "NO-ix");
216+
const CWallet::CommitResult& res = pwalletMain->CommitTransaction(wtx, reservekey, g_connman.get(), "NO-ix");
217217
if (res.status != CWallet::CommitStatus::OK)
218218
return;
219219
tx = (CTransaction)wtx;

src/qt/walletmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction& tran
479479
}
480480

481481
CReserveKey* keyChange = transaction.getPossibleKeyChange();
482-
const CWallet::CommitResult& res = wallet->CommitTransaction(*newTx, *keyChange, (recipients[0].useSwiftTX) ? NetMsgType::IX : NetMsgType::TX);
482+
const CWallet::CommitResult& res = wallet->CommitTransaction(*newTx, *keyChange, g_connman.get(), (recipients[0].useSwiftTX) ? NetMsgType::IX : NetMsgType::TX);
483483
if (res.status != CWallet::CommitStatus::OK) {
484484
return SendCoinsReturn(res);
485485
}

src/rpc/budget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ UniValue preparebudget(const JSONRPCRequest& request)
155155
// make our change address
156156
CReserveKey reservekey(pwalletMain);
157157
//send the tx to the network
158-
const CWallet::CommitResult& res = pwalletMain->CommitTransaction(wtx, reservekey, useIX ? NetMsgType::IX : NetMsgType::TX);
158+
const CWallet::CommitResult& res = pwalletMain->CommitTransaction(wtx, reservekey, g_connman.get(), useIX ? NetMsgType::IX : NetMsgType::TX);
159159
if (res.status != CWallet::CommitStatus::OK)
160160
throw JSONRPCError(RPC_WALLET_ERROR, res.ToString());
161161

src/validationinterface.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void RegisterValidationInterface(CValidationInterface* pwalletIn) {
2121
g_signals.UpdatedTransaction.connect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1));
2222
g_signals.SetBestChain.connect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
2323
g_signals.Inventory.connect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
24-
g_signals.Broadcast.connect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn));
24+
g_signals.Broadcast.connect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1));
2525
g_signals.BlockChecked.connect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));
2626
// XX42 g_signals.ScriptForMining.connect(boost::bind(&CValidationInterface::GetScriptForMining, pwalletIn, _1));
2727
g_signals.BlockFound.connect(boost::bind(&CValidationInterface::ResetRequestCount, pwalletIn, _1));
@@ -31,7 +31,7 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
3131
g_signals.BlockFound.disconnect(boost::bind(&CValidationInterface::ResetRequestCount, pwalletIn, _1));
3232
// XX42 g_signals.ScriptForMining.disconnect(boost::bind(&CValidationInterface::GetScriptForMining, pwalletIn, _1));
3333
g_signals.BlockChecked.disconnect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));
34-
g_signals.Broadcast.disconnect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn));
34+
g_signals.Broadcast.disconnect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1));
3535
g_signals.Inventory.disconnect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
3636
g_signals.SetBestChain.disconnect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
3737
g_signals.UpdatedTransaction.disconnect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1));

src/validationinterface.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
class CBlock;
1414
struct CBlockLocator;
1515
class CBlockIndex;
16+
class CConnman;
1617
class CReserveScript;
1718
class CTransaction;
1819
class CValidationInterface;
@@ -37,8 +38,7 @@ class CValidationInterface {
3738
virtual void SetBestChain(const CBlockLocator &locator) {}
3839
virtual bool UpdatedTransaction(const uint256 &hash) { return false;}
3940
virtual void Inventory(const uint256 &hash) {}
40-
// XX42 virtual void ResendWalletTransactions(int64_t nBestBlockTime) {}
41-
virtual void ResendWalletTransactions() {}
41+
virtual void ResendWalletTransactions(CConnman* connman) {}
4242
virtual void BlockChecked(const CBlock&, const CValidationState&) {}
4343
// XX42 virtual void GetScriptForMining(boost::shared_ptr<CReserveScript>&) {};
4444
virtual void ResetRequestCount(const uint256 &hash) {};
@@ -64,8 +64,7 @@ struct CMainSignals {
6464
/** Notifies listeners about an inventory item being seen on the network. */
6565
boost::signals2::signal<void (const uint256 &)> Inventory;
6666
/** Tells listeners to broadcast their data. */
67-
// XX42 boost::signals2::signal<void (int64_t nBestBlockTime)> Broadcast;
68-
boost::signals2::signal<void ()> Broadcast;
67+
boost::signals2::signal<void (CConnman* connman)> Broadcast;
6968
/** Notifies listeners of a block validation result */
7069
boost::signals2::signal<void (const CBlock&, const CValidationState&)> BlockChecked;
7170
/** Notifies listeners that a key for mining is required (coinbase) */

src/wallet/rpcwallet.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,9 @@ void SendMoney(const CTxDestination& address, CAmount nValue, CWalletTx& wtxNew,
940940
if (nValue > pwalletMain->GetBalance())
941941
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds");
942942

943+
if (!g_connman)
944+
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
945+
943946
std::string strError;
944947
if (pwalletMain->IsLocked()) {
945948
strError = "Error: Wallet locked, unable to create transaction!";
@@ -959,7 +962,7 @@ void SendMoney(const CTxDestination& address, CAmount nValue, CWalletTx& wtxNew,
959962
LogPrintf("SendMoney() : %s\n", strError);
960963
throw JSONRPCError(RPC_WALLET_ERROR, strError);
961964
}
962-
const CWallet::CommitResult&& res = pwalletMain->CommitTransaction(wtxNew, reservekey, (!fUseIX ? NetMsgType::TX : NetMsgType::IX));
965+
const CWallet::CommitResult&& res = pwalletMain->CommitTransaction(wtxNew, reservekey, g_connman.get(), (!fUseIX ? NetMsgType::TX : NetMsgType::IX));
963966
if (res.status != CWallet::CommitStatus::OK)
964967
throw JSONRPCError(RPC_WALLET_ERROR, res.ToString());
965968
}
@@ -1143,7 +1146,7 @@ UniValue delegatestake(const JSONRPCRequest& request)
11431146
CReserveKey reservekey(pwalletMain);
11441147
UniValue ret = CreateColdStakeDelegation(request.params, wtx, reservekey);
11451148

1146-
const CWallet::CommitResult& res = pwalletMain->CommitTransaction(wtx, reservekey, NetMsgType::TX);
1149+
const CWallet::CommitResult& res = pwalletMain->CommitTransaction(wtx, reservekey, g_connman.get(), NetMsgType::TX);
11471150
if (res.status != CWallet::CommitStatus::OK)
11481151
throw JSONRPCError(RPC_WALLET_ERROR, res.ToString());
11491152

@@ -1852,6 +1855,9 @@ UniValue sendmany(const JSONRPCRequest& request)
18521855

18531856
LOCK2(cs_main, pwalletMain->cs_wallet);
18541857

1858+
if (!g_connman)
1859+
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
1860+
18551861
if (!IsDeprecatedRPCEnabled("accounts") && !request.params[0].get_str().empty()) {
18561862
throw JSONRPCError(RPC_INVALID_PARAMETER, "Dummy value must be set to \"\"");
18571863
}
@@ -1909,7 +1915,7 @@ UniValue sendmany(const JSONRPCRequest& request)
19091915
bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, nChangePosInOut, strFailReason);
19101916
if (!fCreated)
19111917
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason);
1912-
const CWallet::CommitResult& res = pwalletMain->CommitTransaction(wtx, keyChange);
1918+
const CWallet::CommitResult& res = pwalletMain->CommitTransaction(wtx, keyChange, g_connman.get());
19131919
if (res.status != CWallet::CommitStatus::OK)
19141920
throw JSONRPCError(RPC_WALLET_ERROR, res.ToString());
19151921

src/wallet/wallet.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ bool CWalletTx::InMempool() const
16481648
return false;
16491649
}
16501650

1651-
void CWalletTx::RelayWalletTransaction(std::string strCommand)
1651+
void CWalletTx::RelayWalletTransaction(CConnman* connman, std::string strCommand)
16521652
{
16531653
LOCK(cs_main);
16541654
if (!IsCoinBase() && !IsCoinStake()) {
@@ -1733,7 +1733,7 @@ bool CWallet::Verify()
17331733

17341734

17351735

1736-
void CWallet::ResendWalletTransactions()
1736+
void CWallet::ResendWalletTransactions(CConnman* connman)
17371737
{
17381738
// Do this infrequently and randomly to avoid giving away
17391739
// that these are our transactions.
@@ -1764,7 +1764,7 @@ void CWallet::ResendWalletTransactions()
17641764
}
17651765
for (PAIRTYPE(const unsigned int, CWalletTx*) & item : mapSorted) {
17661766
CWalletTx& wtx = *item.second;
1767-
wtx.RelayWalletTransaction();
1767+
wtx.RelayWalletTransaction(connman);
17681768
}
17691769
}
17701770
}
@@ -2957,7 +2957,7 @@ std::string CWallet::CommitResult::ToString() const
29572957
/**
29582958
* Call after CreateTransaction unless you want to abort
29592959
*/
2960-
CWallet::CommitResult CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, std::string strCommand)
2960+
CWallet::CommitResult CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CConnman* connman, std::string strCommand)
29612961
{
29622962
CommitResult res;
29632963
{
@@ -3009,7 +3009,7 @@ CWallet::CommitResult CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey&
30093009
mapRequestCount[res.hashTx] = 0;
30103010

30113011
// Broadcast
3012-
wtxNew.RelayWalletTransaction(strCommand);
3012+
wtxNew.RelayWalletTransaction(connman, strCommand);
30133013
}
30143014
return res;
30153015
}
@@ -3605,7 +3605,7 @@ bool CWallet::LoadDestData(const CTxDestination& dest, const std::string& key, c
36053605
return true;
36063606
}
36073607

3608-
void CWallet::AutoCombineDust()
3608+
void CWallet::AutoCombineDust(CConnman* connman)
36093609
{
36103610
LOCK2(cs_main, cs_wallet);
36113611
const CBlockIndex* tip = chainActive.Tip();
@@ -3695,7 +3695,7 @@ void CWallet::AutoCombineDust()
36953695
if (!maxSize && nTotalRewardsValue < nAutoCombineThreshold * COIN && nFeeRet > 0)
36963696
continue;
36973697

3698-
const CWallet::CommitResult& res = CommitTransaction(wtx, keyChange);
3698+
const CWallet::CommitResult& res = CommitTransaction(wtx, keyChange, connman);
36993699
if (res.status != CWallet::CommitStatus::OK) {
37003700
LogPrintf("AutoCombineDust transaction commit failed\n");
37013701
continue;

src/wallet/wallet.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
513513

514514
int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false, bool fromStartup = false);
515515
void ReacceptWalletTransactions(bool fFirstLoad = false);
516-
void ResendWalletTransactions();
516+
void ResendWalletTransactions(CConnman* connman);
517517

518518
CAmount loopTxsBalance(std::function<void(const uint256&, const CWalletTx&, CAmount&)>method) const;
519519
CAmount GetBalance(bool fIncludeDelegated = true) const;
@@ -567,11 +567,11 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
567567
// converts CommitResult in human-readable format
568568
std::string ToString() const;
569569
};
570-
CWallet::CommitResult CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, std::string strCommand = NetMsgType::TX);
570+
CWallet::CommitResult CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CConnman* connman, std::string strCommand = NetMsgType::TX);
571571
bool AddAccountingEntry(const CAccountingEntry&, CWalletDB & pwalletdb);
572572
bool CreateCoinStake(const CKeyStore& keystore, const CBlockIndex* pindexPrev, unsigned int nBits, CMutableTransaction& txNew, int64_t& nTxNewTime);
573573
bool MultiSend();
574-
void AutoCombineDust();
574+
void AutoCombineDust(CConnman* connman);
575575

576576
static CFeeRate minTxFee;
577577
/**
@@ -992,7 +992,7 @@ class CWalletTx : public CMerkleTx
992992
int64_t GetTxTime() const;
993993
void UpdateTimeSmart();
994994
int GetRequestCount() const;
995-
void RelayWalletTransaction(std::string strCommand = NetMsgType::TX);
995+
void RelayWalletTransaction(CConnman* connman, std::string strCommand = NetMsgType::TX);
996996
std::set<uint256> GetConflicts() const;
997997
};
998998

src/wallet/wallet_zerocoin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ std::string CWallet::MintZerocoin(CAmount nValue, CWalletTx& wtxNew, std::vector
195195
}
196196

197197
//commit the transaction to the network
198-
const CWallet::CommitResult& res = CommitTransaction(wtxNew, reservekey);
198+
const CWallet::CommitResult& res = CommitTransaction(wtxNew, reservekey, g_connman.get());
199199
if (res.status != CWallet::CommitStatus::OK) {
200200
return res.ToString();
201201
} else {
@@ -398,7 +398,7 @@ bool CWallet::SpendZerocoin(CAmount nAmount, CWalletTx& wtxNew, CZerocoinSpendRe
398398

399399

400400
CWalletDB walletdb(strWalletFile);
401-
const CWallet::CommitResult& res = CommitTransaction(wtxNew, reserveKey);
401+
const CWallet::CommitResult& res = CommitTransaction(wtxNew, reserveKey, g_connman.get());
402402
if (res.status != CWallet::CommitStatus::OK) {
403403
LogPrintf("%s: failed to commit\n", __func__);
404404
nStatus = ZPIV_COMMIT_FAILED;

0 commit comments

Comments
 (0)