Direct follow-up to PR #2154 (which annotated the free-function half
of bip-0352/bitcoin_utils.py) and 2f7117c ("BIP352: fix Any typing").
The four classes in this file — COutPoint, VinInfo, CScriptWitness,
and CTxInWitness — still had unannotated `__init__`, `serialize`,
`deserialize`, and `is_null` methods. mypy could not flow types
through the surrounding reference.py code that constructs and passes
these objects.
Annotate every method on all four classes:
- COutPoint: __init__ (hash, n), serialize -> bytes, deserialize -> None
- VinInfo: __init__ (typed Optional defaults for the three
construct-on-None fields)
- CScriptWitness: __init__ -> None, is_null -> bool, plus an inline
stack: List[bytes] declaration matching what the
rest of the file already assumes
- CTxInWitness: __init__ -> None, deserialize -> "CTxInWitness"
(forward ref since it returns self), is_null -> bool
Adds Optional to the existing typing import (List was already added
by #2154). No behavior changes.
Verified: mypy --ignore-missing-imports ./bip-0352/bitcoin_utils.py
reports "Success: no issues found in 1 source file"; round-trip
smoke tests on COutPoint serialize/deserialize, CScriptWitness
is_null with empty + non-empty stack, CTxInWitness deserialize
returning self, and VinInfo default-construction all match the
pre-change behavior.
The serialization helpers in bip-0352/bitcoin_utils.py were partially
typed: ser_uint32, hash160, is_p2tr, is_p2wpkh, is_p2sh and is_p2pkh
already declare argument and return types, but the surrounding
from_hex / ser_uint256 / deser_uint256 / deser_txid / deser_compact_size
/ deser_string / deser_string_vector helpers omit them.
Annotate the missing return types (and fill in the obvious argument
types) so the file is consistent and so static analysis can flow types
through callers in reference.py. No behavior changes.