danicoin/src/WalletLegacy/WalletLegacy.h

131 lines
4.6 KiB
C
Raw Normal View History

// Copyright (c) 2011-2016 The Cryptonote developers
2014-06-25 17:21:42 +00:00
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#pragma once
#include <list>
#include <vector>
#include <unordered_map>
#include <memory>
#include <mutex>
2015-07-30 15:22:07 +00:00
#include "IWalletLegacy.h"
2014-06-25 17:21:42 +00:00
#include "INode.h"
2015-07-30 15:22:07 +00:00
#include "Wallet/WalletErrors.h"
#include "Wallet/WalletAsyncContextCounter.h"
2015-05-27 12:08:46 +00:00
#include "Common/ObserverManager.h"
2015-07-30 15:22:07 +00:00
#include "CryptoNoteCore/TransactionExtra.h"
#include "CryptoNoteCore/CryptoNoteFormatUtils.h"
#include "CryptoNoteCore/Currency.h"
#include "WalletLegacy/WalletUserTransactionsCache.h"
#include "WalletLegacy/WalletUnconfirmedTransactions.h"
2015-07-30 15:22:07 +00:00
#include "WalletLegacy/WalletTransactionSender.h"
#include "WalletLegacy/WalletRequest.h"
2014-06-25 17:21:42 +00:00
2015-07-30 15:22:07 +00:00
#include "Transfers/BlockchainSynchronizer.h"
#include "Transfers/TransfersSynchronizer.h"
2014-06-25 17:21:42 +00:00
namespace CryptoNote {
class SyncStarter;
2015-07-30 15:22:07 +00:00
class WalletLegacy :
public IWalletLegacy,
IBlockchainSynchronizerObserver,
ITransfersObserver {
2014-06-25 17:21:42 +00:00
public:
2015-07-30 15:22:07 +00:00
WalletLegacy(const CryptoNote::Currency& currency, INode& node);
virtual ~WalletLegacy();
2014-06-25 17:21:42 +00:00
2015-10-01 15:27:18 +00:00
virtual void addObserver(IWalletLegacyObserver* observer) override;
virtual void removeObserver(IWalletLegacyObserver* observer) override;
2014-06-25 17:21:42 +00:00
2015-10-01 15:27:18 +00:00
virtual void initAndGenerate(const std::string& password) override;
virtual void initAndLoad(std::istream& source, const std::string& password) override;
virtual void initWithKeys(const AccountKeys& accountKeys, const std::string& password) override;
virtual void shutdown() override;
virtual void reset() override;
2014-06-25 17:21:42 +00:00
2015-10-01 15:27:18 +00:00
virtual void save(std::ostream& destination, bool saveDetailed = true, bool saveCache = true) override;
2014-06-25 17:21:42 +00:00
2015-10-01 15:27:18 +00:00
virtual std::error_code changePassword(const std::string& oldPassword, const std::string& newPassword) override;
2014-06-25 17:21:42 +00:00
2015-10-01 15:27:18 +00:00
virtual std::string getAddress() override;
2014-06-25 17:21:42 +00:00
2015-10-01 15:27:18 +00:00
virtual uint64_t actualBalance() override;
virtual uint64_t pendingBalance() override;
2014-06-25 17:21:42 +00:00
2015-10-01 15:27:18 +00:00
virtual size_t getTransactionCount() override;
virtual size_t getTransferCount() override;
2014-06-25 17:21:42 +00:00
2015-10-01 15:27:18 +00:00
virtual TransactionId findTransactionByTransferId(TransferId transferId) override;
2014-06-25 17:21:42 +00:00
2015-10-01 15:27:18 +00:00
virtual bool getTransaction(TransactionId transactionId, WalletLegacyTransaction& transaction) override;
virtual bool getTransfer(TransferId transferId, WalletLegacyTransfer& transfer) override;
2014-06-25 17:21:42 +00:00
2015-10-01 15:27:18 +00:00
virtual TransactionId sendTransaction(const WalletLegacyTransfer& transfer, uint64_t fee, const std::string& extra = "", uint64_t mixIn = 0, uint64_t unlockTimestamp = 0) override;
virtual TransactionId sendTransaction(const std::vector<WalletLegacyTransfer>& transfers, uint64_t fee, const std::string& extra = "", uint64_t mixIn = 0, uint64_t unlockTimestamp = 0) override;
virtual std::error_code cancelTransaction(size_t transactionId) override;
2014-06-25 17:21:42 +00:00
2015-10-01 15:27:18 +00:00
virtual void getAccountKeys(AccountKeys& keys) override;
2014-06-25 17:21:42 +00:00
private:
// IBlockchainSynchronizerObserver
2015-07-30 15:22:07 +00:00
virtual void synchronizationProgressUpdated(uint32_t current, uint32_t total) override;
virtual void synchronizationCompleted(std::error_code result) override;
// ITransfersObserver
2015-07-30 15:22:07 +00:00
virtual void onTransactionUpdated(ITransfersSubscription* object, const Crypto::Hash& transactionHash) override;
virtual void onTransactionDeleted(ITransfersSubscription* object, const Crypto::Hash& transactionHash) override;
void initSync();
2014-06-25 17:21:42 +00:00
void throwIfNotInitialised();
void doSave(std::ostream& destination, bool saveDetailed, bool saveCache);
void doLoad(std::istream& source);
void synchronizationCallback(WalletRequest::Callback callback, std::error_code ec);
void sendTransactionCallback(WalletRequest::Callback callback, std::error_code ec);
2015-07-30 15:22:07 +00:00
void notifyClients(std::deque<std::shared_ptr<WalletLegacyEvent> >& events);
void notifyIfBalanceChanged();
2014-06-25 17:21:42 +00:00
2015-08-05 13:09:05 +00:00
std::vector<TransactionId> deleteOutdatedUnconfirmedTransactions();
2014-06-25 17:21:42 +00:00
enum WalletState
{
NOT_INITIALIZED = 0,
INITIALIZED,
LOADING,
SAVING
};
WalletState m_state;
std::mutex m_cacheMutex;
2015-07-30 15:22:07 +00:00
CryptoNote::AccountBase m_account;
2014-06-25 17:21:42 +00:00
std::string m_password;
2015-05-27 12:08:46 +00:00
const CryptoNote::Currency& m_currency;
2014-06-25 17:21:42 +00:00
INode& m_node;
bool m_isStopping;
std::atomic<uint64_t> m_lastNotifiedActualBalance;
std::atomic<uint64_t> m_lastNotifiedPendingBalance;
2014-06-25 17:21:42 +00:00
BlockchainSynchronizer m_blockchainSync;
TransfersSyncronizer m_transfersSync;
ITransfersContainer* m_transferDetails;
2014-06-25 17:21:42 +00:00
WalletUserTransactionsCache m_transactionsCache;
std::unique_ptr<WalletTransactionSender> m_sender;
2014-06-25 17:21:42 +00:00
WalletAsyncContextCounter m_asyncContextCounter;
2015-07-30 15:22:07 +00:00
Tools::ObserverManager<CryptoNote::IWalletLegacyObserver> m_observerManager;
2014-06-25 17:21:42 +00:00
std::unique_ptr<SyncStarter> m_onInitSyncStarter;
2014-06-25 17:21:42 +00:00
};
} //namespace CryptoNote