2016-01-18 15:33:29 +00:00
|
|
|
// Copyright (c) 2011-2016 The Cryptonote developers
|
2015-09-18 11:55:31 +00:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2015-05-27 12:08:46 +00:00
|
|
|
|
2015-04-06 16:13:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <future>
|
2015-05-27 12:08:46 +00:00
|
|
|
#include <map>
|
|
|
|
#include <mutex>
|
2015-04-06 16:13:07 +00:00
|
|
|
|
|
|
|
#include "crypto/hash.h"
|
2015-07-30 15:22:07 +00:00
|
|
|
#include "IWalletLegacy.h"
|
2015-04-06 16:13:07 +00:00
|
|
|
|
2015-05-27 12:08:46 +00:00
|
|
|
namespace CryptoNote {
|
2015-04-06 16:13:07 +00:00
|
|
|
namespace WalletHelper {
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
class SaveWalletResultObserver : public CryptoNote::IWalletLegacyObserver {
|
2015-04-06 16:13:07 +00:00
|
|
|
public:
|
|
|
|
std::promise<std::error_code> saveResult;
|
|
|
|
virtual void saveCompleted(std::error_code result) override { saveResult.set_value(result); }
|
|
|
|
};
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
class InitWalletResultObserver : public CryptoNote::IWalletLegacyObserver {
|
2015-04-06 16:13:07 +00:00
|
|
|
public:
|
|
|
|
std::promise<std::error_code> initResult;
|
|
|
|
virtual void initCompleted(std::error_code result) override { initResult.set_value(result); }
|
|
|
|
};
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
class SendCompleteResultObserver : public CryptoNote::IWalletLegacyObserver {
|
2015-04-06 16:13:07 +00:00
|
|
|
public:
|
2015-05-27 12:08:46 +00:00
|
|
|
virtual void sendTransactionCompleted(CryptoNote::TransactionId transactionId, std::error_code result) override;
|
|
|
|
std::error_code wait(CryptoNote::TransactionId transactionId);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::mutex m_mutex;
|
|
|
|
std::condition_variable m_condition;
|
|
|
|
std::map<CryptoNote::TransactionId, std::error_code> m_finishedTransactions;
|
2015-07-30 15:22:07 +00:00
|
|
|
std::error_code m_result;
|
2015-05-27 12:08:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class IWalletRemoveObserverGuard {
|
|
|
|
public:
|
2015-07-30 15:22:07 +00:00
|
|
|
IWalletRemoveObserverGuard(CryptoNote::IWalletLegacy& wallet, CryptoNote::IWalletLegacyObserver& observer);
|
2015-05-27 12:08:46 +00:00
|
|
|
~IWalletRemoveObserverGuard();
|
|
|
|
|
|
|
|
void removeObserver();
|
2015-07-30 15:22:07 +00:00
|
|
|
|
2015-05-27 12:08:46 +00:00
|
|
|
private:
|
2015-07-30 15:22:07 +00:00
|
|
|
CryptoNote::IWalletLegacy& m_wallet;
|
|
|
|
CryptoNote::IWalletLegacyObserver& m_observer;
|
2015-05-27 12:08:46 +00:00
|
|
|
bool m_removed;
|
2015-04-06 16:13:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void prepareFileNames(const std::string& file_path, std::string& keys_file, std::string& wallet_file);
|
2015-07-30 15:22:07 +00:00
|
|
|
void storeWallet(CryptoNote::IWalletLegacy& wallet, const std::string& walletFilename);
|
2015-04-06 16:13:07 +00:00
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
}
|
|
|
|
}
|