diff --git a/src/mweb/mweb_transact.cpp b/src/mweb/mweb_transact.cpp index f7c3dd534..d668c0336 100644 --- a/src/mweb/mweb_transact.cpp +++ b/src/mweb/mweb_transact.cpp @@ -8,6 +8,33 @@ using namespace MWEB; +TxType MWEB::GetTxType(const std::vector& recipients, const std::set& input_coins) +{ + assert(!recipients.empty()); + + static auto is_ltc = [](const CInputCoin& input) { return !input.IsMWEB(); }; + static auto is_mweb = [](const CInputCoin& input) { return input.IsMWEB(); }; + + if (recipients.front().IsMWEB()) { + // If any inputs are non-MWEB inputs, this is a peg-in transaction. + // Otherwise, it's a simple MWEB-to-MWEB transaction. + if (std::any_of(input_coins.cbegin(), input_coins.cend(), is_ltc)) { + return TxType::PEGIN; + } else { + return TxType::MWEB_TO_MWEB; + } + } else { + // If any inputs are MWEB inputs, this is a peg-out transaction. + // NOTE: This does not exclude the possibility that it's also pegging-in in addition to the pegout. + // Otherwise, if there are no MWEB inputs, it's a simple LTC-to-LTC transaction. + if (std::any_of(input_coins.cbegin(), input_coins.cend(), is_mweb)) { + return TxType::PEGOUT; + } else { + return TxType::LTC_TO_LTC; + } + } +} + bool MWEB::ContainsPegIn(const TxType& mweb_type, const std::set& input_coins) { if (mweb_type == MWEB::TxType::PEGIN) { diff --git a/src/mweb/mweb_transact.h b/src/mweb/mweb_transact.h index dae95b611..5ad2f5969 100644 --- a/src/mweb/mweb_transact.h +++ b/src/mweb/mweb_transact.h @@ -20,6 +20,7 @@ enum class TxType { PEGOUT // NOTE: It's possible pegout transactions will also have pegins, but they will still be classified as PEGOUT }; +TxType GetTxType(const std::vector& recipients, const std::set& input_coins); bool ContainsPegIn(const TxType& mweb_type, const std::set& input_coins); bool IsChangeOnMWEB(const CWallet& wallet, const MWEB::TxType& mweb_type, const std::vector& recipients, const CTxDestination& dest_change); uint64_t CalcMWEBWeight(const MWEB::TxType& mweb_type, const bool change_on_mweb, const std::vector& recipients); diff --git a/src/mweb/mweb_wallet.cpp b/src/mweb/mweb_wallet.cpp index 5978689b0..bf61fbcda 100644 --- a/src/mweb/mweb_wallet.cpp +++ b/src/mweb/mweb_wallet.cpp @@ -94,6 +94,10 @@ bool Wallet::GetStealthAddress(const uint32_t index, StealthAddress& address) co return false; } + if (keychain->GetSpendKey().IsNull()) { + return false; + } + address = keychain->GetStealthAddress(index); return true; } diff --git a/src/wallet/txassembler.cpp b/src/wallet/txassembler.cpp index b1dd7447a..e5b6fc3ee 100644 --- a/src/wallet/txassembler.cpp +++ b/src/wallet/txassembler.cpp @@ -129,6 +129,8 @@ void TxAssembler::CreateTransaction_Locked( new_tx.coin_selection_params.use_bnb = false; } + new_tx.mweb_type = MWEB::GetTxType(new_tx.recipients, new_tx.selected_coins); + // We already created an output for each non-MWEB recipient, but for pegout transactions, // the recipients are funded through the pegout kernel instead of traditional LTC outputs. if (new_tx.mweb_type == MWEB::TxType::PEGOUT) { @@ -397,7 +399,6 @@ bool TxAssembler::AttemptCoinSelection(InProcessTx& new_tx, const CAmount& nTarg mweb_to_mweb.tx_noinputs_size = 0; if (SelectCoins(new_tx, nTargetValue, mweb_to_mweb)) { - new_tx.mweb_type = MWEB::TxType::MWEB_TO_MWEB; return true; } @@ -411,7 +412,6 @@ bool TxAssembler::AttemptCoinSelection(InProcessTx& new_tx, const CAmount& nTarg params_pegin.change_spend_size = change_on_mweb ? 0 : new_tx.coin_selection_params.change_spend_size; if (SelectCoins(new_tx, nTargetValue, params_pegin)) { - new_tx.mweb_type = MWEB::TxType::PEGIN; return std::any_of(new_tx.selected_coins.cbegin(), new_tx.selected_coins.cend(), is_ltc); } } else { @@ -422,7 +422,6 @@ bool TxAssembler::AttemptCoinSelection(InProcessTx& new_tx, const CAmount& nTarg mweb_to_mweb.mweb_nochange_weight = 0; if (SelectCoins(new_tx, nTargetValue, mweb_to_mweb)) { - new_tx.mweb_type = MWEB::TxType::LTC_TO_LTC; return true; } @@ -441,7 +440,6 @@ bool TxAssembler::AttemptCoinSelection(InProcessTx& new_tx, const CAmount& nTarg new_tx.tx.vout.clear(); if (SelectCoins(new_tx, nTargetValue, params_pegout)) { - new_tx.mweb_type = MWEB::TxType::PEGOUT; return std::any_of(new_tx.selected_coins.cbegin(), new_tx.selected_coins.cend(), is_mweb); } }