Changeset View
Changeset View
Standalone View
Standalone View
src/compressor.h
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | protected: | ||||
bool IsToScriptID(CScriptID &hash) const; | bool IsToScriptID(CScriptID &hash) const; | ||||
bool IsToPubKey(CPubKey &pubkey) const; | bool IsToPubKey(CPubKey &pubkey) const; | ||||
bool Compress(std::vector<uint8_t> &out) const; | bool Compress(std::vector<uint8_t> &out) const; | ||||
unsigned int GetSpecialSize(unsigned int nSize) const; | unsigned int GetSpecialSize(unsigned int nSize) const; | ||||
bool Decompress(unsigned int nSize, const std::vector<uint8_t> &out); | bool Decompress(unsigned int nSize, const std::vector<uint8_t> &out); | ||||
public: | public: | ||||
CScriptCompressor(CScript &scriptIn) : script(scriptIn) {} | explicit CScriptCompressor(CScript &scriptIn) : script(scriptIn) {} | ||||
template <typename Stream> void Serialize(Stream &s) const { | template <typename Stream> void Serialize(Stream &s) const { | ||||
std::vector<uint8_t> compr; | std::vector<uint8_t> compr; | ||||
if (Compress(compr)) { | if (Compress(compr)) { | ||||
s << CFlatData(compr); | s << CFlatData(compr); | ||||
return; | return; | ||||
} | } | ||||
unsigned int nSize = script.size() + nSpecialScripts; | unsigned int nSize = script.size() + nSpecialScripts; | ||||
Show All 26 Lines | |||||
class CTxOutCompressor { | class CTxOutCompressor { | ||||
private: | private: | ||||
CTxOut &txout; | CTxOut &txout; | ||||
public: | public: | ||||
static uint64_t CompressAmount(Amount nAmount); | static uint64_t CompressAmount(Amount nAmount); | ||||
static Amount DecompressAmount(uint64_t nAmount); | static Amount DecompressAmount(uint64_t nAmount); | ||||
CTxOutCompressor(CTxOut &txoutIn) : txout(txoutIn) {} | explicit CTxOutCompressor(CTxOut &txoutIn) : txout(txoutIn) {} | ||||
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) { | ||||
if (!ser_action.ForRead()) { | if (!ser_action.ForRead()) { | ||||
uint64_t nVal = CompressAmount(txout.nValue); | uint64_t nVal = CompressAmount(txout.nValue); | ||||
READWRITE(VARINT(nVal)); | READWRITE(VARINT(nVal)); | ||||
Show All 11 Lines |