Crate bitcoin_compressor
source ·Structs
| Compact serializer for scripts.
|
| It detects common cases and encodes
| 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.
|
| wrapper for CTxOut that provides a more
| compact serialization
|
Constants
| make this static for now (there are only
| 6 special scripts defined) this can
| potentially be extended together with
| a new nVersion for transactions, in
| which case this value becomes dependent
| on nVersion and nHeight of the enclosing
| transaction.
|
Functions
| 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(…).
|
| @pre Function defined only for 0 <=
| nAmount <= MAX_MONEY.
|
| These check for scripts for which a special
| case with a shorter encoding is defined.
|
| They are implemented separately from
| the
|
| CScript test, as these test for exact
| byte sequence correspondences, and
| are more strict. For example, IsToPubKey
| also verifies whether the public key
| is valid (as invalid ones cannot be represented
| in compressed form).
|
Type Definitions
| 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.
|