// 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 .
// Copyright (c) 2012-2014, 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 .
#include "NodeFactory.h"
#include "node_rpc_proxy/NodeRpcProxy.h"
#include
#include
namespace PaymentService {
class NodeRpcStub: public CryptoNote::INode {
public:
virtual ~NodeRpcStub() {}
virtual bool addObserver(CryptoNote::INodeObserver* observer) { return true; }
virtual bool removeObserver(CryptoNote::INodeObserver* observer) { return true; }
virtual void init(const Callback& callback) { }
virtual bool shutdown() { return true; }
virtual size_t getPeerCount() const { return 0; }
virtual uint64_t getLastLocalBlockHeight() const { return 0; }
virtual uint64_t getLastKnownBlockHeight() const { return 0; }
virtual uint64_t getLocalBlockCount() const override { return 0; }
virtual uint64_t getKnownBlockCount() const override { return 0; }
virtual uint64_t getLastLocalBlockTimestamp() const { return 0; }
virtual void relayTransaction(const CryptoNote::Transaction& transaction, const Callback& callback) { callback(std::error_code()); }
virtual void getRandomOutsByAmounts(std::vector&& amounts, uint64_t outsCount,
std::vector& result, const Callback& callback) { callback(std::error_code()); }
virtual void getNewBlocks(std::list&& knownBlockIds, std::list& newBlocks, uint64_t& startHeight, const Callback& callback) { callback(std::error_code()); }
virtual void getTransactionOutsGlobalIndices(const crypto::hash& transactionHash, std::vector& outsGlobalIndices, const Callback& callback) { callback(std::error_code()); }
virtual void queryBlocks(std::list&& knownBlockIds, uint64_t timestamp, std::list& newBlocks,
uint64_t& startHeight, const CryptoNote::INode::Callback& callback) { startHeight = 0; callback(std::error_code()); }
virtual void getPoolSymmetricDifference(std::vector&& known_pool_tx_ids, crypto::hash known_block_id,
bool& is_bc_actual, std::vector& new_txs, std::vector& deleted_tx_ids,
const Callback& callback) { callback(std::error_code()); }
};
class NodeInitObserver {
public:
NodeInitObserver() {}
void initCompleted(std::error_code result) {
initPromise.set_value(result);
}
void waitForInitEnd() {
auto future = initPromise.get_future();
std::error_code ec = future.get();
if (ec) {
throw std::system_error(ec);
}
return;
}
private:
std::promise initPromise;
};
NodeFactory::NodeFactory() {
}
NodeFactory::~NodeFactory() {
}
CryptoNote::INode* NodeFactory::createNode(const std::string& daemonAddress, uint16_t daemonPort) {
std::unique_ptr node(new CryptoNote::NodeRpcProxy(daemonAddress, daemonPort));
NodeInitObserver initObserver;
node->init(std::bind(&NodeInitObserver::initCompleted, &initObserver, std::placeholders::_1));
initObserver.waitForInitEnd();
return node.release();
}
CryptoNote::INode* NodeFactory::createNodeStub() {
return new NodeRpcStub();
}
}