mirror of
https://github.com/bitcoin/bips.git
synced 2026-05-18 16:59:30 +00:00
Merge pull request #2154 from omipheo/bip-0352-typing-return-annotations
BIP352: complete return type annotations in bitcoin_utils
This commit is contained in:
@@ -3,10 +3,10 @@ import struct
|
|||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from ripemd160 import ripemd160
|
from ripemd160 import ripemd160
|
||||||
from secp256k1lab.secp256k1 import Scalar
|
from secp256k1lab.secp256k1 import Scalar
|
||||||
from typing import Union
|
from typing import List, Union
|
||||||
|
|
||||||
|
|
||||||
def from_hex(hex_string):
|
def from_hex(hex_string: str) -> BytesIO:
|
||||||
"""Deserialize from a hex string representation (e.g. from RPC)"""
|
"""Deserialize from a hex string representation (e.g. from RPC)"""
|
||||||
return BytesIO(bytes.fromhex(hex_string))
|
return BytesIO(bytes.fromhex(hex_string))
|
||||||
|
|
||||||
@@ -15,15 +15,15 @@ def ser_uint32(u: int) -> bytes:
|
|||||||
return u.to_bytes(4, "big")
|
return u.to_bytes(4, "big")
|
||||||
|
|
||||||
|
|
||||||
def ser_uint256(u):
|
def ser_uint256(u: int) -> bytes:
|
||||||
return u.to_bytes(32, 'little')
|
return u.to_bytes(32, 'little')
|
||||||
|
|
||||||
|
|
||||||
def deser_uint256(f):
|
def deser_uint256(f: BytesIO) -> int:
|
||||||
return int.from_bytes(f.read(32), 'little')
|
return int.from_bytes(f.read(32), 'little')
|
||||||
|
|
||||||
|
|
||||||
def deser_txid(txid: str):
|
def deser_txid(txid: str) -> bytes:
|
||||||
# recall that txids are serialized little-endian, but displayed big-endian
|
# recall that txids are serialized little-endian, but displayed big-endian
|
||||||
# this means when converting from a human readable hex txid, we need to first
|
# this means when converting from a human readable hex txid, we need to first
|
||||||
# reverse it before deserializing it
|
# reverse it before deserializing it
|
||||||
@@ -31,7 +31,7 @@ def deser_txid(txid: str):
|
|||||||
return bytes.fromhex(dixt)
|
return bytes.fromhex(dixt)
|
||||||
|
|
||||||
|
|
||||||
def deser_compact_size(f: BytesIO):
|
def deser_compact_size(f: BytesIO) -> int:
|
||||||
view = f.getbuffer()
|
view = f.getbuffer()
|
||||||
nbytes = view.nbytes
|
nbytes = view.nbytes
|
||||||
view.release()
|
view.release()
|
||||||
@@ -48,12 +48,12 @@ def deser_compact_size(f: BytesIO):
|
|||||||
return nit
|
return nit
|
||||||
|
|
||||||
|
|
||||||
def deser_string(f: BytesIO):
|
def deser_string(f: BytesIO) -> bytes:
|
||||||
nit = deser_compact_size(f)
|
nit = deser_compact_size(f)
|
||||||
return f.read(nit)
|
return f.read(nit)
|
||||||
|
|
||||||
|
|
||||||
def deser_string_vector(f: BytesIO):
|
def deser_string_vector(f: BytesIO) -> List[bytes]:
|
||||||
nit = deser_compact_size(f)
|
nit = deser_compact_size(f)
|
||||||
r = []
|
r = []
|
||||||
for _ in range(nit):
|
for _ in range(nit):
|
||||||
|
|||||||
Reference in New Issue
Block a user