Changeset View
Changeset View
Standalone View
Standalone View
src/blockencodings.h
Show First 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITE(blockhash); | READWRITE(blockhash); | ||||
uint64_t txn_size = (uint64_t)txn.size(); | uint64_t txn_size = (uint64_t)txn.size(); | ||||
READWRITE(COMPACTSIZE(txn_size)); | READWRITE(COMPACTSIZE(txn_size)); | ||||
if (ser_action.ForRead()) { | if (ser_action.ForRead()) { | ||||
size_t i = 0; | size_t i = 0; | ||||
while (txn.size() < txn_size) { | while (txn.size() < txn_size) { | ||||
txn.resize(std::min(uint64_t(1000 + txn.size()), txn_size)); | txn.resize(std::min(uint64_t(1000 + txn.size()), txn_size)); | ||||
for (; i < txn.size(); i++) { | for (; i < txn.size(); i++) { | ||||
READWRITE(REF(TransactionCompressor(txn[i]))); | READWRITE(TransactionCompressor(txn[i])); | ||||
} | } | ||||
} | } | ||||
} else { | } else { | ||||
for (size_t i = 0; i < txn.size(); i++) { | for (size_t i = 0; i < txn.size(); i++) { | ||||
READWRITE(REF(TransactionCompressor(txn[i]))); | READWRITE(TransactionCompressor(txn[i])); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
// Dumb serialization/storage-helper for CBlockHeaderAndShortTxIDs and | // Dumb serialization/storage-helper for CBlockHeaderAndShortTxIDs and | ||||
// PartiallyDownloadedBlock | // PartiallyDownloadedBlock | ||||
struct PrefilledTransaction { | struct PrefilledTransaction { | ||||
// Used as an offset since last prefilled tx in CBlockHeaderAndShortTxIDs, | // Used as an offset since last prefilled tx in CBlockHeaderAndShortTxIDs, | ||||
// as a proper transaction-in-block-index in PartiallyDownloadedBlock | // as a proper transaction-in-block-index in PartiallyDownloadedBlock | ||||
uint32_t index; | uint32_t index; | ||||
CTransactionRef tx; | CTransactionRef tx; | ||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
uint64_t n = index; | uint64_t n = index; | ||||
READWRITE(COMPACTSIZE(n)); | READWRITE(COMPACTSIZE(n)); | ||||
if (n > std::numeric_limits<uint32_t>::max()) { | if (n > std::numeric_limits<uint32_t>::max()) { | ||||
throw std::ios_base::failure("index overflowed 32-bits"); | throw std::ios_base::failure("index overflowed 32-bits"); | ||||
} | } | ||||
index = n; | index = n; | ||||
READWRITE(REF(TransactionCompressor(tx))); | READWRITE(TransactionCompressor(tx)); | ||||
} | } | ||||
}; | }; | ||||
typedef enum ReadStatus_t { | typedef enum ReadStatus_t { | ||||
READ_STATUS_OK, | READ_STATUS_OK, | ||||
// Invalid object, peer is sending bogus crap. | // Invalid object, peer is sending bogus crap. | ||||
// FIXME: differenciate bogus crap from crap that do not fit our policy. | // FIXME: differenciate bogus crap from crap that do not fit our policy. | ||||
READ_STATUS_INVALID, | READ_STATUS_INVALID, | ||||
▲ Show 20 Lines • Show All 100 Lines • Show Last 20 Lines |