aboutsummaryrefslogtreecommitdiff
path: root/src/main.h
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-06-15 18:52:19 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2012-10-20 23:08:56 +0200
commit69fc8047a9a96bcf5360f810c796049c27e16fcd (patch)
treeb800ff10cf08779f8e7e7e6f9aa0588452bb6885 /src/main.h
parent4d6144f97faf9d2a6c89f41d7d2360f21f0b71e2 (diff)
Compact serialization for scripts
Special serializers for script which detect common cases and encode 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.
Diffstat (limited to 'src/main.h')
-rw-r--r--src/main.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/main.h b/src/main.h
index ea71baf902..1af781f45c 100644
--- a/src/main.h
+++ b/src/main.h
@@ -647,6 +647,20 @@ protected:
const CTxOut& GetOutputFor(const CTxIn& input, const MapPrevTx& inputs) const;
};
+/** wrapper for CTxOut that provides a more compact serialization */
+class CTxOutCompressor
+{
+private:
+ CTxOut &txout;
+public:
+ CTxOutCompressor(CTxOut &txoutIn) : txout(txoutIn) { }
+
+ IMPLEMENT_SERIALIZE(
+ READWRITE(VARINT(txout.nValue));
+ CScriptCompressor cscript(REF(txout.scriptPubKey));
+ READWRITE(cscript);
+ )
+};