Skip to content

Commit

Permalink
Merge branch 'hyperledger:iroha2-dev' into iroha2-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Asem-Abdelhady authored Jan 23, 2024
2 parents d51b2c5 + 85d03b7 commit b18f64b
Show file tree
Hide file tree
Showing 12 changed files with 285 additions and 287 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ result
/test/
/iroha-java/
/lcov.info
**/test-smartcontracts/
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ bash ./scripts/test_env.sh setup
bash ./scripts/tests/register_mint_quantity.sh
bash ./scripts/test_env.sh cleanup
```
To generate WASM files for smart contracts, use the provided script `generate_wasm.sh`. If you are in the root directory of iroha run the following command:

```bash
bash ./scripts/generate_wasm.sh [path/to/smartcontracts]
```

The generated WASM files will be saved in a generated directory `test-smartcontracts`, relative to your current working directory. The default path for smart contracts in this project is `client/tests/integration/smartcontracts`.

</details>

Expand Down
7 changes: 5 additions & 2 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,11 @@ impl NetworkRelay {
}

match msg {
SumeragiPacket(data) => {
self.sumeragi.incoming_message(*data);
SumeragiBlock(data) => {
self.sumeragi.incoming_block_message(*data);
}
SumeragiControlFlow(data) => {
self.sumeragi.incoming_control_flow_message(*data);
}
BlockSync(data) => self.block_sync.message(*data).await,
TransactionGossiper(data) => self.gossiper.gossip(*data).await,
Expand Down
2 changes: 2 additions & 0 deletions client/tests/integration/connected_peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ fn connected_peers_with_f(faults: u64, start_port: Option<u16>) -> Result<()> {
thread::sleep(pipeline_time * 2); // Wait for some time to allow peers to connect
let (removed_peer, removed_peer_client) = peer_clients.remove(removed_peer_idx);

thread::sleep(pipeline_time * 2); // Wait for some time to allow peers to disconnect

check_status(&peer_clients, 2);
let status = removed_peer_client.get_status()?;
// Peer might have been disconnected before getting the block
Expand Down
15 changes: 8 additions & 7 deletions client_cli/pytests/src/client_cli/client_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ def asset(self, asset_definition=None, account=None, value_of_value_type=None):
"""
self.command.insert(3, 'asset')
if asset_definition and account and value_of_value_type:
self.command.append('--account=' + account.name + '@' + asset_definition.domain)
self.command.append('--asset=' + repr(asset_definition))
self.command.append(
'--asset-id='
+ asset_definition.name + '#' + account.domain + '#' + account.name + '@' + asset_definition.domain)
self.command.append(
'--' + asset_definition.value_type.lower() + '=' + value_of_value_type)
self.execute()
Expand All @@ -190,9 +191,9 @@ def transfer(self, asset, source_account, target_account, quantity: str):
"""
self.command.append('asset')
self.command.append('transfer')
self.command.append('--from=' + repr(source_account))
self.command.append('--to=' + repr(target_account))
self.command.append('--asset-id=' + repr(asset))
self.command.append(
'--asset-id=' + asset.name + '#' + source_account.domain + '#' + source_account.name + '@' + asset.domain)
self.command.append('--quantity=' + quantity)
self.execute()
return self
Expand All @@ -211,8 +212,8 @@ def burn(self, account, asset, quantity: str):
"""
self.command.append('asset')
self.command.append('burn')
self.command.append('--account=' + repr(account))
self.command.append('--asset=' + repr(asset))
self.command.append(
'--asset-id=' + asset.name + '#' + account.domain + '#' + account.name + '@' + asset.domain)
self.command.append('--quantity=' + quantity)
self.execute()
return self
Expand All @@ -230,7 +231,7 @@ def definition(self, asset: str, domain: str, value_type: str):
:return: The current ClientCli object.
:rtype: ClientCli
"""
self.command.append('--id=' + asset + '#' + domain)
self.command.append('--definition-id=' + asset + '#' + domain)
self.command.append('--value-type=' + value_type)
self.execute()
return self
Expand Down
85 changes: 31 additions & 54 deletions client_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,9 +795,9 @@ mod asset {
/// Register subcommand of asset
#[derive(clap::Args, Debug)]
pub struct Register {
/// Asset id for registering (in form of `name#domain_name')
#[arg(short, long)]
pub id: AssetDefinitionId,
/// Asset definition id for registering (in form of `asset#domain_name`)
#[arg(long)]
pub definition_id: AssetDefinitionId,
/// Mintability of asset
#[arg(short, long)]
pub unmintable: bool,
Expand All @@ -811,16 +811,16 @@ mod asset {
impl RunArgs for Register {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
let Self {
id,
definition_id,
value_type,
unmintable,
metadata,
} = self;
let mut asset_definition = match value_type {
AssetValueType::Quantity => AssetDefinition::quantity(id),
AssetValueType::BigQuantity => AssetDefinition::big_quantity(id),
AssetValueType::Fixed => AssetDefinition::fixed(id),
AssetValueType::Store => AssetDefinition::store(id),
AssetValueType::Quantity => AssetDefinition::quantity(definition_id),
AssetValueType::BigQuantity => AssetDefinition::big_quantity(definition_id),
AssetValueType::Fixed => AssetDefinition::fixed(definition_id),
AssetValueType::Store => AssetDefinition::store(definition_id),
};
if unmintable {
asset_definition = asset_definition.mintable_once();
Expand All @@ -835,12 +835,9 @@ mod asset {
/// Command for minting asset in existing Iroha account
#[derive(clap::Args, Debug)]
pub struct Mint {
/// Account id where asset is stored (in form of `name@domain_name')
#[arg(long)]
pub account: AccountId,
/// Asset id from which to mint (in form of `name#domain_name')
/// Asset id for the asset (in form of `asset##account@domain_name`)
#[arg(long)]
pub asset: AssetDefinitionId,
pub asset_id: AssetId,
/// Quantity to mint
#[arg(short, long)]
pub quantity: u32,
Expand All @@ -851,15 +848,12 @@ mod asset {
impl RunArgs for Mint {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
let Self {
account,
asset,
asset_id,
quantity,
metadata,
} = self;
let mint_asset = iroha_client::data_model::isi::Mint::asset_quantity(
quantity,
AssetId::new(asset, account),
);
let mint_asset =
iroha_client::data_model::isi::Mint::asset_quantity(quantity, asset_id);
submit([mint_asset], metadata.load()?, context)
.wrap_err("Failed to mint asset of type `NumericValue::U32`")
}
Expand All @@ -868,12 +862,9 @@ mod asset {
/// Command for minting asset in existing Iroha account
#[derive(clap::Args, Debug)]
pub struct Burn {
/// Account id where asset is stored (in form of `name@domain_name')
/// Asset id for the asset (in form of `asset##account@domain_name`)
#[arg(long)]
pub account: AccountId,
/// Asset id from which to mint (in form of `name#domain_name')
#[arg(long)]
pub asset: AssetDefinitionId,
pub asset_id: AssetId,
/// Quantity to mint
#[arg(short, long)]
pub quantity: u32,
Expand All @@ -884,15 +875,12 @@ mod asset {
impl RunArgs for Burn {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
let Self {
account,
asset,
asset_id,
quantity,
metadata,
} = self;
let burn_asset = iroha_client::data_model::isi::Burn::asset_quantity(
quantity,
AssetId::new(asset, account),
);
let burn_asset =
iroha_client::data_model::isi::Burn::asset_quantity(quantity, asset_id);
submit([burn_asset], metadata.load()?, context)
.wrap_err("Failed to burn asset of type `NumericValue::U32`")
}
Expand All @@ -901,15 +889,12 @@ mod asset {
/// Transfer asset between accounts
#[derive(clap::Args, Debug)]
pub struct Transfer {
/// Account from which to transfer (in form `name@domain_name')
#[arg(short, long)]
pub from: AccountId,
/// Account to which to transfer (in form `name@domain_name')
#[arg(short, long)]
/// Account to which to transfer (in form `name@domain_name`)
#[arg(long)]
pub to: AccountId,
/// Asset id to transfer (in form like `name#domain_name')
#[arg(short, long)]
pub asset_id: AssetDefinitionId,
/// Asset id to transfer (in form like `asset##account@domain_name`)
#[arg(long)]
pub asset_id: AssetId,
/// Quantity of asset as number
#[arg(short, long)]
pub quantity: u32,
Expand All @@ -920,37 +905,29 @@ mod asset {
impl RunArgs for Transfer {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
let Self {
from,
to,
asset_id,
quantity,
metadata,
} = self;
let transfer_asset = iroha_client::data_model::isi::Transfer::asset_quantity(
AssetId::new(asset_id, from),
quantity,
to,
);
let transfer_asset =
iroha_client::data_model::isi::Transfer::asset_quantity(asset_id, quantity, to);
submit([transfer_asset], metadata.load()?, context).wrap_err("Failed to transfer asset")
}
}

/// Get info of asset
#[derive(clap::Args, Debug)]
pub struct Get {
/// Account where asset is stored (in form of `name@domain_name')
#[arg(long)]
pub account: AccountId,
/// Asset name to lookup (in form of `name#domain_name')
/// Asset id for the asset (in form of `asset##account@domain_name`)
#[arg(long)]
pub asset: AssetDefinitionId,
pub asset_id: AssetId,
}

impl RunArgs for Get {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
let Self { account, asset } = self;
let Self { asset_id } = self;
let iroha_client = Client::new(context.configuration())?;
let asset_id = AssetId::new(asset, account);
let asset = iroha_client
.request(asset::by_id(asset_id))
.wrap_err("Failed to get asset.")?;
Expand Down Expand Up @@ -989,7 +966,7 @@ mod asset {

#[derive(clap::Args, Debug)]
pub struct SetKeyValue {
/// AssetId for the Store asset (in form of `asset##account@domain_name')
/// Asset id for the Store asset (in form of `asset##account@domain_name`)
#[clap(long)]
pub asset_id: AssetId,
/// The key for the store value
Expand Down Expand Up @@ -1021,7 +998,7 @@ mod asset {
}
#[derive(clap::Args, Debug)]
pub struct RemoveKeyValue {
/// AssetId for the Store asset (in form of `asset##account@domain_name')
/// Asset id for the Store asset (in form of `asset##account@domain_name`)
#[clap(long)]
pub asset_id: AssetId,
/// The key for the store value
Expand All @@ -1040,7 +1017,7 @@ mod asset {

#[derive(clap::Args, Debug)]
pub struct GetKeyValue {
/// AssetId for the Store asset (in form of `asset##account@domain_name')
/// Asset id for the Store asset (in form of `asset##account@domain_name`)
#[clap(long)]
pub asset_id: AssetId,
/// The key for the store value
Expand Down
10 changes: 4 additions & 6 deletions core/src/block_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ impl BlockSynchronizer {
pub mod message {
//! Module containing messages for [`BlockSynchronizer`](super::BlockSynchronizer).
use super::*;
use crate::sumeragi::view_change::ProofChain;

/// Get blocks after some block
#[derive(Debug, Clone, Decode, Encode)]
Expand Down Expand Up @@ -234,12 +233,11 @@ pub mod message {
}
}
Message::ShareBlocks(ShareBlocks { blocks, .. }) => {
use crate::sumeragi::message::{Message, MessagePacket};
use crate::sumeragi::message::BlockMessage;
for block in blocks.clone() {
block_sync.sumeragi.incoming_message(MessagePacket::new(
ProofChain::default(),
Some(Message::BlockSyncUpdate(block.into())),
));
block_sync
.sumeragi
.incoming_block_message(BlockMessage::BlockSyncUpdate(block.into()));
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ use parity_scale_codec::{Decode, Encode};
use tokio::sync::broadcast;

use crate::{
block_sync::message::Message as BlockSyncMessage, prelude::*,
sumeragi::message::MessagePacket as SumeragiPacket,
block_sync::message::Message as BlockSyncMessage,
prelude::*,
sumeragi::message::{BlockMessage, ControlFlowMessage},
};

/// The interval at which sumeragi checks if there are tx in the `queue`.
Expand Down Expand Up @@ -59,8 +60,10 @@ pub type EventsSender = broadcast::Sender<Event>;
/// The network message
#[derive(Clone, Debug, Encode, Decode)]
pub enum NetworkMessage {
/// Blockchain message
SumeragiPacket(Box<SumeragiPacket>),
/// Blockchain concensus data message
SumeragiBlock(Box<BlockMessage>),
/// Blockchain concensus control flow message
SumeragiControlFlow(Box<ControlFlowMessage>),
/// Block sync message
BlockSync(Box<BlockSyncMessage>),
/// Transaction gossiper message
Expand Down
Loading

0 comments on commit b18f64b

Please sign in to comment.