Skip to content

Commit

Permalink
RPC tests and more fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
levonpetrosyan93 committed Nov 13, 2023
1 parent defcf05 commit 33e39f6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
12 changes: 11 additions & 1 deletion src/qt/sendcoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ void SendCoinsDialog::setModel(WalletModel *_model)
std::pair<CAmount, CAmount> 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(),
Expand Down Expand Up @@ -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())
{
Expand Down
9 changes: 6 additions & 3 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1399,10 +1399,13 @@ std::pair<CAmount, CAmount> WalletModel::getSparkBalance()

bool WalletModel::getAvailableLelantusCoins()
{
if (!pwalletMain->zwallet)
return false;

std::list<CLelantusEntry> coins = wallet->GetAvailableLelantusCoins();
if(coins.size() > 0) {
if (coins.size() > 0) {
return true;
}else{
} else {
return false;
}
}
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/spark/sparkwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 15 additions & 7 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CSparkWallet>(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<bip47::CWallet>(walletInstance->vchDefaultKey.GetHash());
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -8119,6 +8119,11 @@ bool CWallet::CreateSparkMintTransactions(
std::pair<CAmount, CAmount> CWallet::GetSparkBalance()
{
std::pair<CAmount, CAmount> balance = {0, 0};
auto sparkWallet = pwalletMain->sparkWallet.get();

if(!sparkWallet)
return balance;

balance.first = sparkWallet->getAvailableBalance();
balance.second = sparkWallet->getUnconfirmedBalance();
return balance;
Expand All @@ -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
Expand Down

0 comments on commit 33e39f6

Please sign in to comment.