Bitcoin Core  21.99.0
P2P Digital Currency
Classes | Typedefs | Functions
compressor.h File Reference
#include <prevector.h>
#include <primitives/transaction.h>
#include <script/script.h>
#include <serialize.h>
#include <span.h>
Include dependency graph for compressor.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ScriptCompression
 Compact serializer for scripts. More...
 
struct  AmountCompression
 
struct  TxOutCompression
 wrapper for CTxOut that provides a more compact serialization More...
 

Typedefs

using CompressedScript = prevector< 33, unsigned char >
 This saves us from making many heap allocations when serializing and deserializing compressed scripts. More...
 

Functions

bool CompressScript (const CScript &script, CompressedScript &out)
 
unsigned int GetSpecialScriptSize (unsigned int nSize)
 
bool DecompressScript (CScript &script, unsigned int nSize, const CompressedScript &in)
 
uint64_t CompressAmount (uint64_t nAmount)
 Compress amount. More...
 
uint64_t DecompressAmount (uint64_t nAmount)
 

Typedef Documentation

◆ CompressedScript

using CompressedScript = prevector<33, unsigned char>

This saves us from making many heap allocations when serializing and deserializing compressed scripts.

This prevector size is determined by the largest .resize() in the CompressScript function. The largest compressed script format is a compressed public key, which is 33 bytes.

Definition at line 23 of file compressor.h.

Function Documentation

◆ CompressAmount()

uint64_t CompressAmount ( uint64_t  nAmount)

Compress amount.

nAmount is of type uint64_t and thus cannot be negative. If you're passing in a CAmount (int64_t), make sure to properly handle the case where the amount is negative before calling CompressAmount(...).

Precondition
Function defined only for 0 <= nAmount <= MAX_MONEY.

Definition at line 149 of file compressor.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CompressScript()

bool CompressScript ( const CScript script,
CompressedScript out 
)

Definition at line 55 of file compressor.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DecompressAmount()

uint64_t DecompressAmount ( uint64_t  nAmount)

Definition at line 168 of file compressor.cpp.

Here is the caller graph for this function:

◆ DecompressScript()

bool DecompressScript ( CScript script,
unsigned int  nSize,
const CompressedScript in 
)

Definition at line 95 of file compressor.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetSpecialScriptSize()

unsigned int GetSpecialScriptSize ( unsigned int  nSize)

Definition at line 86 of file compressor.cpp.

Here is the caller graph for this function: