// Copyright (c) 2012-2015, The CryptoNote developers, The Bytecoin developers
//
// 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 .
#pragma once
#include "crypto/hash.h"
#include "IWalletLegacy.h"
#include "ITransfersContainer.h"
#include "WalletLegacy/WalletLegacyEvent.h"
#include "WalletLegacy/WalletUnconfirmedTransactions.h"
namespace CryptoNote {
class ISerializer;
}
namespace CryptoNote {
class WalletUserTransactionsCache
{
public:
WalletUserTransactionsCache() {}
bool serialize(CryptoNote::ISerializer& serializer);
uint64_t unconfirmedTransactionsAmount() const;
uint64_t unconfrimedOutsAmount() const;
size_t getTransactionCount() const;
size_t getTransferCount() const;
TransactionId addNewTransaction(uint64_t amount, uint64_t fee, const std::string& extra, const std::vector& transfers, uint64_t unlockTime);
void updateTransaction(TransactionId transactionId, const CryptoNote::Transaction& tx, uint64_t amount, const std::list& usedOutputs);
void updateTransactionSendingState(TransactionId transactionId, std::error_code ec);
std::shared_ptr onTransactionUpdated(const TransactionInformation& txInfo, int64_t txBalance);
std::shared_ptr onTransactionDeleted(const Crypto::Hash& transactionHash);
TransactionId findTransactionByTransferId(TransferId transferId) const;
bool getTransaction(TransactionId transactionId, WalletLegacyTransaction& transaction) const;
WalletLegacyTransaction& getTransaction(TransactionId transactionId);
bool getTransfer(TransferId transferId, WalletLegacyTransfer& transfer) const;
WalletLegacyTransfer& getTransfer(TransferId transferId);
bool isUsed(const TransactionOutputInformation& out) const;
void reset();
private:
TransactionId findTransactionByHash(const Crypto::Hash& hash);
TransactionId insertTransaction(WalletLegacyTransaction&& Transaction);
TransferId insertTransfers(const std::vector& transfers);
void updateUnconfirmedTransactions();
typedef std::vector UserTransfers;
typedef std::vector UserTransactions;
void getGoodItems(UserTransactions& transactions, UserTransfers& transfers);
void getGoodTransaction(TransactionId txId, size_t offset, UserTransactions& transactions, UserTransfers& transfers);
void getTransfersByTx(TransactionId id, UserTransfers& transfers);
UserTransactions m_transactions;
UserTransfers m_transfers;
WalletUnconfirmedTransactions m_unconfirmedTransactions;
};
} //namespace CryptoNote