From 76a9aacd3fb75d5e0854e53bb3376f2ab603a561 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sat, 8 Jul 2017 16:43:34 -0700 Subject: Move compressor utility functions out of class --- src/compressor.h | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) (limited to 'src/compressor.h') diff --git a/src/compressor.h b/src/compressor.h index 6fcecd27e9..561c8e66d0 100644 --- a/src/compressor.h +++ b/src/compressor.h @@ -14,6 +14,13 @@ class CKeyID; class CPubKey; class CScriptID; +bool CompressScript(const CScript& script, std::vector &out); +unsigned int GetSpecialScriptSize(unsigned int nSize); +bool DecompressScript(CScript& script, unsigned int nSize, const std::vector &out); + +uint64_t CompressAmount(uint64_t nAmount); +uint64_t DecompressAmount(uint64_t nAmount); + /** Compact serializer for scripts. * * It detects common cases and encodes them much more efficiently. @@ -37,28 +44,13 @@ private: static const unsigned int nSpecialScripts = 6; CScript &script; -protected: - /** - * These check for scripts for which a special case with a shorter encoding is defined. - * They are implemented separately from the CScript test, as these test for exact byte - * sequence correspondences, and are more strict. For example, IsToPubKey also verifies - * whether the public key is valid (as invalid ones cannot be represented in compressed - * form). - */ - bool IsToKeyID(CKeyID &hash) const; - bool IsToScriptID(CScriptID &hash) const; - bool IsToPubKey(CPubKey &pubkey) const; - - bool Compress(std::vector &out) const; - unsigned int GetSpecialSize(unsigned int nSize) const; - bool Decompress(unsigned int nSize, const std::vector &out); public: explicit CScriptCompressor(CScript &scriptIn) : script(scriptIn) { } template void Serialize(Stream &s) const { std::vector compr; - if (Compress(compr)) { + if (CompressScript(script, compr)) { s << CFlatData(compr); return; } @@ -72,9 +64,9 @@ public: unsigned int nSize = 0; s >> VARINT(nSize); if (nSize < nSpecialScripts) { - std::vector vch(GetSpecialSize(nSize), 0x00); + std::vector vch(GetSpecialScriptSize(nSize), 0x00); s >> CFlatData(vch); - Decompress(nSize, vch); + DecompressScript(script, nSize, vch); return; } nSize -= nSpecialScripts; @@ -96,9 +88,6 @@ private: CTxOut &txout; public: - static uint64_t CompressAmount(uint64_t nAmount); - static uint64_t DecompressAmount(uint64_t nAmount); - explicit CTxOutCompressor(CTxOut &txoutIn) : txout(txoutIn) { } ADD_SERIALIZE_METHODS; -- cgit v1.2.3