Skip to content

Commit

Permalink
Update according to changes in iroha main branch
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Murzin <[email protected]>
  • Loading branch information
dima74 committed Nov 14, 2024
1 parent 87e23f9 commit cd7529d
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 58 deletions.
4 changes: 2 additions & 2 deletions Rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ keywords = ["blockchain", "crypto", "iroha", "ledger"]
categories = ["cryptography::cryptocurrencies"]

[dependencies]
iroha = { git = "https://github.com/hyperledger/iroha.git" }
iroha_executor_data_model = { git = "https://github.com/hyperledger/iroha.git" }
iroha = { version = "=2.0.0-rc.1.0", git = "https://github.com/hyperledger-iroha/iroha.git" }
iroha_executor_data_model = { version = "=2.0.0-rc.1.0", git = "https://github.com/hyperledger-iroha/iroha.git" }
eyre = "0.6.12"
serde_json = "1.0.128"
7 changes: 4 additions & 3 deletions Rust/examples/account_register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
//! Depends on the `domain_register` example.
use iroha::client::Client;
use iroha::data_model::Identifiable;
use iroha::data_model::prelude::{
Account, AccountId, FindAccounts, Grant, QueryBuilderExt, Register, Revoke,
};
use iroha_executor_data_model::permission::account::CanRegisterAccount;
use iroha_examples::{
AliceInChess, AliceInWonderland, BobInChess, BobInWonderland, Chess, ExampleDomain,
MagnusInChess,
};
use iroha_executor_data_model::permission::domain::CanRegisterAccountInDomain;

fn main() -> iroha_examples::Result<()> {
// An account is created for a signatory in a domain.
Expand All @@ -20,7 +21,7 @@ fn main() -> iroha_examples::Result<()> {
register(&as_alice_in_wland, AliceInChess::id())?;

// The domain owner can also grant a permission to register accounts in the domain.
let can_register_accounts_in_chess = CanRegisterAccountInDomain {
let can_register_accounts_in_chess = CanRegisterAccount {
domain: Chess::id(),
};
// Grant the permission to Bob from Wonderland.
Expand Down Expand Up @@ -49,7 +50,7 @@ fn register(as_who: &Client, account: AccountId) -> iroha_examples::Result<()> {
.query(FindAccounts)
.filter_with(|acc| acc.id.eq(account))
.execute_single()?;
println!("Account: {}\nRegistered by: {}", account.id, as_who.account);
println!("Account: {}\nRegistered by: {}", account.id(), as_who.account);
// Account: ed12...41@wonderland
// Registered by: ed01...12@wonderland
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion Rust/examples/account_unregister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn unregister(as_who: &Client, account: AccountId) -> iroha_examples::Result<()>
.filter_with(|acc| acc.id.eq(account.clone()))
.execute_single()
.expect_err("account should not be found");
println!("Account: {}\nUnregistered by: {}", account, as_who.account);
println!("Account: {account}\nUnregistered by: {}", as_who.account);
// Account: ed12...41@wonderland
// Unregistered by: ed01...12@wonderland
Ok(())
Expand Down
8 changes: 4 additions & 4 deletions Rust/examples/asset_definition_register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use iroha::data_model::prelude::{
FindAssetsDefinitions, Metadata, NewAssetDefinition, NumericSpec, QueryBuilderExt, Register,
Revoke,
};
use iroha_executor_data_model::permission::asset_definition::CanRegisterAssetDefinition;
use iroha_examples::{
AliceInWonderland, BobInChess, Chess, ChessBook, ChessPawns, ExampleDomain, WonderlandMoney,
WonderlandRoses,
};
use iroha_executor_data_model::permission::domain::CanRegisterAssetDefinitionInDomain;

fn main() -> iroha_examples::Result<()> {
let as_alice_in_wland = AliceInWonderland::client();
Expand All @@ -39,7 +39,7 @@ fn main() -> iroha_examples::Result<()> {
// Since `bob@chess` is not the owner of `chess`, `alice@wonderland`
// has to grant `bob@chess` permission to define assets in `chess`.
let bob_in_chess = BobInChess::id();
let can_define_assets_in_chess = CanRegisterAssetDefinitionInDomain {
let can_define_assets_in_chess = CanRegisterAssetDefinition {
domain: Chess::id(),
};
// Grant the permission to `bob@chess`.
Expand Down Expand Up @@ -78,7 +78,7 @@ fn main() -> iroha_examples::Result<()> {
}

fn register(as_who: &Client, asset_definition: NewAssetDefinition) -> iroha_examples::Result<()> {
let asset_definition_id = asset_definition.id.clone();
let asset_definition_id = asset_definition.id().clone();
let define_asset = Register::asset_definition(asset_definition);
as_who.submit_blocking(define_asset)?;
let asset_definition = as_who
Expand All @@ -87,7 +87,7 @@ fn register(as_who: &Client, asset_definition: NewAssetDefinition) -> iroha_exam
.execute_single()?;
println!(
"Asset definition: {}\nRegistered by: {}",
asset_definition.id, as_who.account
asset_definition.id(), as_who.account
);
// Asset definition: pawn#chess
// Registered by: ed01...12@wonderland
Expand Down
4 changes: 2 additions & 2 deletions Rust/examples/asset_numeric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ impl NumericAssetExt for Client {
.filter_with(|asset| asset.id.eq(asset_id))
.execute_single()
.unwrap();
let AssetValue::Numeric(actual) = asset.value else {
let AssetValue::Numeric(actual) = asset.value() else {
// FIXME: this API inconvenience should be resolved
// when numeric assets are separated from store assets.
panic!("should be a numeric asset");
};
assert_eq!(actual, expected);
assert_eq!(actual, &expected);
}
}
9 changes: 3 additions & 6 deletions Rust/examples/asset_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
use iroha::client::Client;
use iroha::data_model::asset::{Asset, AssetValue};
use iroha::data_model::prelude::{
AssetId, FindAssets, JsonString, Metadata, Name, QueryBuilderExt, Register, RemoveKeyValue,
SetKeyValue,
};
use iroha::data_model::prelude::{AssetId, FindAssets, Json, Metadata, Name, QueryBuilderExt, Register, RemoveKeyValue, SetKeyValue};
use iroha_examples::{AliceInWonderland, BobInChess, BookOfBobInChess};

fn main() -> iroha_examples::Result<()> {
Expand Down Expand Up @@ -82,7 +79,7 @@ fn main() -> iroha_examples::Result<()> {
}

trait StoreAssetExt {
fn assert_metadata_eq<T: Into<JsonString>>(
fn assert_metadata_eq<T: Into<Json>>(
&self,
asset_id: AssetId,
key: &Name,
Expand All @@ -91,7 +88,7 @@ trait StoreAssetExt {
}

impl StoreAssetExt for Client {
fn assert_metadata_eq<T: Into<JsonString>>(
fn assert_metadata_eq<T: Into<Json>>(
&self,
asset_id: AssetId,
key: &Name,
Expand Down
8 changes: 4 additions & 4 deletions Rust/examples/domain_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! Depends on the `domain_register` example.
use iroha::client::Client;
use iroha::data_model::prelude::{AccountId, DomainId, FindDomains, QueryBuilderExt, Transfer};
use iroha::data_model::prelude::{AccountId, DomainId, FindDomains, QueryBuilderExt, Transfer, Identifiable};

use iroha_examples::{AliceInWonderland, BobInWonderland, ExampleDomain, Wonderland};

Expand Down Expand Up @@ -40,7 +40,7 @@ fn transfer(
.query(FindDomains)
.filter_with(|dom| dom.id.eq(domain.clone()))
.execute_single()?;
assert_eq!(domain.owned_by, from);
assert_eq!(domain.owned_by(), &from);
}
let transfer_domain = Transfer::domain(from.clone(), domain.clone(), to.clone());
as_who.submit_blocking(transfer_domain)?;
Expand All @@ -49,10 +49,10 @@ fn transfer(
.query(FindDomains)
.filter_with(|dom| dom.id.eq(domain.clone()))
.execute_single()?;
assert_eq!(domain.owned_by, to);
assert_eq!(domain.owned_by(), &to);
println!(
"Domain: {}\nTransferred\n\tfrom: {}\n\tto: {}\nby: {}",
domain.id, from, to, as_who.account
domain.id(), from, to, as_who.account
);
// Domain: chess
// Transferred
Expand Down
18 changes: 8 additions & 10 deletions Rust/examples/roles.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
//! Shows how to work with permissions and roles.
use iroha::data_model::prelude::*;
use iroha_executor_data_model::permission::asset_definition::CanRegisterAssetDefinition;
use iroha_examples::*;
use iroha_executor_data_model::permission::domain::*;

fn main() -> Result<()> {
let chess = Chess::id();
let bob_in_chess = BobInChess::id();

// define a role for managing chess
let chess_manager: RoleId = "CHESS_MANAGER".parse()?;
let new_chess_manager = Role::new(chess_manager.clone())
//
.add_permission(CanSetKeyValueInDomain {
domain: chess.clone(),
})
.add_permission(CanRemoveKeyValueInDomain {
let new_chess_manager = Role::new(chess_manager.clone(), bob_in_chess.clone())
.add_permission(CanModifyDomainMetadata {
domain: chess.clone(),
});

// grant the role to bob@chess
let bob_in_chess = BobInChess::id();
let as_alice_in_wland = AliceInWonderland::client();
as_alice_in_wland.submit_all_blocking::<InstructionBox>([
Register::role(new_chess_manager).into(),
Grant::role(chess_manager.clone(), bob_in_chess.clone()).into(),
Grant::account_role(chess_manager.clone(), bob_in_chess.clone()).into(),
])?;

// bob@chess is now able to set key-values in chess
Expand All @@ -35,7 +33,7 @@ fn main() -> Result<()> {

// add permissions to an existing role
as_alice_in_wland.submit_all_blocking([Grant::role_permission(
CanRegisterAssetDefinitionInDomain {
CanRegisterAssetDefinition {
domain: chess.clone(),
},
chess_manager.clone(),
Expand All @@ -49,7 +47,7 @@ fn main() -> Result<()> {
as_bob_in_chess.submit_blocking(Unregister::asset_definition(chess_pawns))?;

// revoke the role from bob@chess
as_alice_in_wland.submit_blocking(Revoke::role(chess_manager.clone(), bob_in_chess))?;
as_alice_in_wland.submit_blocking(Revoke::account_role(chess_manager.clone(), bob_in_chess))?;
// remove the role
as_alice_in_wland.submit_blocking(Unregister::role(chess_manager))?;
Ok(())
Expand Down
8 changes: 2 additions & 6 deletions Rust/examples/trigger_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ fn main() -> iroha_examples::Result<()> {
// Query Alice's Wonderland roses before:
println!(
"Alice's Wonderland Rose count before trigger execution: {}",
as_alice_in_wland.query_single(FindAssetQuantityById {
id: wland_roses_of_alice.clone(),
})?
as_alice_in_wland.query_single(FindAssetQuantityById::new(wland_roses_of_alice.clone()))?
);

// Execute the trigger via an instruction.
Expand All @@ -44,9 +42,7 @@ fn main() -> iroha_examples::Result<()> {
// Query Alice's Wonderland roses after:
println!(
"Alice's Wonderland Rose count after trigger execution: {}",
as_alice_in_wland.query_single(FindAssetQuantityById {
id: wland_roses_of_alice.clone(),
})?
as_alice_in_wland.query_single(FindAssetQuantityById::new(wland_roses_of_alice.clone()))?
);

// Unregister the trigger.
Expand Down
8 changes: 2 additions & 6 deletions Rust/examples/trigger_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ fn main() -> iroha_examples::Result<()> {
// Query Alice's Wonderland roses before:
println!(
"Alice's Wonderland Rose count before trigger execution: {}",
as_alice_in_wland.query_single(FindAssetQuantityById {
id: wland_roses_of_alice.clone(),
})?
as_alice_in_wland.query_single(FindAssetQuantityById::new(wland_roses_of_alice.clone()))?
);

// Trigger is now registered and will mint a rose
Expand All @@ -50,9 +48,7 @@ fn main() -> iroha_examples::Result<()> {
// Query Alice's Wonderland roses after:
println!(
"Alice's Wonderland Rose count after trigger execution: {}",
as_alice_in_wland.query_single(FindAssetQuantityById {
id: wland_roses_of_alice.clone(),
})?
as_alice_in_wland.query_single(FindAssetQuantityById::new(wland_roses_of_alice.clone()))?
);

// Unregister the trigger.
Expand Down
10 changes: 3 additions & 7 deletions Rust/examples/trigger_pre_commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn main() -> iroha_examples::Result<()> {
Some(mint_wland_roses_of_alice),
Repeats::Indefinitely,
alice_in_wland,
TimeEventFilter(ExecutionTime::PreCommit),
TimeEventFilter::new(ExecutionTime::PreCommit),
),
);

Expand All @@ -33,9 +33,7 @@ fn main() -> iroha_examples::Result<()> {
// Query Alice's Wonderland roses before:
println!(
"Alice's Wonderland Rose count before trigger execution: {}",
as_alice_in_wland.query_single(FindAssetQuantityById {
id: wland_roses_of_alice.clone(),
})?
as_alice_in_wland.query_single(FindAssetQuantityById::new(wland_roses_of_alice.clone()))?
);

// Issue a dummy instruction to create a block.
Expand All @@ -44,9 +42,7 @@ fn main() -> iroha_examples::Result<()> {
// Query Alice's Wonderland roses after:
println!(
"Alice's Wonderland Rose count after trigger execution: {}",
as_alice_in_wland.query_single(FindAssetQuantityById {
id: wland_roses_of_alice.clone(),
})?
as_alice_in_wland.query_single(FindAssetQuantityById::new(wland_roses_of_alice.clone()))?
);

// Unregister the trigger.
Expand Down
10 changes: 3 additions & 7 deletions Rust/examples/trigger_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn main() -> iroha_examples::Result<()> {
Some(mint_wland_roses_of_alice),
Repeats::Indefinitely,
alice_in_wland,
TimeEventFilter(ExecutionTime::Schedule(every_second)),
TimeEventFilter::new(ExecutionTime::Schedule(every_second)),
),
);

Expand All @@ -41,9 +41,7 @@ fn main() -> iroha_examples::Result<()> {
// Query Alice's Wonderland roses before:
println!(
"Alice's Wonderland Rose count before trigger execution: {}",
as_alice_in_wland.query_single(FindAssetQuantityById {
id: wland_roses_of_alice.clone(),
})?
as_alice_in_wland.query_single(FindAssetQuantityById::new(wland_roses_of_alice.clone()))?
);

// Sleep for a few seconds to allow the trigger to mint multiple roses
Expand All @@ -53,9 +51,7 @@ fn main() -> iroha_examples::Result<()> {
// Query Alice's Wonderland roses after:
println!(
"Alice's Wonderland Rose count after trigger execution: {}",
as_alice_in_wland.query_single(FindAssetQuantityById {
id: wland_roses_of_alice.clone(),
})?
as_alice_in_wland.query_single(FindAssetQuantityById::new(wland_roses_of_alice.clone()))?
);

// Unregister the trigger.
Expand Down

0 comments on commit cd7529d

Please sign in to comment.