-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathINode.h
executable file
·144 lines (124 loc) · 6.56 KB
/
INode.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Copyright (c) 2021-2023, Dynex Developers
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Parts of this project are originally copyright by:
// Copyright (c) 2012-2016, The CN developers, The Bytecoin developers
// Copyright (c) 2014-2018, The Monero project
// Copyright (c) 2014-2018, The Forknote developers
// Copyright (c) 2018, The TurtleCoin developers
// Copyright (c) 2016-2018, The Karbowanec developers
// Copyright (c) 2017-2022, The CROAT.community developers
#pragma once
#include <cstdint>
#include <functional>
#include <system_error>
#include <vector>
#include <memory>
#include "crypto/crypto.h"
#include "DynexCNCore/DynexCNBasic.h"
#include "DynexCNProtocol/DynexCNProtocolDefinitions.h"
#include "Rpc/CoreRpcServerCommandsDefinitions.h"
#include "BlockchainExplorerData.h"
#include "ITransaction.h"
namespace DynexCN {
class INodeObserver {
public:
virtual ~INodeObserver() {}
virtual void peerCountUpdated(size_t count) {}
virtual void localBlockchainUpdated(uint32_t height) {}
virtual void lastKnownBlockHeightUpdated(uint32_t height) {}
virtual void poolChanged() {}
virtual void blockchainSynchronized(uint32_t topHeight) {}
};
struct OutEntry {
uint32_t outGlobalIndex;
Crypto::PublicKey outKey;
};
struct OutsForAmount {
uint64_t amount;
std::vector<OutEntry> outs;
};
struct TransactionShortInfo {
Crypto::Hash txId;
TransactionPrefix txPrefix;
};
struct BlockShortEntry {
Crypto::Hash blockHash;
bool hasBlock;
DynexCN::Block block;
std::vector<TransactionShortInfo> txsShortInfo;
};
struct BlockHeaderInfo {
uint32_t index;
uint8_t majorVersion;
uint8_t minorVersion;
uint64_t timestamp;
Crypto::Hash hash;
Crypto::Hash prevHash;
uint32_t nonce;
bool isAlternative;
uint32_t depth; // last block index = current block index + depth
difficulty_type difficulty;
uint64_t reward;
};
class INode {
public:
typedef std::function<void(std::error_code)> Callback;
virtual ~INode() {}
virtual bool addObserver(INodeObserver* observer) = 0;
virtual bool removeObserver(INodeObserver* observer) = 0;
virtual void init(const Callback& callback) = 0;
virtual bool shutdown() = 0;
virtual size_t getPeerCount() const = 0;
virtual uint32_t getLastLocalBlockHeight() const = 0;
virtual uint32_t getLastKnownBlockHeight() const = 0;
virtual uint32_t getLocalBlockCount() const = 0;
virtual uint32_t getKnownBlockCount() const = 0;
virtual uint64_t getMinimalFee() const = 0;
virtual uint64_t getLastLocalBlockTimestamp() const = 0;
virtual uint32_t getNodeHeight() const = 0;
virtual BlockHeaderInfo getLastLocalBlockHeaderInfo() const = 0;
virtual void getFeeAddress() = 0;
virtual void relayTransaction(const Transaction& transaction, const Callback& callback) = 0;
virtual void getRandomOutsByAmounts(std::vector<uint64_t>&& amounts, uint64_t outsCount, std::vector<DynexCN::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount>& result, const Callback& callback) = 0;
virtual void getNewBlocks(std::vector<Crypto::Hash>&& knownBlockIds, std::vector<DynexCN::block_complete_entry>& newBlocks, uint32_t& startHeight, const Callback& callback) = 0;
virtual void getTransactionOutsGlobalIndices(const Crypto::Hash& transactionHash, std::vector<uint32_t>& outsGlobalIndices, const Callback& callback) = 0;
virtual void queryBlocks(std::vector<Crypto::Hash>&& knownBlockIds, uint64_t timestamp, std::vector<BlockShortEntry>& newBlocks, uint32_t& startHeight, const Callback& callback) = 0;
virtual void getPoolSymmetricDifference(std::vector<Crypto::Hash>&& knownPoolTxIds, Crypto::Hash knownBlockId, bool& isBcActual, std::vector<std::unique_ptr<ITransactionReader>>& newTxs, std::vector<Crypto::Hash>& deletedTxIds, const Callback& callback) = 0;
virtual void getMultisignatureOutputByGlobalIndex(uint64_t amount, uint32_t gindex, MultisignatureOutput& out, const Callback& callback) = 0;
virtual void getBlocks(const std::vector<uint32_t>& blockHeights, std::vector<std::vector<BlockDetails>>& blocks, const Callback& callback) = 0;
virtual void getBlocks(const std::vector<Crypto::Hash>& blockHashes, std::vector<BlockDetails>& blocks, const Callback& callback) = 0;
virtual void getBlocks(uint64_t timestampBegin, uint64_t timestampEnd, uint32_t blocksNumberLimit, std::vector<BlockDetails>& blocks, uint32_t& blocksNumberWithinTimestamps, const Callback& callback) = 0;
virtual void getBlock(const uint32_t blockHeight, BlockDetails &block, const Callback& callback) = 0;
virtual void getTransactions(const std::vector<Crypto::Hash>& transactionHashes, std::vector<TransactionDetails>& transactions, const Callback& callback) = 0;
virtual void getTransactionsByPaymentId(const Crypto::Hash& paymentId, std::vector<TransactionDetails>& transactions, const Callback& callback) = 0;
virtual void getPoolTransactions(uint64_t timestampBegin, uint64_t timestampEnd, uint32_t transactionsNumberLimit, std::vector<TransactionDetails>& transactions, uint64_t& transactionsNumberWithinTimestamps, const Callback& callback) = 0;
virtual void isSynchronized(bool& syncStatus, const Callback& callback) = 0;
virtual std::string feeAddress() const = 0;
};
}