aboutsummaryrefslogtreecommitdiff
path: root/src/main.h
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-06-16 13:36:00 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2012-10-20 23:08:56 +0200
commit0fa593d0fb3a6f731a31610e98ce6bfd6a50a96c (patch)
treee7c296456e910c22bf09dceee3291f6a30fa3c50 /src/main.h
parent69fc8047a9a96bcf5360f810c796049c27e16fcd (diff)
downloadbitcoin-0fa593d0fb3a6f731a31610e98ce6bfd6a50a96c.tar.xz
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.
Diffstat (limited to 'src/main.h')
-rw-r--r--src/main.h17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/main.h b/src/main.h
index 1af781f45c..4286880c9f 100644
--- a/src/main.h
+++ b/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);
- )
+ });)
};