Skip to content

Commit

Permalink
[fix] #191: Updated to iroha version v2.0.0-pre-rc.21
Browse files Browse the repository at this point in the history
Signed-off-by: Sam H. Smith <sam.henning.smith@protonmail.com>
  • Loading branch information
SamHSmith committed May 10, 2024
1 parent 30a6c56 commit 791af7b
Show file tree
Hide file tree
Showing 20 changed files with 1,507 additions and 1,678 deletions.
2,670 changes: 1,282 additions & 1,388 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ pyo3 = { version = "0.20.0", features = ["multiple-pymethods", "rust_decimal"] }
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.108"

iroha_client = { git = "https://github.com/hyperledger/iroha.git", branch = "iroha2-stable" }
iroha_config = { git = "https://github.com/hyperledger/iroha.git", branch = "iroha2-stable" }
iroha_data_model = { git = "https://github.com/hyperledger/iroha.git", branch = "iroha2-stable", features = ["transparent_api"] }
iroha_crypto = { git = "https://github.com/hyperledger/iroha.git", branch = "iroha2-stable" }
iroha_primitives = { git = "https://github.com/hyperledger/iroha.git", branch = "iroha2-stable" }
parity-scale-codec = { version = "3.6.5", default-features = false, features = ["derive"] }
iroha_client = { git = "https://github.com/hyperledger/iroha.git", tag = "v2.0.0-pre-rc.21" }
iroha_config = { git = "https://github.com/hyperledger/iroha.git", tag = "v2.0.0-pre-rc.21" }
iroha_data_model = { git = "https://github.com/hyperledger/iroha.git", tag = "v2.0.0-pre-rc.21", features = ["transparent_api"] }
iroha_crypto = { git = "https://github.com/hyperledger/iroha.git", tag = "v2.0.0-pre-rc.21" }
iroha_primitives = { git = "https://github.com/hyperledger/iroha.git", tag = "v2.0.0-pre-rc.21" }
parity-scale-codec = { version = "3.6.9", default-features = false, features = ["derive"] }
paste = "1.0.14"
derive_more = "0.99.17"
eyre = { version = "0.6.12", features = ["pyo3"] }
rust_decimal = "1.33.1"
rust_decimal = "1.35.0"
hex = "0.4.3"
url = "2.4.1"
18 changes: 11 additions & 7 deletions docs-recipes/2.1.1.key-pair.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@
{
"public_key": "ed01207233BFC89DCBD68C19FDE6CE6158225298EC1131B6A130D1AEB454C1AB5183C0",
"private_key": {
"digest_function": "ed25519",
"algorithm": "ed25519",
"payload": "9ac47abf59b356e0bd7dcbbbb4dec080e302156a48ca907e47cb6aea1d32719e7233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0"
}
}
""")

key_pair2 = iroha.KeyGenConfiguration.default().use_seed_hex("001122").generate()

key_pair3 = iroha.KeyGenConfiguration.default().use_private_key(key_pair2.private_key).generate()

# kp2 and kp3 should have the same value
key_pair2 = iroha.KeyPair.generate()

print("kp1 =", key_pair1)
print("kp2 =", key_pair2)
print("kp3 =", key_pair3)

key_pair3 = iroha.KeyGenConfiguration.default().use_seed_hex("001122").generate()

key_pair4 = iroha.KeyGenConfiguration.default().use_private_key(key_pair2.private_key).generate()

# kp4 and kp4 should have the same value

print("kp3 =", key_pair3)
print("kp4 =", key_pair4)
6 changes: 4 additions & 2 deletions docs-recipes/2.3.client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"public_key": "ed01207233BFC89DCBD68C19FDE6CE6158225298EC1131B6A130D1AEB454C1AB5183C0",
"private_key": {
"digest_function": "ed25519",
"algorithm": "ed25519",
"payload": "9ac47abf59b356e0bd7dcbbbb4dec080e302156a48ca907e47cb6aea1d32719e7233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0"
}
}
Expand All @@ -15,13 +15,15 @@
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(
key_pair,
account_id,
web_login,
password,
api_url)
api_url,
chain_id)

domains = client.query_all_domains()

Expand Down
6 changes: 4 additions & 2 deletions docs-recipes/3.register-domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"public_key": "ed01207233BFC89DCBD68C19FDE6CE6158225298EC1131B6A130D1AEB454C1AB5183C0",
"private_key": {
"digest_function": "ed25519",
"algorithm": "ed25519",
"payload": "9ac47abf59b356e0bd7dcbbbb4dec080e302156a48ca907e47cb6aea1d32719e7233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0"
}
}
Expand All @@ -15,13 +15,15 @@
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(
key_pair,
account_id,
web_login,
password,
api_url)
api_url,
chain_id)

domains = client.query_all_domains()

Expand Down
10 changes: 6 additions & 4 deletions docs-recipes/4.register-account.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"public_key": "ed01207233BFC89DCBD68C19FDE6CE6158225298EC1131B6A130D1AEB454C1AB5183C0",
"private_key": {
"digest_function": "ed25519",
"algorithm": "ed25519",
"payload": "9ac47abf59b356e0bd7dcbbbb4dec080e302156a48ca907e47cb6aea1d32719e7233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0"
}
}
Expand All @@ -15,15 +15,17 @@
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(
key_pair,
account_id,
web_login,
password,
api_url)
api_url,
chain_id)

new_account_key_pair = iroha.KeyGenConfiguration.default().use_seed_hex("abcd1122").generate()
new_account_key_pair = iroha.KeyPair.generate()
new_account_id = "white_rabbit@wonderland"

accounts = client.query_all_accounts_in_domain("wonderland")
Expand All @@ -35,7 +37,7 @@
if new_account_id in accounts:
print("'white_rabbit@wonderland' domain already exists.")

register = iroha.Instruction.register_account(new_account_id, [new_account_key_pair.public_key])
register = iroha.Instruction.register_account(new_account_id, new_account_key_pair.public_key)

client.submit_executable([register])

Expand Down
10 changes: 6 additions & 4 deletions docs-recipes/5.register-and-mint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"public_key": "ed01207233BFC89DCBD68C19FDE6CE6158225298EC1131B6A130D1AEB454C1AB5183C0",
"private_key": {
"digest_function": "ed25519",
"algorithm": "ed25519",
"payload": "9ac47abf59b356e0bd7dcbbbb4dec080e302156a48ca907e47cb6aea1d32719e7233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0"
}
}
Expand All @@ -15,13 +15,15 @@
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(
key_pair,
account_id,
web_login,
password,
api_url)
api_url,
chain_id)

assets = client.query_all_assets_owned_by_account("alice@wonderland")

Expand All @@ -36,9 +38,9 @@
if "time##alice@wonderland" in assets:
print("'alice@wonderland' already has asset 'time'.")

register_definition = iroha.Instruction.register_asset_definition(asset_definition_id, "Quantity")
register_definition = iroha.Instruction.register_asset_definition(asset_definition_id, iroha.AssetValueType.numeric_fractional(0))

mint = iroha.Instruction.mint_asset(5, asset_id, "Quantity")
mint = iroha.Instruction.mint_asset(5, asset_id)

client.submit_executable([register_definition, mint])

Expand Down
2 changes: 1 addition & 1 deletion examples/sign_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
"public_key": "ed01207233BFC89DCBD68C19FDE6CE6158225298EC1131B6A130D1AEB454C1AB5183C0",
"private_key": {
"digest_function": "ed25519",
"algorithm": "ed25519",
"payload": "9ac47abf59b356e0bd7dcbbbb4dec080e302156a48ca907e47cb6aea1d32719e7233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0"
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/sign_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{
"public_key": "ed0120BA85186D0F8C995F8DEA6C95B3EDA321C88C983D4F6B28E079CC121B40AA8E00",
"private_key": {
"digest_function": "ed25519",
"algorithm": "ed25519",
"payload": "1b9068cd9b4acaabf1e8c66c622d9bd15ff3b04099819b750e3987be73d2096fba85186d0f8c995f8dea6c95b3eda321c88c983d4f6b28e079cc121b40aa8e00"
}
}
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ allure-python-commons = "*"
pytest = "^8.1.1"
faker = "^24.4.0"
#iroha = {path = "target/wheels/iroha-0.1.0-cp39-cp39-macosx_11_0_arm64.whl"}
iroha = {path = "target/wheels/iroha-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl"}
28 changes: 18 additions & 10 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use pyo3::{
};

use iroha_client::client::Client as IrohaClient;
use iroha_config::client::*;
use iroha_client::config::Config as IrohaClientConfig;
use iroha_client::config::{BasicAuth, WebLogin};

use std::num::NonZeroU64;
use std::str::FromStr;

Expand All @@ -17,6 +19,7 @@ use crate::data_model::PyMirror;
use crate::{data_model::account::PyAccountId, isi::PyInstruction};
use iroha_data_model::account::AccountId;
use iroha_data_model::prelude::DomainId;
use iroha_data_model::ChainId;

#[allow(unsafe_code)]
const DEFAULT_TRANSACTION_TIME_TO_LIVE_MS: NonZeroU64 =
Expand All @@ -38,27 +41,32 @@ impl Client {
web_login: &str,
password: &str,
api_url: &str,
chain_id: &str,
) -> PyResult<Self> {
let config = Configuration {
public_key: key_pair.0.public_key().clone(),
private_key: key_pair.0.private_key().clone(),
let config = IrohaClientConfig {
chain_id: ChainId::from(chain_id),
account_id: AccountId::from_str(account_id)
.map_err(|e| PyValueError::new_err(e.to_string()))?,
key_pair: key_pair.clone().into(),
basic_auth: Some(BasicAuth {
web_login: WebLogin::from_str(web_login)
.map_err(|e| PyValueError::new_err(e.to_string()))?,
password: iroha_primitives::small::SmallStr::from_str(password),
}),
torii_api_url: url::Url::parse(api_url)
.map_err(|e| PyValueError::new_err(e.to_string()))?,
transaction_time_to_live_ms: Some(DEFAULT_TRANSACTION_TIME_TO_LIVE_MS),
transaction_status_timeout_ms: DEFAULT_TRANSACTION_STATUS_TIMEOUT_MS,
transaction_ttl: std::time::Duration::from_millis(
DEFAULT_TRANSACTION_TIME_TO_LIVE_MS.into(),
),
transaction_status_timeout: std::time::Duration::from_millis(
DEFAULT_TRANSACTION_STATUS_TIMEOUT_MS,
),
// deprecated, does nothing.
transaction_limits: iroha_data_model::transaction::TransactionLimits::new(0, 0),
add_transaction_nonce: DEFAULT_ADD_TRANSACTION_NONCE,
transaction_add_nonce: DEFAULT_ADD_TRANSACTION_NONCE,
};
let client = IrohaClient::new(&config).map_err(|e| PyValueError::new_err(e.to_string()))?;
Ok(Self { client })
Ok(Self {
client: IrohaClient::new(config),
})
}

fn submit_executable(&self, py: Python<'_>, isi: PyObject) -> PyResult<String> {
Expand Down
29 changes: 3 additions & 26 deletions src/data_model/account.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use iroha_data_model::account::{prelude::*, NewAccount};
use iroha_data_model::account::{prelude::*, Account, NewAccount};

use pyo3::{
exceptions::PyValueError,
Expand Down Expand Up @@ -81,8 +81,7 @@ impl PyAccount {
fn get_signatories(&self, py: Python<'_>) -> Py<PyList> {
let signatories = self
.0
.signatories
.iter()
.signatories()
.map(|signatory| PyPublicKey(signatory.clone()).into_py(py))
.collect::<Vec<_>>();
PyList::new(py, signatories).into()
Expand Down Expand Up @@ -113,9 +112,7 @@ impl PyNewAccount {
};

let signatories = if let Ok(single) = signatories.extract::<PyPublicKey>(py) {
vec![single.0]
} else if let Ok(multiple) = signatories.extract::<Vec<PyPublicKey>>(py) {
multiple.into_iter().map(|key| key.0).collect::<Vec<_>>()
single.0
} else {
return Err(PyValueError::new_err(
"signatories should be either a list of public keys or a single public key",
Expand All @@ -135,26 +132,6 @@ impl PyNewAccount {
self.0.id = id.clone().into()
}

#[getter]
fn get_signatories(&self, py: Python<'_>) -> Py<PyList> {
let signatories = self
.0
.signatories
.iter()
.map(|signatory| PyPublicKey(signatory.clone()).into_py(py))
.collect::<Vec<_>>();
PyList::new(py, signatories).into()
}

#[setter]
fn set_signatories(&mut self, signatories: Vec<PyPublicKey>) {
let signatories = signatories
.into_iter()
.map(Into::into)
.collect::<BTreeSet<_>>();
self.0.signatories = signatories
}

#[getter]
fn get_metadata(&self, py: Python<'_>) -> PyResult<Py<PyDict>> {
MetadataWrapper(self.0.metadata.clone()).into_py(py)
Expand Down
Loading

0 comments on commit 791af7b

Please sign in to comment.