Skip to content

Commit

Permalink
fix crash on windows
Browse files Browse the repository at this point in the history
* lock in try catch for transfer and createFusionTransaction
* fix warning C17 in WalletGreen.h
  • Loading branch information
Acktarius committed Feb 9, 2025
1 parent 246754d commit 234df99
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
3 changes: 2 additions & 1 deletion src/CryptoNoteProtocol/CryptoNoteProtocolHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ std::vector<std::string> CryptoNoteProtocolHandler::all_connections()
{
std::vector<std::string> connections;
connections.clear();
m_p2p->for_each_connection([&connections](const CryptoNoteConnectionContext &cntxt, [[maybe_unused]] PeerIdType peer_id)
m_p2p->for_each_connection([&connections](const CryptoNoteConnectionContext &cntxt, PeerIdType peer_id)
{
(void)peer_id;
std::string ipAddress = common::ipAddressToString(cntxt.m_remote_ip);
connections.push_back(ipAddress);
});
Expand Down
55 changes: 32 additions & 23 deletions src/Wallet/WalletGreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1909,15 +1909,21 @@ namespace cn
return bounds;
}

size_t WalletGreen::transfer(const TransactionParameters &transactionParameters, crypto::SecretKey &transactionSK)
size_t WalletGreen::transfer(const TransactionParameters &transactionParameters, crypto::SecretKey &transactionSK)
{
platform_system::EventLock lk(m_readyEvent);
try {
platform_system::EventLock lk(m_readyEvent);

throwIfNotInitialized();
throwIfTrackingMode();
throwIfStopped();
throwIfNotInitialized();
throwIfTrackingMode();
throwIfStopped();

return doTransfer(transactionParameters, transactionSK, true);
}
catch (const std::exception& ) {
throw;
}

return doTransfer(transactionParameters, transactionSK, true);
}

void WalletGreen::prepareTransaction(
Expand Down Expand Up @@ -4010,29 +4016,28 @@ namespace cn
return m_walletsContainer.get<RandomAccessIndex>().begin()->spendSecretKey == NULL_SECRET_KEY ? WalletTrackingMode::TRACKING : WalletTrackingMode::NOT_TRACKING;
}

size_t WalletGreen::createFusionTransaction(
size_t WalletGreen::createFusionTransaction(
uint64_t threshold, uint64_t mixin,
const std::vector<std::string> &sourceAddresses,
const std::string &destinationAddress)
{
platform_system::EventLock lk(m_readyEvent);
size_t id = WALLET_INVALID_TRANSACTION_ID;
try {
platform_system::EventLock lk(m_readyEvent);

throwIfNotInitialized();
throwIfTrackingMode();
throwIfStopped();

validateSourceAddresses(sourceAddresses);
validateChangeDestination(sourceAddresses, destinationAddress, true);
throwIfNotInitialized();
throwIfTrackingMode();
throwIfStopped();

const size_t MAX_FUSION_OUTPUT_COUNT = 8;
validateSourceAddresses(sourceAddresses);
validateChangeDestination(sourceAddresses, destinationAddress, true);

uint64_t fusionTreshold = m_currency.defaultDustThreshold();

if (threshold <= fusionTreshold)
{
throw std::system_error(make_error_code(error::THRESHOLD_TOO_LOW));
}
const size_t MAX_FUSION_OUTPUT_COUNT = 8;
uint64_t fusionTreshold = m_currency.defaultDustThreshold();
if (threshold <= fusionTreshold) {
throw std::system_error(make_error_code(error::THRESHOLD_TOO_LOW));
}

if (m_walletsContainer.get<RandomAccessIndex>().size() == 0)
{
Expand Down Expand Up @@ -4092,14 +4097,18 @@ namespace cn

if (fusionInputs.size() < m_currency.fusionTxMinInputCount())
{
throw std::system_error(make_error_code(error::MINIMUM_INPUT_COUNT));
throw std::system_error(make_error_code(error::MINIMUM_INPUT_COUNT));
}
if (fusionTransaction->getOutputCount() == 0)
{
throw std::system_error(make_error_code(error::WRONG_AMOUNT));
throw std::system_error(make_error_code(error::WRONG_AMOUNT));
}
id = validateSaveAndSendTransaction(*fusionTransaction, {}, true, true);
return id;
}
catch (const std::system_error& ) {
throw;
}
}

WalletGreen::ReceiverAmounts WalletGreen::decomposeFusionOutputs(const AccountPublicAddress &address, uint64_t inputsAmount) const
Expand Down
3 changes: 2 additions & 1 deletion src/Wallet/WalletGreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class WalletGreen : public IObservableImpl<IWalletObserver, IWallet>,
public ITransfersObserver,
public IBlockchainSynchronizerObserver,
public ITransfersSynchronizerObserver,
public IFusionManager
public IFusionManager,
public std::enable_shared_from_this<WalletGreen>
{
public:
WalletGreen(platform_system::Dispatcher &dispatcher, const Currency &currency, INode &node, logging::ILogger &logger, uint32_t transactionSoftLockTime = 1);
Expand Down

0 comments on commit 234df99

Please sign in to comment.