From ad850fe78dff05f4188f6035313a5a627026a985 Mon Sep 17 00:00:00 2001 From: Giacomo Caironi <30932677+giacomocaironi@users.noreply.github.com> Date: Tue, 13 Jun 2023 17:39:26 +0200 Subject: [PATCH] Update version (#110) * Fix circular import * Update version * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- HISTORY.md | 8 +++++++- btclib/__init__.py | 2 +- btclib/b32.py | 12 +++--------- btclib/script/__init__.py | 21 +++++++++------------ docs/source/conf.py | 2 +- tests/script/test_script_pub_key.py | 8 ++++---- tests/script/test_taproot.py | 2 +- tests/test_b32.py | 2 +- 8 files changed, 27 insertions(+), 30 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index c6380dd5..b8325dfe 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -5,12 +5,18 @@ Notable changes to the codebase are documented here. Release names follow *[calendar versioning](https://calver.org/)*: full year, short month, short day (YYYY-M-D) -## v2023.3 (work in progress, not released yet) +## v2023.6 (work in progress, not released yet) Major changes include: - TBD +## v2023.5.30 + +Major changes include: + +- Fix circular import between ``script`` and ``b32`` + ## v2023.2.3 Major changes include: diff --git a/btclib/__init__.py b/btclib/__init__.py index 4cc7e2d4..7baecdb4 100644 --- a/btclib/__init__.py +++ b/btclib/__init__.py @@ -11,7 +11,7 @@ """__init__ module for the btclib package.""" name = "btclib" -__version__ = "2023.3" +__version__ = "2023.5.30" __author__ = "The btclib developers" __author_email__ = "devs@btclib.org" __copyright__ = "Copyright (C) 2017-2023 The btclib developers" diff --git a/btclib/b32.py b/btclib/b32.py index 0a337f66..3a204895 100644 --- a/btclib/b32.py +++ b/btclib/b32.py @@ -46,12 +46,11 @@ from typing import Iterable -from btclib.alias import Octets, String, TaprootScriptTree +from btclib.alias import Octets, String from btclib.bech32 import decode, encode from btclib.exceptions import BTClibValueError from btclib.hashes import hash160, sha256 from btclib.network import NETWORKS, network_from_key_value -from btclib.script import output_pubkey from btclib.to_pub_key import Key, pub_keyinfo_from_key from btclib.utils import bytes_from_octets @@ -170,11 +169,6 @@ def p2wsh(script_pub_key: Octets, network: str = "mainnet") -> str: return address_from_witness(0, h256, network) -def p2tr( - internal_key: Key | None = None, - script_path: TaprootScriptTree | None = None, - network: str = "mainnet", -) -> str: +def p2tr(output_key: Octets, network: str = "mainnet") -> str: """Return the p2tr bech32 address corresponding to a taproot output key.""" - pub_key = output_pubkey(internal_key, script_path)[0] - return address_from_witness(1, pub_key, network) + return address_from_witness(1, output_key, network) diff --git a/btclib/script/__init__.py b/btclib/script/__init__.py index 803d59a3..958e5c0a 100644 --- a/btclib/script/__init__.py +++ b/btclib/script/__init__.py @@ -11,17 +11,7 @@ """Module btclib.script.""" from btclib.script.script import Command, Script, op_int, parse, serialize -from btclib.script.taproot import ( - TaprootScriptTree, - check_output_pubkey, - input_script_sig, - output_prvkey, - output_pubkey, -) -from btclib.script.witness import Witness - -# hack to prevent circular import -from btclib.script.script_pub_key import ( # isort:skip +from btclib.script.script_pub_key import ( ScriptPubKey, address, assert_nulldata, @@ -41,7 +31,14 @@ is_p2wsh, type_and_payload, ) - +from btclib.script.taproot import ( + TaprootScriptTree, + check_output_pubkey, + input_script_sig, + output_prvkey, + output_pubkey, +) +from btclib.script.witness import Witness __all__ = [ "Command", diff --git a/docs/source/conf.py b/docs/source/conf.py index 704f75bf..3082d0fc 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -21,7 +21,7 @@ project = "btclib" project_copyright = "2017-2023 The btclib developers" author = "The btclib developers" -release = "2023.3" +release = "2023.5.30" # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration diff --git a/tests/script/test_script_pub_key.py b/tests/script/test_script_pub_key.py index 5d0da262..22cbdbce 100644 --- a/tests/script/test_script_pub_key.py +++ b/tests/script/test_script_pub_key.py @@ -580,13 +580,13 @@ def test_non_standard_script_in_p2wsh() -> None: def test_p2tr() -> None: pub_key = "cc71eb30d653c0c3163990c47b976f3fb3f37cccdcbedb169a1dfef58bbfbfaf" - payload = output_pubkey(pub_key)[0] - script_pub_key = serialize(["OP_1", payload]) + out_pubkey = output_pubkey(pub_key)[0] + script_pub_key = serialize(["OP_1", out_pubkey]) assert_p2tr(script_pub_key) - assert ("p2tr", payload) == type_and_payload(script_pub_key) + assert ("p2tr", out_pubkey) == type_and_payload(script_pub_key) network = "mainnet" - addr = b32.p2tr(pub_key, network=network) + addr = b32.p2tr(out_pubkey, network=network) assert addr == address(script_pub_key, network) assert script_pub_key == ScriptPubKey.from_address(addr).script diff --git a/tests/script/test_taproot.py b/tests/script/test_taproot.py index b1934a79..9862c6b6 100644 --- a/tests/script/test_taproot.py +++ b/tests/script/test_taproot.py @@ -131,7 +131,7 @@ def test_bip_test_vector() -> None: script_tree = convert_script_tree(test["given"]["scriptTree"]) tweaked_pubkey = output_pubkey(f"02{pub_key}", script_tree)[0] - address = b32.p2tr(f"02{pub_key}", script_tree) + address = b32.p2tr(tweaked_pubkey) assert tweaked_pubkey.hex() == test["intermediary"]["tweakedPubkey"] assert address == test["expected"]["bip350Address"] diff --git a/tests/test_b32.py b/tests/test_b32.py index ac7e8f1e..b4cc7d93 100644 --- a/tests/test_b32.py +++ b/tests/test_b32.py @@ -314,7 +314,7 @@ def test_p2wsh() -> None: def test_p2tr() -> None: key = 1 pub_key = output_pubkey(key)[0] - addr = b32.p2tr(key) + addr = b32.p2tr(pub_key) _, wit_prg, _ = b32.witness_from_address(addr) assert wit_prg == pub_key