Skip to content

Commit 1e20298

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent a4952de commit 1e20298

File tree

10 files changed

+55
-46
lines changed

10 files changed

+55
-46
lines changed

btclib/bip32/key_origin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def decode_hd_key_paths(map_: Mapping[Octets, BIP32KeyOrigin] | None) -> HdKeyPa
138138

139139

140140
def encode_to_bip32_derivs(
141-
hd_key_paths: Mapping[bytes, BIP32KeyOrigin]
141+
hd_key_paths: Mapping[bytes, BIP32KeyOrigin],
142142
) -> list[_BIP32Deriv]:
143143
"""Return the json representation of the dataclass element."""
144144
return [
@@ -152,7 +152,7 @@ def encode_to_bip32_derivs(
152152

153153

154154
def _decode_from_bip32_deriv(
155-
bip32_deriv: Mapping[str, str]
155+
bip32_deriv: Mapping[str, str],
156156
) -> tuple[bytes, BIP32KeyOrigin]:
157157
# FIXME remove size checks to allow
158158
# the instantiation of invalid master_fingerprint and pub_key

btclib/psbt/psbt_in.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def _deserialize_final_script_witness(k: bytes, v: bytes) -> Witness:
126126

127127

128128
def _assert_valid_ripemd160_preimages(
129-
ripemd160_preimages: Mapping[bytes, bytes]
129+
ripemd160_preimages: Mapping[bytes, bytes],
130130
) -> None:
131131
for h, preimage in ripemd160_preimages.items():
132132
if ripemd160(preimage) != h:
@@ -200,8 +200,9 @@ def __init__(
200200
taproot_key_spend_signature: Octets = b"",
201201
taproot_script_spend_signatures: Mapping[Octets, Octets] | None = None,
202202
taproot_leaf_scripts: Mapping[Octets, tuple[Octets, int]] | None = None,
203-
taproot_hd_key_paths: Mapping[Octets, tuple[list[Octets], BIP32KeyOrigin]]
204-
| None = None,
203+
taproot_hd_key_paths: (
204+
Mapping[Octets, tuple[list[Octets], BIP32KeyOrigin]] | None
205+
) = None,
205206
taproot_internal_key: Octets = b"",
206207
taproot_merkle_root: Octets = b"",
207208
unknown: Mapping[Octets, Octets] | None = None,
@@ -283,12 +284,12 @@ def to_dict(self, check_validity: bool = True) -> dict[str, Any]:
283284
self.assert_valid()
284285

285286
return {
286-
"non_witness_utxo": self.non_witness_utxo.to_dict(False)
287-
if self.non_witness_utxo
288-
else None,
289-
"witness_utxo": self.witness_utxo.to_dict(False)
290-
if self.witness_utxo
291-
else None,
287+
"non_witness_utxo": (
288+
self.non_witness_utxo.to_dict(False) if self.non_witness_utxo else None
289+
),
290+
"witness_utxo": (
291+
self.witness_utxo.to_dict(False) if self.witness_utxo else None
292+
),
292293
"partial_signatures": encode_dict_bytes_bytes(self.partial_sigs),
293294
"sig_hash": self.sig_hash_type,
294295
# TODO make it { "asm": "", "hex": "" }
@@ -327,12 +328,16 @@ def from_dict(
327328
decode_from_bip32_derivs(dict_["taproot_hd_key_paths"]),
328329
)
329330
return cls(
330-
Tx.from_dict(dict_["non_witness_utxo"], False)
331-
if dict_["non_witness_utxo"]
332-
else None,
333-
TxOut.from_dict(dict_["witness_utxo"], False)
334-
if dict_["witness_utxo"]
335-
else None,
331+
(
332+
Tx.from_dict(dict_["non_witness_utxo"], False)
333+
if dict_["non_witness_utxo"]
334+
else None
335+
),
336+
(
337+
TxOut.from_dict(dict_["witness_utxo"], False)
338+
if dict_["witness_utxo"]
339+
else None
340+
),
336341
dict_["partial_signatures"],
337342
dict_["sig_hash"],
338343
dict_["redeem_script"],

btclib/psbt/psbt_out.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ def __init__(
8080
hd_key_paths: Mapping[Octets, BIP32KeyOrigin] | None = None,
8181
taproot_internal_key: Octets = b"",
8282
taproot_tree: Sequence[tuple[int, int, Octets]] | None = None,
83-
taproot_hd_key_paths: Mapping[Octets, tuple[list[bytes], BIP32KeyOrigin]]
84-
| None = None,
83+
taproot_hd_key_paths: (
84+
Mapping[Octets, tuple[list[bytes], BIP32KeyOrigin]] | None
85+
) = None,
8586
unknown: Mapping[Octets, Octets] | None = None,
8687
check_validity: bool = True,
8788
) -> None:

btclib/psbt/psbt_utils.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def serialize_dict_bytes_bytes(
9696

9797

9898
def encode_leaf_scripts(
99-
dict_: Mapping[bytes, tuple[bytes, int]]
99+
dict_: Mapping[bytes, tuple[bytes, int]],
100100
) -> dict[str, tuple[str, int]]:
101101
"""Return the json representation of a tap_leaf_script.
102102
@@ -107,7 +107,7 @@ def encode_leaf_scripts(
107107

108108

109109
def decode_leaf_scripts(
110-
map_: Mapping[Octets, tuple[Octets, int]] | None
110+
map_: Mapping[Octets, tuple[Octets, int]] | None,
111111
) -> dict[bytes, tuple[bytes, int]]:
112112
"""Return a tap_leaf_script from its json representation."""
113113
if map_ is None:
@@ -136,7 +136,7 @@ def parse_leaf_script(v: bytes) -> tuple[bytes, int]:
136136

137137

138138
def encode_taproot_tree(
139-
list_: list[tuple[int, int, bytes]]
139+
list_: list[tuple[int, int, bytes]],
140140
) -> list[tuple[int, int, str]]:
141141
"""Return the json representation of a tap_tree.
142142
@@ -146,7 +146,7 @@ def encode_taproot_tree(
146146

147147

148148
def decode_taproot_tree(
149-
list_: Sequence[tuple[int, int, Octets]] | None
149+
list_: Sequence[tuple[int, int, Octets]] | None,
150150
) -> list[tuple[int, int, bytes]]:
151151
"""Return a tap_tree from its json representation."""
152152
if list_ is None:
@@ -184,7 +184,7 @@ def parse_taproot_tree(v: bytes) -> list[tuple[int, int, bytes]]:
184184

185185

186186
def taproot_bip32_to_dict(
187-
taproot_hd_key_paths: dict[bytes, tuple[list[bytes], BIP32KeyOrigin]]
187+
taproot_hd_key_paths: dict[bytes, tuple[list[bytes], BIP32KeyOrigin]],
188188
) -> list[dict[str, Any]]:
189189
"""Return the json representation of a tap_bip32_derivation.
190190
@@ -203,7 +203,7 @@ def taproot_bip32_to_dict(
203203

204204

205205
def taproot_bip32_from_dict(
206-
taproot_hd_key_paths: list[dict[str, str]]
206+
taproot_hd_key_paths: list[dict[str, str]],
207207
) -> dict[bytes, tuple[list[bytes], BIP32KeyOrigin]]:
208208
"""Return a tap_bip32_derivation from its json representation."""
209209
return {
@@ -219,7 +219,7 @@ def taproot_bip32_from_dict(
219219

220220

221221
def decode_taproot_bip32(
222-
dict_: Mapping[Octets, tuple[Sequence[Octets], BIP32KeyOrigin]] | None
222+
dict_: Mapping[Octets, tuple[Sequence[Octets], BIP32KeyOrigin]] | None,
223223
) -> dict[bytes, tuple[list[bytes], BIP32KeyOrigin]]:
224224
"""Parse correctly the tap_bip32_derivation init arguments."""
225225
if dict_ is None:
@@ -315,7 +315,7 @@ def assert_valid_taproot_tree(tree: list[tuple[int, int, bytes]]) -> None:
315315

316316

317317
def assert_valid_taproot_bip32_derivation(
318-
derivations: dict[bytes, tuple[list[bytes], BIP32KeyOrigin]]
318+
derivations: dict[bytes, tuple[list[bytes], BIP32KeyOrigin]],
319319
) -> None:
320320
"""Fails when the public keys have not the correct length."""
321321
for pubkey in derivations:

btclib/tx/tx.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,14 @@ def serialize(self, include_witness: bool, check_validity: bool = True) -> bytes
224224
b"".join(tx_in.serialize(check_validity) for tx_in in self.vin),
225225
var_int.serialize(len(self.vout)),
226226
b"".join(tx_out.serialize(check_validity) for tx_out in self.vout),
227-
b"".join(
228-
tx_in.script_witness.serialize(check_validity) for tx_in in self.vin
229-
)
230-
if segwit
231-
else b"",
227+
(
228+
b"".join(
229+
tx_in.script_witness.serialize(check_validity)
230+
for tx_in in self.vin
231+
)
232+
if segwit
233+
else b""
234+
),
232235
self.lock_time.to_bytes(4, byteorder="little", signed=False),
233236
]
234237
)

btclib/var_int.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ def serialize(i: int) -> bytes:
5858
if i < 0xFD: # 1 byte
5959
return bytes([i])
6060
if i <= 0xFFFF: # 2 bytes
61-
return b"\xFD" + i.to_bytes(2, byteorder="little", signed=False)
61+
return b"\xfd" + i.to_bytes(2, byteorder="little", signed=False)
6262
if i <= 0xFFFFFFFF: # 4 bytes
63-
return b"\xFE" + i.to_bytes(4, byteorder="little", signed=False)
63+
return b"\xfe" + i.to_bytes(4, byteorder="little", signed=False)
6464
if i <= 0xFFFFFFFFFFFFFFFF: # 8 bytes
65-
return b"\xFF" + i.to_bytes(8, byteorder="little", signed=False)
65+
return b"\xff" + i.to_bytes(8, byteorder="little", signed=False)
6666
raise BTClibValueError(f"integer too big for var_int encoding: '{hex_string(i)}'")

tests/bip32/test_bip32.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_exceptions() -> None:
4444

4545
seed = "5b56c417303faa3fcba7e57400e120a0"
4646
with pytest.raises(BTClibValueError, match="unknown extended key version: "):
47-
version = b"\x04\x88\xAD\xE5"
47+
version = b"\x04\x88\xad\xe5"
4848
rootxprv_from_seed(seed, version)
4949

5050
with pytest.raises(BTClibValueError, match="too many bits for seed: "):

tests/script/test_script.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ def test_op_int() -> None:
6060

6161
def test_serialize_bytes_command() -> None:
6262
length = 75
63-
b = b"\x0A" * length
63+
b = b"\x0a" * length
6464
assert len(serialize([b])) == length + 1
65-
b = b"\x0A" * (length + 1)
65+
b = b"\x0a" * (length + 1)
6666
assert len(serialize([b])) == (length + 1) + 2
6767

6868
length = 255
69-
b = b"\x0A" * length
69+
b = b"\x0a" * length
7070
assert len(serialize([b])) == length + 2
71-
b = b"\x0A" * (length + 1)
71+
b = b"\x0a" * (length + 1)
7272
assert len(serialize([b])) == (length + 1) + 3
7373

7474

tests/script/test_taproot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ def test_serialize_op_success() -> None:
145145

146146
def test_serialize_bytes_command() -> None:
147147
length = 75
148-
b = b"\x0A" * length
148+
b = b"\x0a" * length
149149
assert len(serialize([b])) == length + 1
150-
b = b"\x0A" * (length + 1)
150+
b = b"\x0a" * (length + 1)
151151
assert len(serialize([b])) == (length + 1) + 2
152152

153153
length = 255
154-
b = b"\x0A" * length
154+
b = b"\x0a" * length
155155
assert len(serialize([b])) == length + 2
156-
b = b"\x0A" * (length + 1)
156+
b = b"\x0a" * (length + 1)
157157
assert len(serialize([b])) == (length + 1) + 3
158158

159159

tests/test_bech32.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def test_bech32() -> None:
7272

7373
invalid_checksum = [
7474
["\x20" + " 1nwldj5", r"HRP character out of range: *"],
75-
["\x7F" + "1axkwrx", r"HRP character out of range: *"],
75+
["\x7f" + "1axkwrx", r"HRP character out of range: *"],
7676
["\x80" + "1eym55h", r"HRP character out of range: *"],
7777
["pzry9x0s0muk", r"no separator character: *"],
7878
["1pzry9x0s0muk", r"empty HRP: *"],
@@ -129,7 +129,7 @@ def test_bech32m() -> None:
129129

130130
invalid_checksum = [
131131
["\x20" + "1xj0phk", r"HRP character out of range: *"],
132-
["\x7F" + "1g6xzxy", r"HRP character out of range: *"],
132+
["\x7f" + "1g6xzxy", r"HRP character out of range: *"],
133133
["\x80" + "1vctc34", r"HRP character out of range: *"],
134134
["qyrz8wqd2c9m", r"no separator character: *"],
135135
["1qyrz8wqd2c9m", r"empty HRP: *"],

0 commit comments

Comments
 (0)