Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: remove _id suffix for entity ids in public API #4714

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,14 @@ impl Iroha {
&config.block_sync,
sumeragi.clone(),
Arc::clone(&kura),
config.common.peer_id(),
config.common.peer.clone(),
network.clone(),
Arc::clone(&state),
)
.start();

let gossiper = TransactionGossiper::from_config(
config.common.chain_id.clone(),
config.common.chain.clone(),
config.transaction_gossiper,
network.clone(),
Arc::clone(&queue),
Expand Down Expand Up @@ -356,7 +356,7 @@ impl Iroha {
let kiso = KisoHandle::new(config.clone());

let torii = Torii::new(
config.common.chain_id.clone(),
config.common.chain.clone(),
kiso.clone(),
config.torii,
Arc::clone(&queue),
Expand Down
2 changes: 1 addition & 1 deletion cli/src/samples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn get_config_toml(

let mut raw = toml::Table::new();
iroha_config::base::toml::Writer::new(&mut raw)
.write("chain_id", chain_id)
.write("chain", chain_id)
.write("public_key", public_key)
.write("private_key", ExposedPrivateKey(private_key))
.write(["sumeragi", "trusted_peers"], peers)
Expand Down
27 changes: 13 additions & 14 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ impl_query_output! {
#[display(fmt = "{}@{torii_url}", "key_pair.public_key()")]
pub struct Client {
/// Unique id of the blockchain. Used for simple replay attack protection.
pub chain_id: ChainId,
pub chain: ChainId,
/// Url for accessing Iroha node
pub torii_url: Url,
/// Accounts keypair
Expand All @@ -372,7 +372,7 @@ pub struct Client {
/// Transaction status timeout
pub transaction_status_timeout: Duration,
/// Current account
pub account_id: AccountId,
pub account: AccountId,
/// Http headers which will be appended to each request
pub headers: HashMap<String, String>,
/// If `true` add nonce, which makes different hashes for
Expand Down Expand Up @@ -435,8 +435,8 @@ impl Client {
#[inline]
pub fn with_headers(
Config {
chain_id,
account_id,
chain,
account,
torii_api_url,
key_pair,
basic_auth,
Expand All @@ -454,12 +454,12 @@ impl Client {
}

Self {
chain_id,
chain,
torii_url: torii_api_url,
key_pair,
transaction_ttl: Some(transaction_ttl),
transaction_status_timeout,
account_id,
account,
headers,
add_transaction_nonce: transaction_add_nonce,
}
Expand All @@ -474,7 +474,7 @@ impl Client {
instructions: impl Into<Executable>,
metadata: UnlimitedMetadata,
) -> SignedTransaction {
let tx_builder = TransactionBuilder::new(self.chain_id.clone(), self.account_id.clone());
let tx_builder = TransactionBuilder::new(self.chain.clone(), self.account.clone());

let mut tx_builder = match instructions.into() {
Executable::Instructions(instructions) => tx_builder.with_instructions(instructions),
Expand Down Expand Up @@ -836,7 +836,7 @@ impl Client {
where
<R::Output as TryFrom<QueryOutputBox>>::Error: Into<eyre::Error>,
{
let query_builder = ClientQueryBuilder::new(request, self.account_id.clone())
let query_builder = ClientQueryBuilder::new(request, self.account.clone())
.with_filter(filter)
.with_pagination(pagination)
.with_sorting(sorting)
Expand Down Expand Up @@ -1619,9 +1619,9 @@ mod tests {
fn config_factory() -> Config {
let (account_id, key_pair) = gen_account_in("wonderland");
Config {
chain_id: ChainId::from("00000000-0000-0000-0000-000000000000"),
chain: ChainId::from("00000000-0000-0000-0000-000000000000"),
key_pair,
account_id,
account: account_id,
torii_api_url: "http://127.0.0.1:8080".parse().unwrap(),
basic_auth: None,
transaction_add_nonce: false,
Expand All @@ -1644,10 +1644,9 @@ mod tests {
assert_ne!(tx1.hash(), tx2.hash());

let tx2 = {
let mut tx =
TransactionBuilder::new(client.chain_id.clone(), client.account_id.clone())
.with_executable(tx1.instructions().clone())
.with_metadata(tx1.metadata().clone());
let mut tx = TransactionBuilder::new(client.chain.clone(), client.account.clone())
.with_executable(tx1.instructions().clone())
.with_metadata(tx1.metadata().clone());

tx.set_creation_time(tx1.creation_time());
if let Some(nonce) = tx1.nonce() {
Expand Down
8 changes: 4 additions & 4 deletions client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ pub struct BasicAuth {
#[derive(Clone, Debug, Serialize)]
#[allow(missing_docs)]
pub struct Config {
pub chain_id: ChainId,
pub account_id: AccountId,
pub chain: ChainId,
pub account: AccountId,
pub key_pair: KeyPair,
pub basic_auth: Option<BasicAuth>,
pub torii_api_url: Url,
Expand Down Expand Up @@ -108,15 +108,15 @@ mod tests {

fn config_sample() -> toml::Table {
toml::toml! {
chain_id = "00000000-0000-0000-0000-000000000000"
chain = "00000000-0000-0000-0000-000000000000"
torii_url = "http://127.0.0.1:8080/"

[basic_auth]
web_login = "mad_hatter"
password = "ilovetea"

[account]
domain_id = "wonderland"
domain = "wonderland"
public_key = "ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03"
private_key = "802640CCF31D85E3B32A4BEA59987CE0C78E3B8E2DB93881468AB2435FE45D5C9DCD53CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03"

Expand Down
12 changes: 6 additions & 6 deletions client/src/config/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::config::BasicAuth;
#[derive(Clone, Debug, ReadConfig)]
#[allow(missing_docs)]
pub struct Root {
pub chain_id: ChainId,
pub chain: ChainId,
#[config(env = "TORII_URL")]
pub torii_url: WithOrigin<Url>,
pub basic_auth: Option<BasicAuth>,
Expand Down Expand Up @@ -44,12 +44,12 @@ impl Root {
/// If a set of validity errors occurs.
pub fn parse(self) -> error_stack::Result<super::Config, ParseError> {
let Self {
chain_id,
chain: chain_id,
torii_url,
basic_auth,
account:
Account {
domain_id,
domain: domain_id,
public_key,
private_key,
},
Expand Down Expand Up @@ -98,8 +98,8 @@ impl Root {
emitter.into_result()?;

Ok(super::Config {
chain_id,
account_id,
chain: chain_id,
account: account_id,
key_pair: key_pair.unwrap(),
torii_api_url: torii_url.into_value(),
basic_auth,
Expand All @@ -113,7 +113,7 @@ impl Root {
#[derive(Debug, Clone, ReadConfig)]
#[allow(missing_docs)]
pub struct Account {
pub domain_id: DomainId,
pub domain: DomainId,
pub public_key: WithOrigin<PublicKey>,
pub private_key: WithOrigin<PrivateKey>,
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ pub mod samples {
.parse()
.expect("should be valid");
Config {
chain_id,
chain: chain_id,
key_pair,
torii_api_url,
account_id,
account: account_id,
basic_auth: None,
transaction_ttl: DEFAULT_TRANSACTION_TIME_TO_LIVE,
transaction_status_timeout: DEFAULT_TRANSACTION_STATUS_TIMEOUT,
Expand Down
18 changes: 9 additions & 9 deletions client/tests/integration/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn client_register_asset_should_add_asset_once_but_not_twice() -> Result<()> {
let assets = result.collect::<QueryResult<Vec<_>>>().expect("Valid");

assets.iter().any(|asset| {
asset.id().definition_id == asset_definition_id
*asset.id().definition() == asset_definition_id
&& *asset.value() == AssetValue::Numeric(Numeric::ZERO)
})
})?;
Expand Down Expand Up @@ -77,7 +77,7 @@ fn unregister_asset_should_remove_asset_from_account() -> Result<()> {

assets
.iter()
.any(|asset| asset.id().definition_id == asset_definition_id)
.any(|asset| *asset.id().definition() == asset_definition_id)
})?;

test_client.submit(unregister_asset)?;
Expand All @@ -88,7 +88,7 @@ fn unregister_asset_should_remove_asset_from_account() -> Result<()> {

assets
.iter()
.all(|asset| asset.id().definition_id != asset_definition_id)
.all(|asset| *asset.id().definition() != asset_definition_id)
})?;

Ok(())
Expand Down Expand Up @@ -120,7 +120,7 @@ fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount() ->
let assets = result.collect::<QueryResult<Vec<_>>>().expect("Valid");

assets.iter().any(|asset| {
asset.id().definition_id == asset_definition_id
*asset.id().definition() == asset_definition_id
&& *asset.value() == AssetValue::Numeric(quantity)
})
})?;
Expand Down Expand Up @@ -151,7 +151,7 @@ fn client_add_big_asset_quantity_to_existing_asset_should_increase_asset_amount(
let assets = result.collect::<QueryResult<Vec<_>>>().expect("Valid");

assets.iter().any(|asset| {
asset.id().definition_id == asset_definition_id
*asset.id().definition() == asset_definition_id
&& *asset.value() == AssetValue::Numeric(quantity)
})
})?;
Expand Down Expand Up @@ -183,7 +183,7 @@ fn client_add_asset_with_decimal_should_increase_asset_amount() -> Result<()> {
let assets = result.collect::<QueryResult<Vec<_>>>().expect("Valid");

assets.iter().any(|asset| {
asset.id().definition_id == asset_definition_id
*asset.id().definition() == asset_definition_id
&& *asset.value() == AssetValue::Numeric(quantity)
})
})?;
Expand All @@ -202,7 +202,7 @@ fn client_add_asset_with_decimal_should_increase_asset_amount() -> Result<()> {
let assets = result.collect::<QueryResult<Vec<_>>>().expect("Valid");

assets.iter().any(|asset| {
asset.id().definition_id == asset_definition_id
*asset.id().definition() == asset_definition_id
&& *asset.value() == AssetValue::Numeric(sum)
})
})?;
Expand Down Expand Up @@ -298,13 +298,13 @@ fn find_rate_and_make_exchange_isi_should_succeed() {
let instruction = Grant::permission(
Permission::new(
"CanTransferUserAsset".parse().unwrap(),
json!({ "asset_id": asset_id }),
json!({ "asset": asset_id }),
),
alice_id.clone(),
);
let transaction = TransactionBuilder::new(
ChainId::from("00000000-0000-0000-0000-000000000000"),
asset_id.account_id().clone(),
asset_id.account().clone(),
)
.with_instructions([instruction])
.sign(&owner_key_pair);
Expand Down
2 changes: 1 addition & 1 deletion client/tests/integration/asset_propagation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount_on_a
let assets = result.collect::<QueryResult<Vec<_>>>().expect("Valid");

assets.iter().any(|asset| {
asset.id().definition_id == asset_definition_id
*asset.id().definition() == asset_definition_id
&& *asset.value() == AssetValue::Numeric(quantity)
})
},
Expand Down
16 changes: 8 additions & 8 deletions client/tests/integration/domain_owner_permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn domain_owner_domain_permissions() -> Result<()> {
// Granting a respective token also allows "bob@kingdom" to do so
let token = Permission::new(
"CanRegisterAssetDefinitionInDomain".parse().unwrap(),
json!({ "domain_id": kingdom_id }),
json!({ "domain": kingdom_id }),
);
test_client.submit_blocking(Grant::permission(token.clone(), bob_id.clone()))?;
let transaction = TransactionBuilder::new(chain_id, bob_id.clone())
Expand All @@ -66,7 +66,7 @@ fn domain_owner_domain_permissions() -> Result<()> {
// check that "alice@wonderland" as owner of domain can grant and revoke domain related permission tokens
let token = Permission::new(
"CanUnregisterDomain".parse().unwrap(),
json!({ "domain_id": kingdom_id }),
json!({ "domain": kingdom_id }),
);
test_client.submit_blocking(Grant::permission(token.clone(), bob_id.clone()))?;
test_client.submit_blocking(Revoke::permission(token, bob_id))?;
Expand Down Expand Up @@ -106,7 +106,7 @@ fn domain_owner_account_permissions() -> Result<()> {
let bob_id = BOB_ID.clone();
let token = Permission::new(
"CanUnregisterAccount".parse().unwrap(),
json!({ "account_id": mad_hatter_id }),
json!({ "account": mad_hatter_id }),
);
test_client.submit_blocking(Grant::permission(token.clone(), bob_id.clone()))?;
test_client.submit_blocking(Revoke::permission(token, bob_id))?;
Expand Down Expand Up @@ -141,7 +141,7 @@ fn domain_owner_asset_definition_permissions() -> Result<()> {
// Grant permission to register asset definitions to "bob@kingdom"
let token = Permission::new(
"CanRegisterAssetDefinitionInDomain".parse().unwrap(),
json!({ "domain_id": kingdom_id }),
json!({ "domain": kingdom_id }),
);
test_client.submit_blocking(Grant::permission(token, bob_id.clone()))?;

Expand Down Expand Up @@ -172,7 +172,7 @@ fn domain_owner_asset_definition_permissions() -> Result<()> {
// check that "alice@wonderland" as owner of domain can grant and revoke asset definition related permission tokens in her domain
let token = Permission::new(
"CanUnregisterAssetDefinition".parse().unwrap(),
json!({ "asset_definition_id": coin_id }),
json!({ "asset_definition": coin_id }),
);
test_client.submit_blocking(Grant::permission(token.clone(), bob_id.clone()))?;
test_client.submit_blocking(Revoke::permission(token, bob_id))?;
Expand Down Expand Up @@ -206,7 +206,7 @@ fn domain_owner_asset_permissions() -> Result<()> {
// Grant permission to register asset definitions to "bob@kingdom"
let token = Permission::new(
"CanRegisterAssetDefinitionInDomain".parse().unwrap(),
json!({ "domain_id": kingdom_id }),
json!({ "domain": kingdom_id }),
);
test_client.submit_blocking(Grant::permission(token, bob_id.clone()))?;

Expand Down Expand Up @@ -242,7 +242,7 @@ fn domain_owner_asset_permissions() -> Result<()> {
// check that "alice@wonderland" as owner of domain can grant and revoke asset related permission tokens in her domain
let token = Permission::new(
"CanUnregisterUserAsset".parse().unwrap(),
json!({ "asset_id": bob_store_id }),
json!({ "asset": bob_store_id }),
);
test_client.submit_blocking(Grant::permission(token.clone(), bob_id.clone()))?;
test_client.submit_blocking(Revoke::permission(token, bob_id))?;
Expand Down Expand Up @@ -293,7 +293,7 @@ fn domain_owner_trigger_permissions() -> Result<()> {
// check that "alice@wonderland" as owner of domain can grant and revoke trigger related permission tokens in her domain
let token = Permission::new(
"CanUnregisterUserTrigger".parse().unwrap(),
json!({ "account_id": bob_id }),
json!({ "account": bob_id }),
);
test_client.submit_blocking(Grant::permission(token.clone(), bob_id.clone()))?;
test_client.submit_blocking(Revoke::permission(token, bob_id))?;
Expand Down
Loading
Loading