From 33e39f62d7289014404bb4242a68a2c700af2883 Mon Sep 17 00:00:00 2001 From: levonpetrosyan93 Date: Mon, 13 Nov 2023 06:08:36 +0400 Subject: [PATCH] RPC tests and more fixed --- src/qt/sendcoinsdialog.cpp | 12 +++++++++++- src/qt/walletmodel.cpp | 9 ++++++--- src/spark/sparkwallet.cpp | 2 +- src/wallet/wallet.cpp | 22 +++++++++++++++------- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 938b0ff716..5480410cbd 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -162,6 +162,15 @@ void SendCoinsDialog::setModel(WalletModel *_model) std::pair sparkBalance = _model->getSparkBalance(); privateBalance = spark::IsSparkAllowed() ? sparkBalance : privateBalance; + if (model->getWallet()) { + auto allowed = lelantus::IsLelantusAllowed() || (spark::IsSparkAllowed() && model->getWallet()->sparkWallet); + setAnonymizeMode(allowed); + + if (!allowed) { + ui->switchFundButton->setEnabled(false); + } + } + setBalance( _model->getBalance(), _model->getUnconfirmedBalance(), _model->getImmatureBalance(), _model->getWatchBalance(), _model->getWatchUnconfirmedBalance(), _model->getWatchImmatureBalance(), @@ -628,7 +637,8 @@ void SendCoinsDialog::updateBlocks(int count, const QDateTime& blockDate, double return; } - auto allowed = lelantus::IsLelantusAllowed() || spark::IsSparkAllowed(); + auto allowed = lelantus::IsLelantusAllowed() || (spark::IsSparkAllowed() && model->getWallet() && model->getWallet()->sparkWallet); + if (allowed && !ui->switchFundButton->isEnabled()) { diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 30df13d4da..d9951cfc1f 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -1399,10 +1399,13 @@ std::pair WalletModel::getSparkBalance() bool WalletModel::getAvailableLelantusCoins() { + if (!pwalletMain->zwallet) + return false; + std::list coins = wallet->GetAvailableLelantusCoins(); - if(coins.size() > 0) { + if (coins.size() > 0) { return true; - }else{ + } else { return false; } } @@ -1411,7 +1414,7 @@ bool WalletModel::migrateLelantusToSpark() { std::string strFailReason; bool res = wallet->LelantusToSpark(strFailReason); - if(!res) { + if (!res) { Q_EMIT message(tr("Lelantus To Spark"), QString::fromStdString(strFailReason), CClientUIInterface::MSG_ERROR); } diff --git a/src/spark/sparkwallet.cpp b/src/spark/sparkwallet.cpp index 7f5fd842f0..01c632c813 100644 --- a/src/spark/sparkwallet.cpp +++ b/src/spark/sparkwallet.cpp @@ -1089,7 +1089,7 @@ bool CSparkWallet::CreateSparkMintTransactions( while (i < tx.vout.size()) { if (tx.vout[i].scriptPubKey.IsSparkMint()) { tx.vout[i] = txout; - CWalletDB walletdb(strWalletFile); + CWalletDB walletdb(pwalletMain->strWalletFile); CSparkOutputTx output; output.address = recipient.address; output.amount = recipient.nAmount; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index b0751f08e9..a86adce8bb 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -7166,13 +7166,13 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile) // if it is first run, we need to generate the full key set for spark, if not we are loading spark wallet from db walletInstance->sparkWallet = std::make_unique(pwalletMain->strWalletFile); - } - spark::Address address = walletInstance->sparkWallet->getDefaultAddress(); - unsigned char network = spark::GetNetworkType(); - if (!walletInstance->SetSparkAddressBook(address.encode(network), "", "receive")) { - InitError(_("Cannot write default spark address") += "\n"); - return NULL; + spark::Address address = walletInstance->sparkWallet->getDefaultAddress(); + unsigned char network = spark::GetNetworkType(); + if (!walletInstance->SetSparkAddressBook(address.encode(network), "", "receive")) { + InitError(_("Cannot write default spark address") += "\n"); + return NULL; + } } walletInstance->bip47wallet = std::make_shared(walletInstance->vchDefaultKey.GetHash()); @@ -7826,7 +7826,7 @@ void CWallet::HandleBip47Transaction(CWalletTx const & wtx) } void CWallet::HandleSparkTransaction(CWalletTx const & wtx) { - if (!wtx.tx->IsSparkTransaction()) + if (!wtx.tx->IsSparkTransaction() || !sparkWallet) return; uint256 txHash = wtx.GetHash(); @@ -8119,6 +8119,11 @@ bool CWallet::CreateSparkMintTransactions( std::pair CWallet::GetSparkBalance() { std::pair balance = {0, 0}; + auto sparkWallet = pwalletMain->sparkWallet.get(); + + if(!sparkWallet) + return balance; + balance.first = sparkWallet->getAvailableBalance(); balance.second = sparkWallet->getUnconfirmedBalance(); return balance; @@ -8130,6 +8135,9 @@ bool CWallet::IsSparkAddressMine(const std::string& address) { bool CWallet::SetSparkAddressBook(const std::string& address, const std::string& strName, const std::string& strPurpose) { + if (!sparkWallet) + return false; + bool fUpdated = false; { LOCK(cs_wallet); // mapAddressBook