From 4a91cbb46f3382e0cf9dc36091c1b1b0f2430780 Mon Sep 17 00:00:00 2001 From: levonpetrosyan93 Date: Sat, 28 Oct 2023 05:35:20 +0400 Subject: [PATCH] Spend remaining sigma coins in lelantustospark rpc --- src/wallet/wallet.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 6224f1f5ac..a94a56bbb2 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -5759,6 +5759,8 @@ CWalletTx CWallet::SpendAndStoreSpark( bool CWallet::LelantusToSpark(std::string& strFailReason) { std::list coins = GetAvailableLelantusCoins(); + std::list sigmaCoins = GetAvailableCoins(); + CScript scriptChange; { // Reserve a new key pair from key pool @@ -5774,21 +5776,29 @@ bool CWallet::LelantusToSpark(std::string& strFailReason) { scriptChange = GetScriptForDestination(vchPubKey.GetID()); } - while (coins.size() > 0) { + while (coins.size() > 0 || sigmaCoins.size() > 0) { bool addMoreCoins = true; std::size_t selectedNum = 0; CCoinControl coinControl; CAmount spendValue = 0; while (true) { - auto coin = coins.begin(); COutPoint outPoint; - lelantus::GetOutPoint(outPoint, coin->value); - coinControl.Select(outPoint); - spendValue += coin->amount; - selectedNum ++; - coins.erase(coin); - if (!coins.size()) - break; + if (sigmaCoins.size() > 0) { + auto coin = sigmaCoins.begin(); + sigma::GetOutPoint(outPoint, coin->value); + coinControl.Select(outPoint); + spendValue += coin->get_denomination_value(); + selectedNum++; + sigmaCoins.erase(coin); + } else if (coins.size() > 0) { + auto coin = coins.begin(); + lelantus::GetOutPoint(outPoint, coin->value); + coinControl.Select(outPoint); + spendValue += coin->amount; + selectedNum++; + coins.erase(coin); + } else + break; if ((spendValue + coins.begin()->amount) > Params().GetConsensus().nMaxValueLelantusSpendPerTransaction) break;