Changeset View
Changeset View
Standalone View
Standalone View
src/blockencodings.h
// Copyright (c) 2016 The Bitcoin Core developers | // Copyright (c) 2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_BLOCKENCODINGS_H | #ifndef BITCOIN_BLOCKENCODINGS_H | ||||
#define BITCOIN_BLOCKENCODINGS_H | #define BITCOIN_BLOCKENCODINGS_H | ||||
#include <primitives/block.h> | #include <primitives/block.h> | ||||
#include <serialize.h> | |||||
class Config; | class Config; | ||||
class CTxMemPool; | class CTxMemPool; | ||||
// Transaction compression schemes for compact block relay can be introduced by | // Transaction compression schemes for compact block relay can be introduced by | ||||
// writing an actual formatter here. | // writing an actual formatter here. | ||||
using TransactionCompression = DefaultFormatter; | using TransactionCompression = DefaultFormatter; | ||||
class DifferenceFormatter { | |||||
uint64_t m_shift = 0; | |||||
public: | |||||
template <typename Stream, typename I> void Ser(Stream &s, I v) { | |||||
if (v < m_shift || v >= std::numeric_limits<uint64_t>::max()) { | |||||
throw std::ios_base::failure("differential value overflow"); | |||||
} | |||||
WriteCompactSize(s, v - m_shift); | |||||
m_shift = uint64_t(v) + 1; | |||||
} | |||||
template <typename Stream, typename I> void Unser(Stream &s, I &v) { | |||||
uint64_t n = ReadCompactSize(s); | |||||
m_shift += n; | |||||
if (m_shift < n || m_shift >= std::numeric_limits<uint64_t>::max() || | |||||
m_shift < std::numeric_limits<I>::min() || | |||||
m_shift > std::numeric_limits<I>::max()) { | |||||
throw std::ios_base::failure("differential value overflow"); | |||||
} | |||||
v = I(m_shift++); | |||||
} | |||||
}; | |||||
class BlockTransactionsRequest { | class BlockTransactionsRequest { | ||||
public: | public: | ||||
// A BlockTransactionsRequest message | // A BlockTransactionsRequest message | ||||
BlockHash blockhash; | BlockHash blockhash; | ||||
std::vector<uint32_t> indices; | std::vector<uint32_t> indices; | ||||
SERIALIZE_METHODS(BlockTransactionsRequest, obj) { | SERIALIZE_METHODS(BlockTransactionsRequest, obj) { | ||||
READWRITE(obj.blockhash, | READWRITE(obj.blockhash, | ||||
▲ Show 20 Lines • Show All 112 Lines • Show Last 20 Lines |