diff --git a/Rust/Cargo.toml b/Rust/Cargo.toml index aceda1c..7ee0955 100644 --- a/Rust/Cargo.toml +++ b/Rust/Cargo.toml @@ -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" diff --git a/Rust/examples/account_register.rs b/Rust/examples/account_register.rs index 02402ae..7f53daf 100644 --- a/Rust/examples/account_register.rs +++ b/Rust/examples/account_register.rs @@ -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. @@ -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. @@ -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(()) diff --git a/Rust/examples/account_unregister.rs b/Rust/examples/account_unregister.rs index 3f7ef15..aa3139e 100644 --- a/Rust/examples/account_unregister.rs +++ b/Rust/examples/account_unregister.rs @@ -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(()) diff --git a/Rust/examples/asset_definition_register.rs b/Rust/examples/asset_definition_register.rs index b623428..f6b728c 100644 --- a/Rust/examples/asset_definition_register.rs +++ b/Rust/examples/asset_definition_register.rs @@ -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(); @@ -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`. @@ -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 @@ -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 diff --git a/Rust/examples/asset_numeric.rs b/Rust/examples/asset_numeric.rs index 019231e..2850324 100644 --- a/Rust/examples/asset_numeric.rs +++ b/Rust/examples/asset_numeric.rs @@ -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); } } diff --git a/Rust/examples/asset_store.rs b/Rust/examples/asset_store.rs index 128fb81..c0f84cb 100644 --- a/Rust/examples/asset_store.rs +++ b/Rust/examples/asset_store.rs @@ -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<()> { @@ -82,7 +79,7 @@ fn main() -> iroha_examples::Result<()> { } trait StoreAssetExt { - fn assert_metadata_eq>( + fn assert_metadata_eq>( &self, asset_id: AssetId, key: &Name, @@ -91,7 +88,7 @@ trait StoreAssetExt { } impl StoreAssetExt for Client { - fn assert_metadata_eq>( + fn assert_metadata_eq>( &self, asset_id: AssetId, key: &Name, diff --git a/Rust/examples/domain_transfer.rs b/Rust/examples/domain_transfer.rs index b3a03bb..52a314f 100644 --- a/Rust/examples/domain_transfer.rs +++ b/Rust/examples/domain_transfer.rs @@ -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}; @@ -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)?; @@ -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 diff --git a/Rust/examples/roles.rs b/Rust/examples/roles.rs index 4523666..a980cf9 100644 --- a/Rust/examples/roles.rs +++ b/Rust/examples/roles.rs @@ -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::([ 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 @@ -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(), @@ -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(()) diff --git a/Rust/examples/trigger_call.rs b/Rust/examples/trigger_call.rs index 69c7a5f..8d78c55 100644 --- a/Rust/examples/trigger_call.rs +++ b/Rust/examples/trigger_call.rs @@ -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. @@ -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. diff --git a/Rust/examples/trigger_data.rs b/Rust/examples/trigger_data.rs index 5053593..591cc63 100644 --- a/Rust/examples/trigger_data.rs +++ b/Rust/examples/trigger_data.rs @@ -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 @@ -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. diff --git a/Rust/examples/trigger_pre_commit.rs b/Rust/examples/trigger_pre_commit.rs index 2910245..447bfcd 100644 --- a/Rust/examples/trigger_pre_commit.rs +++ b/Rust/examples/trigger_pre_commit.rs @@ -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), ), ); @@ -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. @@ -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. diff --git a/Rust/examples/trigger_time.rs b/Rust/examples/trigger_time.rs index 975dae0..bce63db 100644 --- a/Rust/examples/trigger_time.rs +++ b/Rust/examples/trigger_time.rs @@ -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)), ), ); @@ -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 @@ -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.