Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
Compact serializer for scripts. More...
#include <compressor.h>
Public Member Functions | |
CScriptCompressor (CScript &scriptIn) | |
template<typename Stream > | |
void | Serialize (Stream &s) const |
template<typename Stream > | |
void | Unserialize (Stream &s) |
Protected Member Functions | |
bool | IsToKeyID (CKeyID &hash) const |
These check for scripts for which a special case with a shorter encoding is defined. More... | |
bool | IsToScriptID (CScriptID &hash) const |
bool | IsToPubKey (CPubKey &pubkey) const |
bool | Compress (std::vector< unsigned char > &out) const |
unsigned int | GetSpecialSize (unsigned int nSize) const |
bool | Decompress (unsigned int nSize, const std::vector< unsigned char > &out) |
Private Attributes | |
CScript & | script |
Static Private Attributes | |
static const unsigned int | nSpecialScripts = 6 |
make this static for now (there are only 6 special scripts defined) this can potentially be extended together with a new nVersion for transactions, in which case this value becomes dependent on nVersion and nHeight of the enclosing transaction. More... | |
Detailed Description
Compact serializer for scripts.
It detects common cases and encodes them much more efficiently. 3 special cases are defined:
- Pay to pubkey hash (encoded as 21 bytes)
- Pay to script hash (encoded as 21 bytes)
- Pay to pubkey starting with 0x02, 0x03 or 0x04 (encoded as 33 bytes)
Other scripts up to 121 bytes require 1 byte + script length. Above that, scripts up to 16505 bytes require 2 bytes + script length.
Definition at line 28 of file compressor.h.
Constructor & Destructor Documentation
◆ CScriptCompressor()
|
inlineexplicit |
Definition at line 56 of file compressor.h.
Member Function Documentation
◆ Compress()
|
protected |
Definition at line 48 of file compressor.cpp.
References IsToKeyID(), IsToPubKey(), IsToScriptID(), and memcpy().
Referenced by Serialize().
◆ Decompress()
|
protected |
Definition at line 88 of file compressor.cpp.
References prevector< N, T, Size, Diff >::begin(), prevector< N, T, Size, Diff >::data(), memcpy(), OP_CHECKSIG, OP_DUP, OP_EQUAL, OP_EQUALVERIFY, OP_HASH160, prevector< N, T, Size, Diff >::resize(), and script.
Referenced by Unserialize().
◆ GetSpecialSize()
|
protected |
Definition at line 79 of file compressor.cpp.
Referenced by Unserialize().
◆ IsToKeyID()
|
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).
Definition at line 12 of file compressor.cpp.
References memcpy(), OP_CHECKSIG, OP_DUP, OP_EQUALVERIFY, OP_HASH160, script, and prevector< N, T, Size, Diff >::size().
Referenced by Compress().
◆ IsToPubKey()
|
protected |
Definition at line 33 of file compressor.cpp.
References CPubKey::IsFullyValid(), OP_CHECKSIG, script, CPubKey::Set(), and prevector< N, T, Size, Diff >::size().
Referenced by Compress().
◆ IsToScriptID()
|
protected |
Definition at line 23 of file compressor.cpp.
References memcpy(), OP_EQUAL, OP_HASH160, script, and prevector< N, T, Size, Diff >::size().
Referenced by Compress().
◆ Serialize()
|
inline |
Definition at line 59 of file compressor.h.
References Compress(), nSpecialScripts, script, prevector< N, T, Size, Diff >::size(), and VARINT.
◆ Unserialize()
|
inline |
Definition at line 71 of file compressor.h.
References Decompress(), GetSpecialSize(), MAX_SCRIPT_SIZE, nSpecialScripts, OP_RETURN, REF(), prevector< N, T, Size, Diff >::resize(), script, and VARINT.
Member Data Documentation
◆ nSpecialScripts
|
staticprivate |
make this static for now (there are only 6 special scripts defined) this can potentially be extended together with a new nVersion for transactions, in which case this value becomes dependent on nVersion and nHeight of the enclosing transaction.
Definition at line 37 of file compressor.h.
Referenced by Serialize(), and Unserialize().
◆ script
|
private |
Definition at line 39 of file compressor.h.
Referenced by Decompress(), IsToKeyID(), IsToPubKey(), IsToScriptID(), Serialize(), and Unserialize().
The documentation for this class was generated from the following files:
- src/compressor.h
- src/compressor.cpp