2015-05-27 12:08:46 +00:00
|
|
|
// Copyright (c) 2012-2015, The CryptoNote developers, The Bytecoin developers
|
2014-08-13 10:38:35 +00:00
|
|
|
//
|
|
|
|
// This file is part of Bytecoin.
|
|
|
|
//
|
|
|
|
// Bytecoin is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Bytecoin is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with Bytecoin. If not, see <http://www.gnu.org/licenses/>.
|
2014-06-25 17:21:42 +00:00
|
|
|
|
|
|
|
#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-04-06 16:13:07 +00:00
|
|
|
|
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"
|
2015-04-06 16:13:07 +00:00
|
|
|
|
2014-06-25 17:21:42 +00:00
|
|
|
namespace CryptoNote {
|
|
|
|
|
2015-04-06 16:13:07 +00:00
|
|
|
class SyncStarter;
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
class WalletLegacy :
|
|
|
|
public IWalletLegacy,
|
2015-04-06 16:13:07 +00:00
|
|
|
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-07-30 15:22:07 +00:00
|
|
|
virtual void addObserver(IWalletLegacyObserver* observer);
|
|
|
|
virtual void removeObserver(IWalletLegacyObserver* observer);
|
2014-06-25 17:21:42 +00:00
|
|
|
|
|
|
|
virtual void initAndGenerate(const std::string& password);
|
|
|
|
virtual void initAndLoad(std::istream& source, const std::string& password);
|
2015-07-30 15:22:07 +00:00
|
|
|
virtual void initWithKeys(const AccountKeys& accountKeys, const std::string& password);
|
2014-06-25 17:21:42 +00:00
|
|
|
virtual void shutdown();
|
2015-04-06 16:13:07 +00:00
|
|
|
virtual void reset();
|
2014-06-25 17:21:42 +00:00
|
|
|
|
|
|
|
virtual void save(std::ostream& destination, bool saveDetailed = true, bool saveCache = true);
|
|
|
|
|
|
|
|
virtual std::error_code changePassword(const std::string& oldPassword, const std::string& newPassword);
|
|
|
|
|
|
|
|
virtual std::string getAddress();
|
|
|
|
|
|
|
|
virtual uint64_t actualBalance();
|
|
|
|
virtual uint64_t pendingBalance();
|
|
|
|
|
|
|
|
virtual size_t getTransactionCount();
|
|
|
|
virtual size_t getTransferCount();
|
|
|
|
|
|
|
|
virtual TransactionId findTransactionByTransferId(TransferId transferId);
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
virtual bool getTransaction(TransactionId transactionId, WalletLegacyTransaction& transaction);
|
|
|
|
virtual bool getTransfer(TransferId transferId, WalletLegacyTransfer& transfer);
|
2014-06-25 17:21:42 +00:00
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
virtual TransactionId sendTransaction(const WalletLegacyTransfer& transfer, uint64_t fee, const std::string& extra = "", uint64_t mixIn = 0, uint64_t unlockTimestamp = 0);
|
|
|
|
virtual TransactionId sendTransaction(const std::vector<WalletLegacyTransfer>& transfers, uint64_t fee, const std::string& extra = "", uint64_t mixIn = 0, uint64_t unlockTimestamp = 0);
|
2014-06-25 17:21:42 +00:00
|
|
|
virtual std::error_code cancelTransaction(size_t transactionId);
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
virtual void getAccountKeys(AccountKeys& keys);
|
2014-06-25 17:21:42 +00:00
|
|
|
|
|
|
|
private:
|
2015-04-06 16:13:07 +00:00
|
|
|
|
|
|
|
// IBlockchainSynchronizerObserver
|
2015-07-30 15:22:07 +00:00
|
|
|
virtual void synchronizationProgressUpdated(uint32_t current, uint32_t total) override;
|
2015-04-06 16:13:07 +00:00
|
|
|
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;
|
2015-04-06 16:13:07 +00:00
|
|
|
|
|
|
|
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);
|
2015-04-06 16:13:07 +00:00
|
|
|
void notifyIfBalanceChanged();
|
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;
|
|
|
|
|
2015-04-06 16:13:07 +00:00
|
|
|
std::atomic<uint64_t> m_lastNotifiedActualBalance;
|
|
|
|
std::atomic<uint64_t> m_lastNotifiedPendingBalance;
|
2014-06-25 17:21:42 +00:00
|
|
|
|
2015-04-06 16:13:07 +00:00
|
|
|
BlockchainSynchronizer m_blockchainSync;
|
|
|
|
TransfersSyncronizer m_transfersSync;
|
|
|
|
ITransfersContainer* m_transferDetails;
|
2014-06-25 17:21:42 +00:00
|
|
|
|
|
|
|
WalletUserTransactionsCache m_transactionsCache;
|
2015-04-06 16:13:07 +00:00
|
|
|
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
|
|
|
|
2015-04-06 16:13:07 +00:00
|
|
|
std::unique_ptr<SyncStarter> m_onInitSyncStarter;
|
2014-06-25 17:21:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} //namespace CryptoNote
|