6 #ifndef RAVEN_BLOCK_ENCODINGS_H 7 #define RAVEN_BLOCK_ENCODINGS_H 25 template <
typename Stream,
typename Operation>
39 template <
typename Stream,
typename Operation>
42 uint64_t indexes_size = (uint64_t)indexes.size();
44 if (ser_action.ForRead()) {
46 while (indexes.size() < indexes_size) {
47 indexes.resize(std::min((uint64_t)(1000 + indexes.size()), indexes_size));
48 for (; i < indexes.size(); i++) {
51 if (index > std::numeric_limits<uint16_t>::max())
52 throw std::ios_base::failure(
"index overflowed 16 bits");
58 for (
size_t j = 0; j < indexes.size(); j++) {
59 if (uint64_t(indexes[j]) + uint64_t(offset) > std::numeric_limits<uint16_t>::max())
60 throw std::ios_base::failure(
"indexes overflowed 16 bits");
61 indexes[j] = indexes[j] + offset;
62 offset = indexes[j] + 1;
65 for (
size_t i = 0; i < indexes.size(); i++) {
66 uint64_t index = indexes[i] - (i == 0 ? 0 : (indexes[i - 1] + 1));
77 std::vector<CTransactionRef>
txn;
81 blockhash(req.blockhash), txn(req.indexes.size()) {}
85 template <
typename Stream,
typename Operation>
88 uint64_t txn_size = (uint64_t)txn.size();
90 if (ser_action.ForRead()) {
92 while (txn.size() < txn_size) {
93 txn.resize(std::min((uint64_t)(1000 + txn.size()), txn_size));
94 for (; i < txn.size(); i++)
98 for (
size_t i = 0; i < txn.size(); i++)
113 template <
typename Stream,
typename Operation>
115 uint64_t idx = index;
117 if (idx > std::numeric_limits<uint16_t>::max())
118 throw std::ios_base::failure(
"index overflowed 16-bits");
138 void FillShortTxIDSelector()
const;
142 static const int SHORTTXIDS_LENGTH = 6;
155 uint64_t GetShortID(
const uint256& txhash)
const;
157 size_t BlockTxCount()
const {
return shorttxids.size() + prefilledtxn.size(); }
161 template <
typename Stream,
typename Operation>
166 uint64_t shorttxids_size = (uint64_t)shorttxids.size();
168 if (ser_action.ForRead()) {
170 while (shorttxids.size() < shorttxids_size) {
171 shorttxids.resize(std::min((uint64_t)(1000 + shorttxids.size()), shorttxids_size));
172 for (; i < shorttxids.size(); i++) {
173 uint32_t lsb = 0; uint16_t msb = 0;
176 shorttxids[i] = (uint64_t(msb) << 32) | uint64_t(lsb);
177 static_assert(SHORTTXIDS_LENGTH == 6,
"shorttxids serialization assumes 6-byte shorttxids");
181 for (
size_t i = 0; i < shorttxids.size(); i++) {
182 uint32_t lsb = shorttxids[i] & 0xffffffff;
183 uint16_t msb = (shorttxids[i] >> 32) & 0xffff;
191 if (ser_action.ForRead())
192 FillShortTxIDSelector();
199 size_t prefilled_count = 0, mempool_count = 0, extra_count = 0;
207 bool IsTxAvailable(
size_t index)
const;
208 ReadStatus FillBlock(
CBlock& block,
const std::vector<CTransactionRef>& vtx_missing);
225 template <
typename Stream,
typename Operation>
enum ReadStatus_t ReadStatus
CBlockHeaderAndShortTxIDs()
std::vector< uint16_t > indexes
std::vector< CTransactionRef > txn_available
BlockTransactions(const BlockTransactionsRequest &req)
PartiallyDownloadedBlock(CTxMemPool *poolIn)
std::shared_ptr< const CTransaction > CTransactionRef
int64_t CAmount
Amount in corbies (Can be negative)
void SerializationOp(Stream &s, Operation ser_action)
TransactionCompressor(CTransactionRef &txIn)
std::vector< CTransactionRef > txn
void SerializationOp(Stream &s, Operation ser_action)
void SerializationOp(Stream &s, Operation ser_action)
void SerializationOp(Stream &s, Operation ser_action)
void SerializationOp(Stream &s, Operation ser_action)
void SerializationOp(Stream &s, Operation ser_action)
std::vector< uint64_t > shorttxids
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
std::vector< PrefilledTransaction > prefilledtxn
size_t BlockTxCount() const
T & REF(const T &val)
Used to bypass the rule against non-const reference to temporary where it makes sense with wrappers s...