Compact serialization for amounts
Special serializer/deserializer for amount values. It is optimized for values which have few non-zero digits in decimal representation. Most amounts currently in the txout set take only 1 or 2 bytes to represent.
This commit is contained in:
17
src/main.h
17
src/main.h
@@ -652,14 +652,25 @@ class CTxOutCompressor
|
||||
{
|
||||
private:
|
||||
CTxOut &txout;
|
||||
|
||||
public:
|
||||
static uint64 CompressAmount(uint64 nAmount);
|
||||
static uint64 DecompressAmount(uint64 nAmount);
|
||||
|
||||
CTxOutCompressor(CTxOut &txoutIn) : txout(txoutIn) { }
|
||||
|
||||
IMPLEMENT_SERIALIZE(
|
||||
READWRITE(VARINT(txout.nValue));
|
||||
IMPLEMENT_SERIALIZE(({
|
||||
if (!fRead) {
|
||||
uint64 nVal = CompressAmount(txout.nValue);
|
||||
READWRITE(VARINT(nVal));
|
||||
} else {
|
||||
uint64 nVal = 0;
|
||||
READWRITE(VARINT(nVal));
|
||||
txout.nValue = DecompressAmount(nVal);
|
||||
}
|
||||
CScriptCompressor cscript(REF(txout.scriptPubKey));
|
||||
READWRITE(cscript);
|
||||
)
|
||||
});)
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user