Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/coinjoin/coinjoin-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1345,12 +1345,12 @@ bool CCoinJoinClientSession::PrepareDenominate(int nMinRounds, int nMaxRounds, s
++nSteps;
continue;
}
CWallet* pwallet = GetWallet(mixingWallet.GetName());
const auto pwallet = GetWallet(mixingWallet.GetName());
if (!pwallet) {
strErrorRet ="Couldn't get wallet pointer";
return false;
}
scriptDenom = keyHolderStorage.AddKey(pwallet);
scriptDenom = keyHolderStorage.AddKey(pwallet.get());
}
vecPSInOutPairsRet.emplace_back(entry, CTxOut(nDenomAmount, scriptDenom));
// step is complete
Expand Down Expand Up @@ -1434,7 +1434,7 @@ bool CCoinJoinClientSession::MakeCollateralAmounts(const CompactTallyItem& tally
return false;
}

CWallet* pwallet = GetWallet(mixingWallet.GetName());
const auto pwallet = GetWallet(mixingWallet.GetName());

if (!pwallet) {
LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::%s -- Couldn't get wallet pointer\n", __func__);
Expand Down Expand Up @@ -1607,7 +1607,7 @@ bool CCoinJoinClientSession::CreateDenominated(CAmount nBalanceToDenominate, con
return false;
}

CWallet* pwallet = GetWallet(mixingWallet.GetName());
const auto pwallet = GetWallet(mixingWallet.GetName());

if (!pwallet) {
LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::%s -- Couldn't get wallet pointer\n", __func__);
Expand Down
10 changes: 5 additions & 5 deletions src/coinjoin/coinjoin-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ void CKeyHolderStorage::ReturnAll()
}
}

CTransactionBuilderOutput::CTransactionBuilderOutput(CTransactionBuilder* pTxBuilderIn, CWallet* pwalletIn, CAmount nAmountIn) :
CTransactionBuilderOutput::CTransactionBuilderOutput(CTransactionBuilder* pTxBuilderIn, std::shared_ptr<CWallet> pwalletIn, CAmount nAmountIn) :
pTxBuilder(pTxBuilderIn),
key(pwalletIn),
key(pwalletIn.get()),
nAmount(nAmountIn)
{
assert(pTxBuilder);
Expand All @@ -105,9 +105,9 @@ bool CTransactionBuilderOutput::UpdateAmount(const CAmount nNewAmount)
return true;
}

CTransactionBuilder::CTransactionBuilder(CWallet* pwalletIn, const CompactTallyItem& tallyItemIn) :
CTransactionBuilder::CTransactionBuilder(std::shared_ptr<CWallet> pwalletIn, const CompactTallyItem& tallyItemIn) :
pwallet(pwalletIn),
dummyReserveKey(pwalletIn),
dummyReserveKey(pwalletIn.get()),
tallyItem(tallyItemIn)
{
// Generate a feerate which will be used to consider if the remainder is dust and will go into fees or not
Expand Down Expand Up @@ -139,7 +139,7 @@ CTransactionBuilder::CTransactionBuilder(CWallet* pwalletIn, const CompactTallyI
for (const auto& coin : tallyItem.vecInputCoins) {
const CScript& scriptPubKey = coin.txout.scriptPubKey;
SignatureData sigdata;
bool res = ProduceSignature(DummySignatureCreator(pwallet), scriptPubKey, sigdata);
bool res = ProduceSignature(DummySignatureCreator(pwallet.get()), scriptPubKey, sigdata);
assert(res);
UpdateTransaction(dummyTx, nIn, sigdata);
nIn++;
Expand Down
6 changes: 3 additions & 3 deletions src/coinjoin/coinjoin-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CTransactionBuilderOutput
CScript script;

public:
CTransactionBuilderOutput(CTransactionBuilder* pTxBuilderIn, CWallet* pwalletIn, CAmount nAmountIn);
CTransactionBuilderOutput(CTransactionBuilder* pTxBuilderIn, std::shared_ptr<CWallet> pwalletIn, CAmount nAmountIn);
CTransactionBuilderOutput(CTransactionBuilderOutput&&) = delete;
CTransactionBuilderOutput& operator=(CTransactionBuilderOutput&&) = delete;
/// Get the scriptPubKey of this output
Expand All @@ -76,7 +76,7 @@ class CTransactionBuilderOutput
class CTransactionBuilder
{
/// Wallet the transaction will be build for
CWallet* pwallet{nullptr};
std::shared_ptr<CWallet> pwallet;
/// See CTransactionBuilder() for initialization
CCoinControl coinControl;
/// Dummy since we anyway use tallyItem's destination as change destination in coincontrol.
Expand All @@ -99,7 +99,7 @@ class CTransactionBuilder
friend class CTransactionBuilderOutput;

public:
CTransactionBuilder(CWallet* pwalletIn, const CompactTallyItem& tallyItemIn);
CTransactionBuilder(std::shared_ptr<CWallet> pwalletIn, const CompactTallyItem& tallyItemIn);
~CTransactionBuilder();
/// Check it would be possible to add a single output with the amount nAmount. Returns true if its possible and false if not.
bool CouldAddOutput(CAmount nAmountOutput) const;
Expand Down
6 changes: 3 additions & 3 deletions src/interfaces/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ class NodeImpl : public Node
{
#ifdef ENABLE_WALLET
std::vector<std::unique_ptr<Wallet>> wallets;
for (CWalletRef wallet : GetWallets()) {
wallets.emplace_back(MakeWallet(*wallet));
for (const std::shared_ptr<CWallet>& wallet : GetWallets()) {
wallets.emplace_back(MakeWallet(wallet));
}
return wallets;
#else
Expand Down Expand Up @@ -390,7 +390,7 @@ class NodeImpl : public Node
std::unique_ptr<Handler> handleLoadWallet(LoadWalletFn fn) override
{
CHECK_WALLET(
return MakeHandler(::uiInterface.LoadWallet.connect([fn](CWallet* wallet) { fn(MakeWallet(*wallet)); })));
return MakeHandler(::uiInterface.LoadWallet.connect([fn](std::shared_ptr<CWallet> wallet) { fn(MakeWallet(wallet)); })));
}
std::unique_ptr<Handler> handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) override
{
Expand Down
5 changes: 3 additions & 2 deletions src/interfaces/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class WalletImpl : public Wallet
public:
CoinJoinImpl m_coinjoin;

WalletImpl(CWallet& wallet) : m_wallet(wallet), m_coinjoin(wallet) {}
WalletImpl(const std::shared_ptr<CWallet>& wallet) : m_shared_wallet(wallet), m_wallet(*wallet.get()), m_coinjoin(*wallet.get()) {}

void markDirty() override
{
Expand Down Expand Up @@ -518,11 +518,12 @@ class WalletImpl : public Wallet
return MakeHandler(m_wallet.NotifyWatchonlyChanged.connect(fn));
}

std::shared_ptr<CWallet> m_shared_wallet;
CWallet& m_wallet;
};

} // namespace

std::unique_ptr<Wallet> MakeWallet(CWallet& wallet) { return MakeUnique<WalletImpl>(wallet); }
std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet>& wallet) { return MakeUnique<WalletImpl>(wallet); }

} // namespace interfaces
2 changes: 1 addition & 1 deletion src/interfaces/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ struct WalletTxOut

//! Return implementation of Wallet interface. This function will be undefined
//! in builds where ENABLE_WALLET is false.
std::unique_ptr<Wallet> MakeWallet(CWallet& wallet);
std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet>& wallet);

} // namespace interfaces

Expand Down
24 changes: 12 additions & 12 deletions src/qt/test/wallettests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,22 @@ void TestGUI()
for (int i = 0; i < 5; ++i) {
test.CreateAndProcessBlock({}, GetScriptForRawPubKey(test.coinbaseKey.GetPubKey()));
}
CWallet wallet("mock", WalletDatabase::CreateMock());
AddWallet(&wallet);
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>("mock", WalletDatabase::CreateMock());
AddWallet(wallet);
bool firstRun;
wallet.LoadWallet(firstRun);
wallet->LoadWallet(firstRun);
{
LOCK(wallet.cs_wallet);
wallet.SetAddressBook(test.coinbaseKey.GetPubKey().GetID(), "", "receive");
wallet.AddKeyPubKey(test.coinbaseKey, test.coinbaseKey.GetPubKey());
LOCK(wallet->cs_wallet);
wallet->SetAddressBook(test.coinbaseKey.GetPubKey().GetID(), "", "receive");
wallet->AddKeyPubKey(test.coinbaseKey, test.coinbaseKey.GetPubKey());
}
{
LOCK(cs_main);
WalletRescanReserver reserver(&wallet);
WalletRescanReserver reserver(wallet.get());
reserver.reserve();
wallet.ScanForWalletTransactions(chainActive.Genesis(), nullptr, reserver, true);
wallet->ScanForWalletTransactions(chainActive.Genesis(), nullptr, reserver, true);
}
wallet.SetBroadcastTransactions(true);
wallet->SetBroadcastTransactions(true);

// Create widgets for sending coins and listing transactions.
SendCoinsDialog sendCoinsDialog;
Expand All @@ -149,8 +149,8 @@ void TestGUI()
// Send two transactions, and verify they are added to transaction list.
TransactionTableModel* transactionTableModel = walletModel.getTransactionTableModel();
QCOMPARE(transactionTableModel->rowCount({}), 105);
uint256 txid1 = SendCoins(wallet, sendCoinsDialog, CKeyID(), 5 * COIN);
uint256 txid2 = SendCoins(wallet, sendCoinsDialog, CKeyID(), 10 * COIN);
uint256 txid1 = SendCoins(*wallet.get(), sendCoinsDialog, CKeyID(), 5 * COIN);
uint256 txid2 = SendCoins(*wallet.get(), sendCoinsDialog, CKeyID(), 10 * COIN);
QCOMPARE(transactionTableModel->rowCount({}), 107);
QVERIFY(FindTx(*transactionTableModel, txid1).isValid());
QVERIFY(FindTx(*transactionTableModel, txid2).isValid());
Expand Down Expand Up @@ -217,7 +217,7 @@ void TestGUI()
QPushButton* removeRequestButton = receiveCoinsDialog.findChild<QPushButton*>("removeRequestButton");
removeRequestButton->click();
QCOMPARE(requestTableModel->rowCount({}), currentRowCount-1);
RemoveWallet(&wallet);
RemoveWallet(wallet);
}

}
Expand Down
6 changes: 4 additions & 2 deletions src/rpc/coinjoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
#ifdef ENABLE_WALLET
UniValue coinjoin(const JSONRPCRequest& request)
{
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get();
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
return NullUniValue;

Expand Down Expand Up @@ -143,7 +144,8 @@ UniValue getcoinjoininfo(const JSONRPCRequest& request)

obj.pushKV("queue_size", coinJoinClientQueueManager.GetQueueSize());

CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get();
if (!pwallet) {
return obj;
}
Expand Down
12 changes: 8 additions & 4 deletions src/rpc/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ void gobject_prepare_help(CWallet* const pwallet)

UniValue gobject_prepare(const JSONRPCRequest& request)
{
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get();
if (request.fHelp || (request.params.size() != 5 && request.params.size() != 6 && request.params.size() != 8))
gobject_prepare_help(pwallet);

Expand Down Expand Up @@ -244,7 +245,8 @@ void gobject_list_prepared_help(CWallet* const pwallet)

UniValue gobject_list_prepared(const JSONRPCRequest& request)
{
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get();
if (request.fHelp || (request.params.size() > 2)) {
gobject_list_prepared_help(pwallet);
}
Expand Down Expand Up @@ -570,7 +572,8 @@ void gobject_vote_many_help(CWallet* const pwallet)

UniValue gobject_vote_many(const JSONRPCRequest& request)
{
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get();
if (request.fHelp || request.params.size() != 4)
gobject_vote_many_help(pwallet);

Expand Down Expand Up @@ -624,7 +627,8 @@ void gobject_vote_alias_help(CWallet* const pwallet)

UniValue gobject_vote_alias(const JSONRPCRequest& request)
{
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get();
if (request.fHelp || request.params.size() != 5)
gobject_vote_alias_help(pwallet);

Expand Down
3 changes: 2 additions & 1 deletion src/rpc/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ void masternode_outputs_help()

UniValue masternode_outputs(const JSONRPCRequest& request)
{
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get();
if (request.fHelp)
masternode_outputs_help();

Expand Down
3 changes: 2 additions & 1 deletion src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,8 @@ UniValue signrawtransactionwithkey(const JSONRPCRequest& request)
UniValue signrawtransaction(const JSONRPCRequest& request)
{
#ifdef ENABLE_WALLET
CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get();
#endif

if (request.fHelp || request.params.size() < 1 || request.params.size() > 4)
Expand Down
21 changes: 14 additions & 7 deletions src/rpc/rpcevo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ void protx_register_submit_help(CWallet* const pwallet)
// handles register, register_prepare and register_fund in one method
UniValue protx_register(const JSONRPCRequest& request)
{
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get();
bool isExternalRegister = request.params[0].get_str() == "register";
bool isFundRegister = request.params[0].get_str() == "register_fund";
bool isPrepareRegister = request.params[0].get_str() == "register_prepare";
Expand Down Expand Up @@ -564,7 +565,8 @@ UniValue protx_register(const JSONRPCRequest& request)

UniValue protx_register_submit(const JSONRPCRequest& request)
{
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get();
if (request.fHelp || request.params.size() != 3) {
protx_register_submit_help(pwallet);
}
Expand Down Expand Up @@ -618,7 +620,8 @@ void protx_update_service_help(CWallet* const pwallet)

UniValue protx_update_service(const JSONRPCRequest& request)
{
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get();
if (request.fHelp || (request.params.size() < 4 || request.params.size() > 6))
protx_update_service_help(pwallet);

Expand Down Expand Up @@ -713,7 +716,8 @@ void protx_update_registrar_help(CWallet* const pwallet)

UniValue protx_update_registrar(const JSONRPCRequest& request)
{
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get();
if (request.fHelp || (request.params.size() != 5 && request.params.size() != 6)) {
protx_update_registrar_help(pwallet);
}
Expand Down Expand Up @@ -801,7 +805,8 @@ void protx_revoke_help(CWallet* const pwallet)

UniValue protx_revoke(const JSONRPCRequest& request)
{
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get();
if (request.fHelp || (request.params.size() < 3 || request.params.size() > 5)) {
protx_revoke_help(pwallet);
}
Expand Down Expand Up @@ -962,7 +967,8 @@ UniValue protx_list(const JSONRPCRequest& request)
}

#ifdef ENABLE_WALLET
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get();
#else
CWallet* const pwallet = nullptr;
#endif
Expand Down Expand Up @@ -1060,7 +1066,8 @@ UniValue protx_info(const JSONRPCRequest& request)
}

#ifdef ENABLE_WALLET
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get();
#else
CWallet* const pwallet = nullptr;
#endif
Expand Down
3 changes: 2 additions & 1 deletion src/ui_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#ifndef BITCOIN_UI_INTERFACE_H
#define BITCOIN_UI_INTERFACE_H

#include <memory>
#include <stdint.h>
#include <string>

Expand Down Expand Up @@ -93,7 +94,7 @@ class CClientUIInterface
boost::signals2::signal<void ()> NotifyAlertChanged;

/** A wallet has been loaded. */
boost::signals2::signal<void (CWallet* wallet)> LoadWallet;
boost::signals2::signal<void (std::shared_ptr<CWallet> wallet)> LoadWallet;

/**
* Show progress e.g. for verifychain.
Expand Down
Loading