danicoin/src/PaymentGate/WalletService.h

103 lines
5.3 KiB
C
Raw Normal View History

// Copyright (c) 2011-2016 The Cryptonote developers
// 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
#pragma once
2015-07-30 15:22:07 +00:00
#include <System/ContextGroup.h>
2015-05-27 12:08:46 +00:00
#include <System/Dispatcher.h>
2015-07-30 15:22:07 +00:00
#include <System/Event.h>
2015-05-27 12:08:46 +00:00
#include "IWallet.h"
#include "INode.h"
2015-07-30 15:22:07 +00:00
#include "CryptoNoteCore/Currency.h"
#include "PaymentServiceJsonRpcMessages.h"
2015-05-27 12:08:46 +00:00
#undef ERROR //TODO: workaround for windows build. fix it
#include "Logging/LoggerRef.h"
#include <fstream>
#include <memory>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/hashed_index.hpp>
namespace PaymentService {
2015-07-30 15:22:07 +00:00
struct WalletConfiguration {
std::string walletFile;
std::string walletPassword;
};
void generateNewWallet(const CryptoNote::Currency &currency, const WalletConfiguration &conf, Logging::ILogger &logger, System::Dispatcher& dispatcher);
2015-05-27 12:08:46 +00:00
2015-12-09 13:19:03 +00:00
struct TransactionsInBlockInfoFilter;
2015-07-30 15:22:07 +00:00
class WalletService {
2015-05-27 12:08:46 +00:00
public:
2015-12-09 13:19:03 +00:00
WalletService(const CryptoNote::Currency& currency, System::Dispatcher& sys, CryptoNote::INode& node, CryptoNote::IWallet& wallet, const WalletConfiguration& conf, Logging::ILogger& logger);
2015-05-27 12:08:46 +00:00
virtual ~WalletService();
void init();
void saveWallet();
2015-12-09 13:19:03 +00:00
std::error_code resetWallet();
std::error_code replaceWithNewWallet(const std::string& viewSecretKey);
std::error_code createAddress(const std::string& spendSecretKeyText, std::string& address);
2015-07-30 15:22:07 +00:00
std::error_code createAddress(std::string& address);
2015-12-09 13:19:03 +00:00
std::error_code createTrackingAddress(const std::string& spendPublicKeyText, std::string& address);
2015-07-30 15:22:07 +00:00
std::error_code deleteAddress(const std::string& address);
2015-12-09 13:19:03 +00:00
std::error_code getSpendkeys(const std::string& address, std::string& publicSpendKeyText, std::string& secretSpendKeyText);
std::error_code getBalance(const std::string& address, uint64_t& availableBalance, uint64_t& lockedAmount);
std::error_code getBalance(uint64_t& availableBalance, uint64_t& lockedAmount);
std::error_code getBlockHashes(uint32_t firstBlockIndex, uint32_t blockCount, std::vector<std::string>& blockHashes);
std::error_code getViewKey(std::string& viewSecretKey);
std::error_code getTransactionHashes(const std::vector<std::string>& addresses, const std::string& blockHash,
uint32_t blockCount, const std::string& paymentId, std::vector<TransactionHashesInBlockRpcInfo>& transactionHashes);
std::error_code getTransactionHashes(const std::vector<std::string>& addresses, uint32_t firstBlockIndex,
uint32_t blockCount, const std::string& paymentId, std::vector<TransactionHashesInBlockRpcInfo>& transactionHashes);
std::error_code getTransactions(const std::vector<std::string>& addresses, const std::string& blockHash,
uint32_t blockCount, const std::string& paymentId, std::vector<TransactionsInBlockRpcInfo>& transactionHashes);
std::error_code getTransactions(const std::vector<std::string>& addresses, uint32_t firstBlockIndex,
uint32_t blockCount, const std::string& paymentId, std::vector<TransactionsInBlockRpcInfo>& transactionHashes);
std::error_code getTransaction(const std::string& transactionHash, TransactionRpcInfo& transaction);
std::error_code getAddresses(std::vector<std::string>& addresses);
std::error_code sendTransaction(const SendTransaction::Request& request, std::string& transactionHash);
std::error_code createDelayedTransaction(const CreateDelayedTransaction::Request& request, std::string& transactionHash);
std::error_code getDelayedTransactionHashes(std::vector<std::string>& transactionHashes);
std::error_code deleteDelayedTransaction(const std::string& transactionHash);
std::error_code sendDelayedTransaction(const std::string& transactionHash);
std::error_code getUnconfirmedTransactionHashes(const std::vector<std::string>& addresses, std::vector<std::string>& transactionHashes);
std::error_code getStatus(uint32_t& blockCount, uint32_t& knownBlockCount, std::string& lastBlockHash, uint32_t& peerCount);
2015-05-27 12:08:46 +00:00
private:
2015-07-30 15:22:07 +00:00
void refresh();
2015-12-09 13:19:03 +00:00
void reset();
2015-05-27 12:08:46 +00:00
2015-07-30 15:22:07 +00:00
void loadWallet();
2015-12-09 13:19:03 +00:00
void loadTransactionIdIndex();
void replaceWithNewWallet(const Crypto::SecretKey& viewSecretKey);
std::vector<CryptoNote::TransactionsInBlockInfo> getTransactions(const Crypto::Hash& blockHash, size_t blockCount) const;
std::vector<CryptoNote::TransactionsInBlockInfo> getTransactions(uint32_t firstBlockIndex, size_t blockCount) const;
std::vector<TransactionHashesInBlockRpcInfo> getRpcTransactionHashes(const Crypto::Hash& blockHash, size_t blockCount, const TransactionsInBlockInfoFilter& filter) const;
std::vector<TransactionHashesInBlockRpcInfo> getRpcTransactionHashes(uint32_t firstBlockIndex, size_t blockCount, const TransactionsInBlockInfoFilter& filter) const;
std::vector<TransactionsInBlockRpcInfo> getRpcTransactions(const Crypto::Hash& blockHash, size_t blockCount, const TransactionsInBlockInfoFilter& filter) const;
std::vector<TransactionsInBlockRpcInfo> getRpcTransactions(uint32_t firstBlockIndex, size_t blockCount, const TransactionsInBlockInfoFilter& filter) const;
const CryptoNote::Currency& currency;
CryptoNote::IWallet& wallet;
CryptoNote::INode& node;
2015-07-30 15:22:07 +00:00
const WalletConfiguration& config;
2015-05-27 12:08:46 +00:00
bool inited;
Logging::LoggerRef logger;
2015-07-30 15:22:07 +00:00
System::Dispatcher& dispatcher;
2015-12-09 13:19:03 +00:00
System::Event readyEvent;
2015-07-30 15:22:07 +00:00
System::ContextGroup refreshContext;
2015-05-27 12:08:46 +00:00
2015-12-09 13:19:03 +00:00
std::map<std::string, size_t> transactionIdIndex;
2015-05-27 12:08:46 +00:00
};
} //namespace PaymentService