diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..e3106585 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,51 @@ +name: Iroha 2 main branch workflow +on: + push: + branches: [main] +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ 3.12 ] + steps: + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Checkout code + uses: actions/checkout@v4 + - name: Install correct rust version + run: rustup install nightly-2024-09-09 && rustup component add rust-src --toolchain nightly-2024-09-09 + - name: Set toolchain + run: rustup default nightly-2024-09-09 + - name: Maturin build + run: | + maturin build + mkdir dist + cp target/wheels/* dist/ + - name: Store the distribution packages + uses: actions/upload-artifact@v4 + with: + name: python-package-distributions + path: dist/ + + publish-to-pypi: + name: >- + Publish Python 🐍 distribution 📦 to PyPI + needs: + - build + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/project/iroha2/ + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution 📦 to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/Cargo.toml b/Cargo.toml index 2c87ad9e..7c87e0d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] -name = "iroha" +name = "iroha2" crate-type = ["cdylib"] [dependencies] diff --git a/docs-recipes/2.1.1.key-pair.py b/docs-recipes/2.1.1.key-pair.py index 8d7529ea..b8ddfc9f 100644 --- a/docs-recipes/2.1.1.key-pair.py +++ b/docs-recipes/2.1.1.key-pair.py @@ -1,20 +1,20 @@ -import iroha +import iroha2 -key_pair1 = iroha.KeyPair.from_json(""" +key_pair1 = iroha2.KeyPair.from_json(""" { "public_key": "ed01205113952DCE80063E467AFEE17D95363A558982A5AE250D221E29933CE73B79FE", "private_key": "80262082E3965D74D8244C8D3CD4EE9C8C4D6C1959B051ECB48B07DE425329F94AD295" } """) -key_pair2 = iroha.KeyPair.random() +key_pair2 = iroha2.KeyPair.random() print("kp1 =", key_pair1) print("kp2 =", key_pair2) -key_pair3 = iroha.KeyPair.from_hex_seed("001122") +key_pair3 = iroha2.KeyPair.from_hex_seed("001122") -key_pair4 = iroha.KeyPair.from_private_key(key_pair2.private_key) +key_pair4 = iroha2.KeyPair.from_private_key(key_pair2.private_key) # kp2 and kp4 should have the same value @@ -24,7 +24,7 @@ # Different algorithms are supported -print("kp using Ed25519 =", iroha.KeyPair.random_with_algorithm("Ed25519")) -print("kp using Secp256k1 =", iroha.KeyPair.random_with_algorithm("Secp256k1")) -print("kp using BlsNormal =", iroha.KeyPair.random_with_algorithm("BlsNormal")) -print("kp using BlsSmall =", iroha.KeyPair.random_with_algorithm("BlsSmall")) \ No newline at end of file +print("kp using Ed25519 =", iroha2.KeyPair.random_with_algorithm("Ed25519")) +print("kp using Secp256k1 =", iroha2.KeyPair.random_with_algorithm("Secp256k1")) +print("kp using BlsNormal =", iroha2.KeyPair.random_with_algorithm("BlsNormal")) +print("kp using BlsSmall =", iroha2.KeyPair.random_with_algorithm("BlsSmall")) \ No newline at end of file diff --git a/docs-recipes/2.3.client.py b/docs-recipes/2.3.client.py index d2d18306..5f347417 100644 --- a/docs-recipes/2.3.client.py +++ b/docs-recipes/2.3.client.py @@ -1,23 +1,20 @@ -import iroha +import iroha2 -key_pair = iroha.KeyPair.from_json(""" +key_pair = iroha2.KeyPair.from_json(""" { - "public_key": "ed01207233BFC89DCBD68C19FDE6CE6158225298EC1131B6A130D1AEB454C1AB5183C0", - "private_key": { - "algorithm": "ed25519", - "payload": "9ac47abf59b356e0bd7dcbbbb4dec080e302156a48ca907e47cb6aea1d32719e7233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0" - } + "public_key": "ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03", + "private_key": "802620CCF31D85E3B32A4BEA59987CE0C78E3B8E2DB93881468AB2435FE45D5C9DCD53" } """) -account_id = "alice@wonderland" +account_id = "ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03@wonderland" web_login = "mad_hatter" password = "ilovetea" api_url = "http://127.0.0.1:8080/" telemetry_url = "http://127.0.0.1:8180/" chain_id = "00000000-0000-0000-0000-000000000000" -client = iroha.Client.create( +client = iroha2.Client.create( key_pair, account_id, web_login, diff --git a/docs-recipes/3.register-domain.py b/docs-recipes/3.register-domain.py index 877654c3..6c8712cf 100644 --- a/docs-recipes/3.register-domain.py +++ b/docs-recipes/3.register-domain.py @@ -1,6 +1,6 @@ -import iroha +import iroha2 -key_pair = iroha.KeyPair.from_json(""" +key_pair = iroha2.KeyPair.from_json(""" { "public_key": "ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03", "private_key": "802620CCF31D85E3B32A4BEA59987CE0C78E3B8E2DB93881468AB2435FE45D5C9DCD53" @@ -14,7 +14,7 @@ telemetry_url = "http://127.0.0.1:8180/" chain_id = "00000000-0000-0000-0000-000000000000" -client = iroha.Client.create( +client = iroha2.Client.create( key_pair, account_id, web_login, @@ -31,7 +31,7 @@ if "looking_glass" in domains: print("'looking_glass' domain already exists.") -register = iroha.Instruction.register_domain("looking_glass") +register = iroha2.Instruction.register_domain("looking_glass") client.submit_executable([register]) diff --git a/docs-recipes/4.register-account.py b/docs-recipes/4.register-account.py index 7d5ef2fa..8ad97cac 100644 --- a/docs-recipes/4.register-account.py +++ b/docs-recipes/4.register-account.py @@ -1,6 +1,6 @@ -import iroha +import iroha2 -key_pair = iroha.KeyPair.from_json(""" +key_pair = iroha2.KeyPair.from_json(""" { "public_key": "ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03", "private_key": "802620CCF31D85E3B32A4BEA59987CE0C78E3B8E2DB93881468AB2435FE45D5C9DCD53" @@ -14,7 +14,7 @@ telemetry_url = "http://127.0.0.1:8180/" chain_id = "00000000-0000-0000-0000-000000000000" -client = iroha.Client.create( +client = iroha2.Client.create( key_pair, account_id, web_login, @@ -22,7 +22,7 @@ api_url, chain_id) -# new_account_key_pair = iroha.KeyPair.random() TODO(Sam): easy account_id from public key and domain util function +# new_account_key_pair = iroha2.KeyPair.random() TODO(Sam): easy account_id from public key and domain util function new_account_id = "ed01206EA0DD4252E4EAE48F60159CE2DBDAA5F324B34C09840CC0897FCD27DD47FED4@wonderland" accounts = client.query_all_accounts_in_domain("wonderland") @@ -34,7 +34,7 @@ if new_account_id in accounts: print("'ed01206EA0DD4252E4EAE48F60159CE2DBDAA5F324B34C09840CC0897FCD27DD47FED4@wonderland' domain already exists.") -register = iroha.Instruction.register_account(new_account_id) +register = iroha2.Instruction.register_account(new_account_id) client.submit_executable([register]) diff --git a/docs-recipes/5.register-and-mint.py b/docs-recipes/5.register-and-mint.py index 0535f690..80287b6d 100644 --- a/docs-recipes/5.register-and-mint.py +++ b/docs-recipes/5.register-and-mint.py @@ -1,6 +1,6 @@ -import iroha +import iroha2 -key_pair = iroha.KeyPair.from_json(""" +key_pair = iroha2.KeyPair.from_json(""" { "public_key": "ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03", "private_key": "802620CCF31D85E3B32A4BEA59987CE0C78E3B8E2DB93881468AB2435FE45D5C9DCD53" @@ -14,7 +14,7 @@ telemetry_url = "http://127.0.0.1:8180/" chain_id = "00000000-0000-0000-0000-000000000000" -client = iroha.Client.create( +client = iroha2.Client.create( key_pair, account_id, web_login, @@ -35,9 +35,9 @@ if "time##ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03@wonderland" in assets: print("'ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03@wonderland' already has asset 'time'.") -register_definition = iroha.Instruction.register_asset_definition(asset_definition_id, iroha.AssetType.numeric_fractional(0)) +register_definition = iroha2.Instruction.register_asset_definition(asset_definition_id, iroha2.AssetType.numeric_fractional(0)) -mint = iroha.Instruction.mint_asset(5, asset_id) +mint = iroha2.Instruction.mint_asset(5, asset_id) client.submit_executable([register_definition, mint]) diff --git a/examples/sign_email.py b/examples/sign_email.py index cbfe5ae2..3b8003df 100644 --- a/examples/sign_email.py +++ b/examples/sign_email.py @@ -1,8 +1,8 @@ # Import dependency -import iroha +import iroha2 # Example ed25519 key pair -key_pair = iroha.KeyPair.from_json(""" +key_pair = iroha2.KeyPair.from_json(""" { "public_key": "ed01207233BFC89DCBD68C19FDE6CE6158225298EC1131B6A130D1AEB454C1AB5183C0", "private_key": { @@ -13,7 +13,7 @@ """) # Hash the user's email address: -hashed_email = iroha.hash(b"email@address") +hashed_email = iroha2.hash(b"email@address") # Sign the user's email address: signature = key_pair.sign(bytes(hashed_email)) diff --git a/examples/sign_tx.py b/examples/sign_tx.py index 2d563214..c3e6026e 100644 --- a/examples/sign_tx.py +++ b/examples/sign_tx.py @@ -1,11 +1,11 @@ # Import dependency -import iroha +import iroha2 # Example signed transaction, encoded with SCALE codec and represented as hex string: encoded_transaction = "010400807233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c00101b65301ad504ea1430c171379ed45226bfc5fe770a216815654e20491626bbf857247bee73f6790314f892ed1a3e4c18cc6815ce9ff85ce956e0f9ab46605bc093962fb8f8e01000028776f6e6465726c616e6414616c6963650008000d09020c786f7228776f6e6465726c616e6401000000020d1402000000000000000002000000000000000d08030c786f7228776f6e6465726c616e6428776f6e6465726c616e6414616c69636501a0860100000000000000" # Example ed25519 key pair -key_pair = iroha.KeyPair.from_json(""" +key_pair = iroha2.KeyPair.from_json(""" { "public_key": "ed0120BA85186D0F8C995F8DEA6C95B3EDA321C88C983D4F6B28E079CC121B40AA8E00", "private_key": { @@ -16,7 +16,7 @@ """) # Decode the transaction: -transaction = iroha.SignedTransaction.decode_hex(encoded_transaction) +transaction = iroha2.SignedTransaction.decode_hex(encoded_transaction) # Sign the transaction with the provided private key: transaction.append_signature(key_pair) diff --git a/pyproject.toml b/pyproject.toml index 6014569c..5c93ff21 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = ["maturin>=1.3,<2.0"] build-backend = "maturin" [project] -name = "iroha" +name = "iroha2" requires-python = ">=3.7" classifiers = [ "Programming Language :: Rust", diff --git a/src/lib.rs b/src/lib.rs index bdd79feb..6f56ea34 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,8 +6,8 @@ mod isi; /// A Python module implemented in Rust. #[pymodule] -#[pyo3(name = "iroha")] -fn iroha_python(py: Python, m: &PyModule) -> PyResult<()> { +#[pyo3(name = "iroha2")] +fn iroha2_python(py: Python, m: &PyModule) -> PyResult<()> { client::register_items(py, m)?; data_model::register_items(py, m)?; isi::register_items(py, m)?; diff --git a/tests/__init__.py b/tests/__init__.py index 1a3fe46a..b04b261c 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,7 +1,7 @@ -import iroha +import iroha2 from faker import Faker -key_pair = iroha.KeyPair.from_json(""" +key_pair = iroha2.KeyPair.from_json(""" { "public_key": "ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03", "private_key": "802620CCF31D85E3B32A4BEA59987CE0C78E3B8E2DB93881468AB2435FE45D5C9DCD53" @@ -15,7 +15,7 @@ telemetry_url = "http://127.0.0.1:8180/" chain_id = "00000000-0000-0000-0000-000000000000" -client = iroha.Client.create( +client = iroha2.Client.create( key_pair, account_id, web_login, diff --git a/tests/conftest.py b/tests/conftest.py index 131dfe0f..e76f1d39 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,7 +2,7 @@ import time import allure -import iroha +import iroha2 import pytest from tests import client, fake @@ -50,10 +50,10 @@ def GIVEN_registered_asset_definition(GIVEN_new_asset_definition_id): with allure.step( f'GIVEN registered asset definition "{GIVEN_new_asset_definition_id}"'): (client.submit_executable_only_success( - [iroha.Instruction + [iroha2.Instruction .register_asset_definition( GIVEN_new_asset_definition_id, - iroha.AssetType.numeric_fractional(0))])) + iroha2.AssetType.numeric_fractional(0))])) return GIVEN_new_asset_definition_id @pytest.fixture() @@ -61,7 +61,7 @@ def GIVEN_registered_domain(GIVEN_new_domain_id): """Fixture to provide a registered domain in Iroha""" with allure.step(f'GIVEN registered domain name "{GIVEN_new_domain_id}"'): (client.submit_executable_only_success( - [iroha.Instruction + [iroha2.Instruction .register_domain(GIVEN_new_domain_id)])) return GIVEN_new_domain_id @@ -71,7 +71,7 @@ def GIVEN_registered_account(GIVEN_new_account_id): with allure.step( f'GIVEN client registered the account "{GIVEN_new_account_id}"'): (client.submit_executable_only_success( - [iroha.Instruction + [iroha2.Instruction .register_account(GIVEN_new_account_id)])) return GIVEN_new_account_id @@ -83,7 +83,7 @@ def GIVEN_registered_domain_with_registered_accounts( with allure.step( f'GIVEN client registered the account "{GIVEN_new_account_id}"'): (client.submit_executable_only_success( - [iroha.Instruction + [iroha2.Instruction .register_account(GIVEN_new_account_id)])) return GIVEN_registered_domain @@ -97,7 +97,7 @@ def GIVEN_registered_account_with_minted_assets( with allure.step( f'GIVEN client minted an asset "{asset}"'): (client.submit_executable_only_success( - [iroha.Instruction + [iroha2.Instruction .mint_asset( 5, asset)])) @@ -111,7 +111,7 @@ def GIVEN_minted_asset( with allure.step( f'GIVEN client mints an asset "{asset}"'): (client.submit_executable_only_success( - [iroha.Instruction + [iroha2.Instruction .mint_asset( 5, asset)])) @@ -123,6 +123,6 @@ def GIVEN_hash_of_registered_transaction(GIVEN_new_domain_id): """Fixture to provide a registered transaction in Iroha""" with allure.step(f'GIVEN registered domain name "{GIVEN_new_domain_id}"'): tx_hash_string = client.submit_executable_only_success( - [iroha.Instruction + [iroha2.Instruction .register_domain(GIVEN_new_domain_id)]) return tx_hash_string diff --git a/tests/helpers.py b/tests/helpers.py index 3675dacf..fd8d7615 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -1,8 +1,8 @@ -import iroha +import iroha2 def generate_public_key(seed="abcd1122"): """ Generate a public key using Ed25519PrivateKey. """ - return iroha.KeyPair.from_hex_seed(seed).public_key \ No newline at end of file + return iroha2.KeyPair.from_hex_seed(seed).public_key \ No newline at end of file diff --git a/tests/query/transactions/test_query_transactions.py b/tests/query/transactions/test_query_transactions.py index d59eb01c..b8d54f13 100644 --- a/tests/query/transactions/test_query_transactions.py +++ b/tests/query/transactions/test_query_transactions.py @@ -1,5 +1,5 @@ import allure -import iroha +import iroha2 from tests import client,account_id from tests.helpers import generate_public_key diff --git a/tests/transaction/accounts/test_register_account.py b/tests/transaction/accounts/test_register_account.py index 59aebdfb..0f9629ce 100644 --- a/tests/transaction/accounts/test_register_account.py +++ b/tests/transaction/accounts/test_register_account.py @@ -1,5 +1,5 @@ import allure -import iroha +import iroha2 import pytest from tests import client @@ -16,7 +16,7 @@ def test_register_account( with allure.step( f'WHEN client registers the account "{GIVEN_new_account_id}"'): (client.submit_executable_only_success( - [iroha.Instruction + [iroha2.Instruction .register_account(GIVEN_new_account_id)])) with allure.step( f'THEN Iroha should have the "{GIVEN_new_account_id}" account'): diff --git a/tests/transaction/assets/test_mint_assets.py b/tests/transaction/assets/test_mint_assets.py index 273c3bf8..1d9b6284 100644 --- a/tests/transaction/assets/test_mint_assets.py +++ b/tests/transaction/assets/test_mint_assets.py @@ -1,7 +1,7 @@ import re import allure -import iroha +import iroha2 import pytest @@ -20,7 +20,7 @@ def test_mint_asset( with allure.step( f'WHEN client mints an asset "{asset}"'): (client.submit_executable_only_success( - [iroha.Instruction + [iroha2.Instruction .mint_asset( 5, asset)])) diff --git a/tests/transaction/assets/test_register_asset_definitions.py b/tests/transaction/assets/test_register_asset_definitions.py index 1aae894e..299885bb 100644 --- a/tests/transaction/assets/test_register_asset_definitions.py +++ b/tests/transaction/assets/test_register_asset_definitions.py @@ -1,5 +1,5 @@ import allure -import iroha +import iroha2 import pytest @@ -17,10 +17,10 @@ def test_register_asset_definition( with allure.step( f'WHEN client registers a new asset definition id "{GIVEN_new_asset_definition_id}"'): (client.submit_executable_only_success( - [iroha.Instruction + [iroha2.Instruction .register_asset_definition( GIVEN_new_asset_definition_id, - iroha.AssetType.numeric_fractional(0))])) + iroha2.AssetType.numeric_fractional(0))])) with allure.step( f'THEN Iroha should have the "{GIVEN_new_asset_definition_id}" account'): assert GIVEN_new_asset_definition_id in client.query_all_asset_definitions() diff --git a/tests/transaction/assets/test_transfer_assets.py b/tests/transaction/assets/test_transfer_assets.py index 518827a9..164084ff 100644 --- a/tests/transaction/assets/test_transfer_assets.py +++ b/tests/transaction/assets/test_transfer_assets.py @@ -1,5 +1,5 @@ import allure -import iroha +import iroha2 import pytest @@ -16,7 +16,7 @@ def test_transfer_asset( with allure.step( f'WHEN client transfers an asset'): (client.submit_executable_only_success( - [iroha.Instruction. + [iroha2.Instruction. transfer( 5, GIVEN_minted_asset, diff --git a/tests/transaction/domains/test_register_domain.py b/tests/transaction/domains/test_register_domain.py index c585fa86..c1d49d01 100644 --- a/tests/transaction/domains/test_register_domain.py +++ b/tests/transaction/domains/test_register_domain.py @@ -1,5 +1,5 @@ import allure -import iroha +import iroha2 import pytest from tests import client @@ -15,7 +15,7 @@ def test_register_domain( GIVEN_new_domain_id): with allure.step(f'WHEN client registers the domain name "{GIVEN_new_domain_id}"'): (client.submit_executable_only_success( - [iroha.Instruction + [iroha2.Instruction .register_domain(GIVEN_new_domain_id)])) with allure.step(f'THEN Iroha should have the domain name "{GIVEN_new_domain_id}"'): assert GIVEN_new_domain_id in client.query_all_domains()