mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 07:28:59 +01:00
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.
This commit is contained in:
14
src/main.h
14
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);
|
||||
)
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user