Skip to content

Commit

Permalink
fix: Rename to iroha2 and add build CI
Browse files Browse the repository at this point in the history
Signed-off-by: Sam H. Smith <[email protected]>
  • Loading branch information
SamHSmith committed Nov 15, 2024
1 parent 8cf76fb commit a0e90a8
Show file tree
Hide file tree
Showing 20 changed files with 116 additions and 68 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
18 changes: 9 additions & 9 deletions docs-recipes/2.1.1.key-pair.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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"))
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"))
15 changes: 6 additions & 9 deletions docs-recipes/2.3.client.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
8 changes: 4 additions & 4 deletions docs-recipes/3.register-domain.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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,
Expand All @@ -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])

Expand Down
10 changes: 5 additions & 5 deletions docs-recipes/4.register-account.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -14,15 +14,15 @@
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,
password,
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")
Expand All @@ -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])

Expand Down
10 changes: 5 additions & 5 deletions docs-recipes/5.register-and-mint.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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,
Expand All @@ -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])

Expand Down
6 changes: 3 additions & 3 deletions examples/sign_email.py
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions examples/sign_tx.py
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
6 changes: 3 additions & 3 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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,
Expand Down
18 changes: 9 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import time

import allure
import iroha
import iroha2
import pytest

from tests import client, fake
Expand Down Expand Up @@ -50,18 +50,18 @@ 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()
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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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)]))
Expand All @@ -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)]))
Expand All @@ -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
4 changes: 2 additions & 2 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -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
return iroha2.KeyPair.from_hex_seed(seed).public_key
Loading

0 comments on commit a0e90a8

Please sign in to comment.