From c7d0c94a62036bb491bc7fc5d4890d0986410e4b Mon Sep 17 00:00:00 2001 From: schimih Date: Wed, 23 Nov 2022 11:41:09 +0200 Subject: [PATCH 01/15] accept adding the hrp on the Address construct --- erdpy/accounts.py | 5 +++-- erdpy/constants.py | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/erdpy/accounts.py b/erdpy/accounts.py index e3d4ce5b..16f6e2c1 100644 --- a/erdpy/accounts.py +++ b/erdpy/accounts.py @@ -80,14 +80,15 @@ def sign_transaction(self, transaction: ITransaction) -> str: class Address(IAddress): - HRP = "erd" + HRP: str PUBKEY_LENGTH = 32 PUBKEY_STRING_LENGTH = PUBKEY_LENGTH * 2 # hex-encoded BECH32_LENGTH = 62 _value_hex: str - def __init__(self, value: Any): + def __init__(self, value: Any, HRP: str = DEFAULT_HRP): self._value_hex = '' + self.HRP = HRP if not value: return diff --git a/erdpy/constants.py b/erdpy/constants.py index 488d9757..edf1e261 100644 --- a/erdpy/constants.py +++ b/erdpy/constants.py @@ -4,3 +4,4 @@ SC_HEX_PUBKEY_PREFIX_SYSTEM = SC_HEX_PUBKEY_PREFIX + VM_TYPE_SYSTEM + "0" * 30 SC_HEX_PUBKEY_PREFIX_WASM_VM = SC_HEX_PUBKEY_PREFIX + VM_TYPE_WASM_VM DEFAULT_CARGO_TARGET_DIR_NAME = "default_cargo_target" +DEFAULT_HRP = "erd" From c2a13bdd77be82af7c3a9b9b55345425d798c820 Mon Sep 17 00:00:00 2001 From: schimih Date: Wed, 23 Nov 2022 12:38:58 +0200 Subject: [PATCH 02/15] change decode_bech32() return from accounts --- erdpy/accounts.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/erdpy/accounts.py b/erdpy/accounts.py index 16f6e2c1..8c9fa9f0 100644 --- a/erdpy/accounts.py +++ b/erdpy/accounts.py @@ -1,6 +1,6 @@ import logging from pathlib import Path -from typing import Any, Optional +from typing import Any, Optional, Tuple import nacl.signing @@ -80,15 +80,15 @@ def sign_transaction(self, transaction: ITransaction) -> str: class Address(IAddress): - HRP: str + # Default value is "erd" + DEFAULT_HRP = "erd" PUBKEY_LENGTH = 32 PUBKEY_STRING_LENGTH = PUBKEY_LENGTH * 2 # hex-encoded BECH32_LENGTH = 62 - _value_hex: str - def __init__(self, value: Any, HRP: str = DEFAULT_HRP): + def __init__(self, value: Any, hrp: str = DEFAULT_HRP): self._value_hex = '' - self.HRP = HRP + self.hrp = hrp if not value: return @@ -103,7 +103,9 @@ def __init__(self, value: Any, HRP: str = DEFAULT_HRP): elif len(value) == Address.PUBKEY_STRING_LENGTH: self._value_hex = _as_string(value) elif len(value) == Address.BECH32_LENGTH: - self._value_hex = _decode_bech32(value).hex() + hrp, value_hex = _decode_bech32(value) + self.hrp = hrp + self._value_hex = value_hex.hex() else: raise errors.BadAddressFormatError(value) @@ -114,7 +116,7 @@ def hex(self) -> str: def bech32(self) -> str: self._assert_validity() pubkey = self.pubkey() - b32 = bech32.bech32_encode(self.HRP, bech32.convertbits(pubkey, 8, 5)) + b32 = bech32.bech32_encode(self.hrp, bech32.convertbits(pubkey, 8, 5)) assert isinstance(b32, str) return b32 @@ -144,10 +146,8 @@ def _as_string(value): return value.decode("utf-8") -def _decode_bech32(value): +def _decode_bech32(value) -> Tuple[str, bytes]: bech32_string = _as_string(value) hrp, value_bytes = bech32.bech32_decode(bech32_string) - if hrp != Address.HRP: - raise errors.BadAddressFormatError(value) decoded_bytes = bech32.convertbits(value_bytes, 5, 8, False) - return bytearray(decoded_bytes) + return hrp, bytearray(decoded_bytes) From 34041df1f25fbeb65ddc23278503846bd5b95152 Mon Sep 17 00:00:00 2001 From: schimih Date: Wed, 23 Nov 2022 12:46:52 +0200 Subject: [PATCH 03/15] small fixes --- erdpy/CHANGELOG.md | 3 +++ erdpy/accounts.py | 2 +- erdpy/constants.py | 1 - 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/erdpy/CHANGELOG.md b/erdpy/CHANGELOG.md index dc4d1cc4..80754fb5 100644 --- a/erdpy/CHANGELOG.md +++ b/erdpy/CHANGELOG.md @@ -7,6 +7,9 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how ## [Unreleased] - TBD +## [2.0.5] + - [Prepare erdpy for accepting any address hrp]() + ## [2.0.4] - Fix resolving latest release of Github repositories diff --git a/erdpy/accounts.py b/erdpy/accounts.py index 8c9fa9f0..1f968b98 100644 --- a/erdpy/accounts.py +++ b/erdpy/accounts.py @@ -80,7 +80,7 @@ def sign_transaction(self, transaction: ITransaction) -> str: class Address(IAddress): - # Default value is "erd" + # Default hrp value is "erd" DEFAULT_HRP = "erd" PUBKEY_LENGTH = 32 PUBKEY_STRING_LENGTH = PUBKEY_LENGTH * 2 # hex-encoded diff --git a/erdpy/constants.py b/erdpy/constants.py index edf1e261..488d9757 100644 --- a/erdpy/constants.py +++ b/erdpy/constants.py @@ -4,4 +4,3 @@ SC_HEX_PUBKEY_PREFIX_SYSTEM = SC_HEX_PUBKEY_PREFIX + VM_TYPE_SYSTEM + "0" * 30 SC_HEX_PUBKEY_PREFIX_WASM_VM = SC_HEX_PUBKEY_PREFIX + VM_TYPE_WASM_VM DEFAULT_CARGO_TARGET_DIR_NAME = "default_cargo_target" -DEFAULT_HRP = "erd" From ea2afeb910390001ea4754a9e99de7969ba72329 Mon Sep 17 00:00:00 2001 From: schimih Date: Wed, 23 Nov 2022 14:20:16 +0200 Subject: [PATCH 04/15] update erdpy.yml - install libtinfo5 --- .github/workflows/erdpy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/erdpy.yml b/.github/workflows/erdpy.yml index 20501b86..7247a09e 100644 --- a/.github/workflows/erdpy.yml +++ b/.github/workflows/erdpy.yml @@ -49,6 +49,7 @@ jobs: python3 -m pip install --upgrade pip pip3 install -r requirements.txt pip3 install pytest + sudo apt-get install libtinfo5 - name: Set github_api_token run: | mkdir ~/elrondsdk From 5f5f41897ed0129eb4a53aed3496e5bb4edee4dc Mon Sep 17 00:00:00 2001 From: schimih Date: Wed, 23 Nov 2022 14:21:56 +0200 Subject: [PATCH 05/15] fix --- .github/workflows/erdpy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/erdpy.yml b/.github/workflows/erdpy.yml index 7247a09e..700b5201 100644 --- a/.github/workflows/erdpy.yml +++ b/.github/workflows/erdpy.yml @@ -49,7 +49,7 @@ jobs: python3 -m pip install --upgrade pip pip3 install -r requirements.txt pip3 install pytest - sudo apt-get install libtinfo5 + sudo apt install libtinfo5 - name: Set github_api_token run: | mkdir ~/elrondsdk From 05735c73a89850ae9bb12e9bef993e878bd47781 Mon Sep 17 00:00:00 2001 From: schimih Date: Wed, 23 Nov 2022 14:25:26 +0200 Subject: [PATCH 06/15] fix --- .github/workflows/erdpy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/erdpy.yml b/.github/workflows/erdpy.yml index 700b5201..e9145c56 100644 --- a/.github/workflows/erdpy.yml +++ b/.github/workflows/erdpy.yml @@ -49,7 +49,7 @@ jobs: python3 -m pip install --upgrade pip pip3 install -r requirements.txt pip3 install pytest - sudo apt install libtinfo5 + sudo apt update && sudo apt install -y libtinfo5 - name: Set github_api_token run: | mkdir ~/elrondsdk From 91cf9294535860c38fd8b8fb079c7cbf1276e24d Mon Sep 17 00:00:00 2001 From: schimih Date: Wed, 23 Nov 2022 14:36:43 +0200 Subject: [PATCH 07/15] fix --- .github/workflows/erdpy.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/erdpy.yml b/.github/workflows/erdpy.yml index e9145c56..95ec1d51 100644 --- a/.github/workflows/erdpy.yml +++ b/.github/workflows/erdpy.yml @@ -49,7 +49,8 @@ jobs: python3 -m pip install --upgrade pip pip3 install -r requirements.txt pip3 install pytest - sudo apt update && sudo apt install -y libtinfo5 + sudo apt update + sudo apt install -y libtinfo5 - name: Set github_api_token run: | mkdir ~/elrondsdk From c7bcec541a25d6bdfae09a897935afa33660b031 Mon Sep 17 00:00:00 2001 From: schimih Date: Wed, 23 Nov 2022 14:41:22 +0200 Subject: [PATCH 08/15] only ubuntu --- .github/workflows/erdpy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/erdpy.yml b/.github/workflows/erdpy.yml index 95ec1d51..104345ec 100644 --- a/.github/workflows/erdpy.yml +++ b/.github/workflows/erdpy.yml @@ -35,7 +35,7 @@ jobs: strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest] python-version: [3.8] steps: From 869b287d705cdd9b682bd3dc7140d4b86a12673e Mon Sep 17 00:00:00 2001 From: schimih Date: Wed, 23 Nov 2022 14:54:01 +0200 Subject: [PATCH 09/15] add macos and conditional if in yml --- .github/workflows/erdpy.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/erdpy.yml b/.github/workflows/erdpy.yml index 104345ec..84460dbb 100644 --- a/.github/workflows/erdpy.yml +++ b/.github/workflows/erdpy.yml @@ -35,7 +35,7 @@ jobs: strategy: matrix: - os: [ubuntu-latest] + os: [ubuntu-latest, macos-latest] python-version: [3.8] steps: @@ -49,6 +49,9 @@ jobs: python3 -m pip install --upgrade pip pip3 install -r requirements.txt pip3 install pytest + - name: Install libtinfo5 + if: os = "macos-latest" + run: | sudo apt update sudo apt install -y libtinfo5 - name: Set github_api_token From 2577dd40e83903e216fb0dbbfe1b0af946975338 Mon Sep 17 00:00:00 2001 From: schimih Date: Wed, 23 Nov 2022 14:59:06 +0200 Subject: [PATCH 10/15] fix --- .github/workflows/erdpy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/erdpy.yml b/.github/workflows/erdpy.yml index 84460dbb..050cfd1a 100644 --- a/.github/workflows/erdpy.yml +++ b/.github/workflows/erdpy.yml @@ -50,7 +50,7 @@ jobs: pip3 install -r requirements.txt pip3 install pytest - name: Install libtinfo5 - if: os = "macos-latest" + if: ${{ os == "macos-latest" }} run: | sudo apt update sudo apt install -y libtinfo5 From d0ec003ddf33570ecc432b9335c47a1408677e4d Mon Sep 17 00:00:00 2001 From: schimih Date: Wed, 23 Nov 2022 15:03:54 +0200 Subject: [PATCH 11/15] test --- .github/workflows/erdpy.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/erdpy.yml b/.github/workflows/erdpy.yml index 050cfd1a..428a380d 100644 --- a/.github/workflows/erdpy.yml +++ b/.github/workflows/erdpy.yml @@ -49,11 +49,8 @@ jobs: python3 -m pip install --upgrade pip pip3 install -r requirements.txt pip3 install pytest - - name: Install libtinfo5 - if: ${{ os == "macos-latest" }} - run: | - sudo apt update - sudo apt install -y libtinfo5 + - name: echo os + run: echo ${{ matrix.os }} - name: Set github_api_token run: | mkdir ~/elrondsdk From c9376b77240a1475d434a2f0e3cecb538b1134e5 Mon Sep 17 00:00:00 2001 From: schimih Date: Wed, 23 Nov 2022 15:06:16 +0200 Subject: [PATCH 12/15] fix --- .github/workflows/erdpy.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/erdpy.yml b/.github/workflows/erdpy.yml index 428a380d..d917982b 100644 --- a/.github/workflows/erdpy.yml +++ b/.github/workflows/erdpy.yml @@ -49,8 +49,11 @@ jobs: python3 -m pip install --upgrade pip pip3 install -r requirements.txt pip3 install pytest - - name: echo os - run: echo ${{ matrix.os }} + - name: Install libtinfo5 + if: ${{ matrix.os == "macos-latest" }} + run: | + sudo apt update + sudo apt install -y libtinfo5 - name: Set github_api_token run: | mkdir ~/elrondsdk From 7c96898e1009c58a93a0e3344b2381cf176708e3 Mon Sep 17 00:00:00 2001 From: schimih Date: Wed, 23 Nov 2022 15:08:25 +0200 Subject: [PATCH 13/15] fix build --- .github/workflows/erdpy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/erdpy.yml b/.github/workflows/erdpy.yml index d917982b..b352beff 100644 --- a/.github/workflows/erdpy.yml +++ b/.github/workflows/erdpy.yml @@ -50,7 +50,7 @@ jobs: pip3 install -r requirements.txt pip3 install pytest - name: Install libtinfo5 - if: ${{ matrix.os == "macos-latest" }} + if: ${{ matrix.os == 'macos-latest' }} run: | sudo apt update sudo apt install -y libtinfo5 From e385b01ef78fef6fab19e921e969cfbc485e716f Mon Sep 17 00:00:00 2001 From: schimih Date: Wed, 23 Nov 2022 15:11:38 +0200 Subject: [PATCH 14/15] small fix --- .github/workflows/erdpy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/erdpy.yml b/.github/workflows/erdpy.yml index b352beff..f2119145 100644 --- a/.github/workflows/erdpy.yml +++ b/.github/workflows/erdpy.yml @@ -50,7 +50,7 @@ jobs: pip3 install -r requirements.txt pip3 install pytest - name: Install libtinfo5 - if: ${{ matrix.os == 'macos-latest' }} + if: ${{ matrix.os != 'macos-latest' }} run: | sudo apt update sudo apt install -y libtinfo5 From 2cfca73b11ad1abede492f58dc097207be111681 Mon Sep 17 00:00:00 2001 From: schimih Date: Wed, 23 Nov 2022 15:31:27 +0200 Subject: [PATCH 15/15] update changelog --- erdpy/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erdpy/CHANGELOG.md b/erdpy/CHANGELOG.md index 80754fb5..f5a5a364 100644 --- a/erdpy/CHANGELOG.md +++ b/erdpy/CHANGELOG.md @@ -8,7 +8,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how - TBD ## [2.0.5] - - [Prepare erdpy for accepting any address hrp]() + - [Prepare erdpy for accepting any address hrp](https://github.com/ElrondNetwork/elrond-sdk-erdpy/pull/158) ## [2.0.4] - Fix resolving latest release of Github repositories