Skip to content

Commit 0fa9530

Browse files
committed
[refactor]: Rename item identifiers so that they are globally unique
Signed-off-by: Marin Veršić <marin.versic101@gmail.com>
1 parent 726f5ea commit 0fa9530

37 files changed

+218
-5640
lines changed

cli/src/samples.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use iroha_config::{
88
torii::{uri::DEFAULT_API_URL, DEFAULT_TORII_P2P_ADDR, DEFAULT_TORII_TELEMETRY_URL},
99
};
1010
use iroha_crypto::{KeyPair, PublicKey};
11-
use iroha_data_model::peer::Id as PeerId;
11+
use iroha_data_model::peer::PeerId;
1212

1313
/// Get sample trusted peers. The public key must be the same as `configuration.public_key`
1414
///

client/examples/tutorial.rs

+9-17
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,13 @@ fn domain_registration_test(config: &Configuration) -> Result<(), Error> {
9393

9494
fn account_definition_test() -> Result<(), Error> {
9595
// #region account_definition_comparison
96-
use iroha_data_model::{account::Id as AccountIdStruct, prelude::AccountId};
96+
use iroha_data_model::prelude::AccountId;
9797

98-
// Create an `iroha_data_model::account::Id` instance
98+
// Create an `iroha_data_model::AccountId` instance
9999
// with a DomainId instance and a Domain ID for an account
100-
let longhand_account_id = AccountIdStruct {
101-
name: "white_rabbit".parse()?,
102-
domain_id: "looking_glass".parse()?,
103-
};
100+
let longhand_account_id = AccountId::new("white_rabbit".parse()?, "looking_glass".parse()?);
104101
let account_id: AccountId = "white_rabbit@looking_glass"
105-
.parse::<AccountIdStruct>()
102+
.parse()
106103
.expect("Valid, because the string contains no whitespace, has a single '@' character and is not empty after");
107104

108105
// Check that two ways to define an account match
@@ -119,7 +116,6 @@ fn account_registration_test(config: &Configuration) -> Result<(), Error> {
119116
use iroha_client::client::Client;
120117
use iroha_crypto::KeyPair;
121118
use iroha_data_model::{
122-
account::Id as AccountIdStruct,
123119
metadata::UnlimitedMetadata,
124120
prelude::{Account, AccountId, Instruction, RegisterBox},
125121
};
@@ -129,10 +125,9 @@ fn account_registration_test(config: &Configuration) -> Result<(), Error> {
129125
let iroha_client: Client = Client::new(&config)?;
130126

131127
// #region register_account_create
132-
// Create an AccountId instance by providing
133-
// the account and domain name
128+
// Create an AccountId instance by providing the account and domain name
134129
let account_id: AccountId = "white_rabbit@looking_glass"
135-
.parse::<AccountIdStruct>()
130+
.parse()
136131
.expect("Valid, because the string contains no whitespace, has a single '@' character and is not empty after");
137132
// #endregion register_account_create
138133

@@ -169,11 +164,8 @@ fn asset_registration_test(config: &Configuration) -> Result<(), Error> {
169164
use std::str::FromStr as _;
170165

171166
use iroha_client::client::Client;
172-
use iroha_data_model::{
173-
account::Id as AccountIdStruct,
174-
prelude::{
175-
AccountId, AssetDefinition, AssetDefinitionId, AssetId, IdBox, MintBox, RegisterBox,
176-
},
167+
use iroha_data_model::prelude::{
168+
AccountId, AssetDefinition, AssetDefinitionId, AssetId, IdBox, MintBox, RegisterBox,
177169
};
178170
// #endregion register_asset_crates
179171

@@ -197,7 +189,7 @@ fn asset_registration_test(config: &Configuration) -> Result<(), Error> {
197189

198190
// Create an account using the previously defined asset
199191
let account_id: AccountId = "white_rabbit@looking_glass"
200-
.parse::<AccountIdStruct>()
192+
.parse()
201193
.expect("Valid, because the string contains no whitespace, has a single '@' character and is not empty after");
202194

203195
// #region register_asset_mint_submit

config/src/iroha.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl ConfigurationProxy {
111111
// former and overwritten silently in case of difference
112112
if let Some(torii_proxy) = &mut self.torii {
113113
if sumeragi_proxy.peer_id.is_none() {
114-
sumeragi_proxy.peer_id = Some(iroha_data_model::peer::Id::new(
114+
sumeragi_proxy.peer_id = Some(iroha_data_model::peer::PeerId::new(
115115
&torii_proxy.p2p_addr.clone().ok_or_else(|| {
116116
eyre::eyre!("Torii `p2p_addr` field has `None` value")
117117
})?,

core/src/smartcontracts/wasm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ impl<'wrld> Runtime<'wrld> {
617617
&self,
618618
wsv: &WorldStateView,
619619
authority: &<Account as Identifiable>::Id,
620-
id: &validator::Id,
620+
id: &validator::ValidatorId,
621621
module: &wasmtime::Module,
622622
operation: &permission::validator::NeedsPermissionBox,
623623
) -> Result<permission::validator::Verdict> {

core/src/validator.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use core::fmt::{self, Debug, Formatter};
55
use dashmap::DashMap;
66
use iroha_data_model::{
77
permission::validator::{
8-
DenialReason, Id, NeedsPermission as _, NeedsPermissionBox, Type, Validator,
8+
DenialReason, NeedsPermission as _, NeedsPermissionBox, Type, Validator, ValidatorId,
99
},
1010
prelude::Account,
1111
Identifiable,
@@ -47,8 +47,8 @@ pub type Result<T, E = Error> = core::result::Result<T, E>;
4747
/// [`Deny`](iroha_data_model::permission::validator::Verdict::Deny) verdict.
4848
#[derive(Clone)]
4949
pub struct Chain {
50-
all_validators: DashMap<Id, LoadedValidator>,
51-
concrete_type_validators: DashMap<Type, Vec<Id>>,
50+
all_validators: DashMap<ValidatorId, LoadedValidator>,
51+
concrete_type_validators: DashMap<Type, Vec<ValidatorId>>,
5252
/// Engine for WASM [`Runtime`](wasm::Runtime) to execute validators.
5353
engine: wasmtime::Engine,
5454
}
@@ -79,7 +79,7 @@ impl Default for Chain {
7979
/// [`validate()`](Chain::validate) step.
8080
#[derive(Clone)]
8181
struct LoadedValidator {
82-
id: Id,
82+
id: ValidatorId,
8383
validator_type: Type,
8484
module: wasmtime::Module,
8585
}
@@ -143,7 +143,7 @@ impl Chain {
143143
/// Return `true` if the validator was removed
144144
/// and `false` if no validator with the given id was found.
145145
#[allow(clippy::expect_used)]
146-
pub fn remove_validator(&self, id: &Id) -> bool {
146+
pub fn remove_validator(&self, id: &ValidatorId) -> bool {
147147
self.all_validators.get(id).map_or(false, |entry| {
148148
let type_ = &entry.validator_type;
149149

@@ -207,7 +207,7 @@ impl Chain {
207207
runtime: &wasm::Runtime,
208208
wsv: &WorldStateView,
209209
authority: &<Account as Identifiable>::Id,
210-
validator_id: &iroha_data_model::permission::validator::Id,
210+
validator_id: &iroha_data_model::permission::validator::ValidatorId,
211211
operation: &NeedsPermissionBox,
212212
) -> Result<()> {
213213
let validator = self.all_validators.get(validator_id).expect(

data_model/derive/src/api.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ pub fn process_item(mut input: syn::DeriveInput) -> TokenStream {
1010
}
1111

1212
let non_transparent_item = quote! {
13-
#[cfg(not(feature = "transparent_api"))]
13+
#[cfg(all(not(test), not(feature = "transparent_api")))]
1414
#input
1515
};
1616

1717
input.vis = parse_quote! {pub};
1818
let transparent_item = quote! {
19-
#[cfg(feature = "transparent_api")]
19+
#[cfg(any(test, feature = "transparent_api"))]
2020
#input
2121
};
2222

@@ -45,11 +45,11 @@ fn process_pub_item(input: syn::DeriveInput) -> TokenStream {
4545
}
4646

4747
quote! {
48-
#[cfg(feature = "transparent_api")]
48+
#[cfg(any(test, feature = "transparent_api"))]
4949
#(#field_attrs)*
5050
pub #field_name: #field_ty,
5151

52-
#[cfg(not(feature = "transparent_api"))]
52+
#[cfg(all(not(test), not(feature = "transparent_api")))]
5353
#(#field_attrs)*
5454
pub(crate) #field_name: #field_ty,
5555
}
@@ -73,11 +73,11 @@ fn process_pub_item(input: syn::DeriveInput) -> TokenStream {
7373
}
7474

7575
quote! {
76-
#[cfg(feature = "transparent_api")]
76+
#[cfg(any(test, feature = "transparent_api"))]
7777
#(#field_attrs)*
7878
pub #field_ty,
7979

80-
#[cfg(not(feature = "transparent_api"))]
80+
#[cfg(all(not(test), not(feature = "transparent_api")))]
8181
#(#field_attrs)*
8282
pub(crate) #field_ty,
8383
}
@@ -120,11 +120,11 @@ fn process_pub_item(input: syn::DeriveInput) -> TokenStream {
120120

121121
quote! {
122122
#(#field_attrs)*
123-
#[cfg(feature = "transparent_api")]
123+
#[cfg(any(test, feature = "transparent_api"))]
124124
pub #field_name: #field_ty,
125125

126126
#(#field_attrs)*
127-
#[cfg(not(feature = "transparent_api"))]
127+
#[cfg(all(not(test), not(feature = "transparent_api")))]
128128
pub(crate) #field_name: #field_ty,
129129
}
130130
});

data_model/derive/src/lib.rs

+17-10
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,35 @@ impl syn::parse::Parse for Items {
3939
/// use iroha_data_model_derive::model;
4040
///
4141
/// model! {
42-
/// struct DataModel {
42+
/// pub struct DataModel1 {
43+
/// pub item1: u32,
44+
/// item2: u64
45+
/// }
46+
///
47+
/// pub(crate) struct DataModel2 {
4348
/// pub item1: u32,
4449
/// item2: u64
4550
/// }
4651
/// }
4752
///
4853
/// /* will produce:
49-
/// #[cfg(feature = "transparent_api")]
50-
/// pub struct DataModel {
51-
/// #[cfg(feature = "transparent_api")]
54+
/// pub struct DataModel1 {
55+
/// #[cfg(any(test, feature = "transparent_api"))]
5256
/// pub item1: u32,
53-
/// #[cfg(not(feature = "transparent_api"))]
57+
/// #[cfg(all(not(test), not(feature = "transparent_api")))]
5458
/// pub(crate) item1: u32,
5559
/// item2: u64
5660
/// }
5761
///
58-
/// #[cfg(not(feature = "transparent_api"))]
59-
/// struct DataModel {
60-
/// #[cfg(feature = "transparent_api")]
62+
/// #[cfg(all(not(test), not(feature = "transparent_api")))]
63+
/// pub struct DataModel2 {
64+
/// pub item1: u32,
65+
/// item2: u64
66+
/// }
67+
///
68+
/// #[cfg(any(test, feature = "transparent_api"))]
69+
/// struct DataModel2 {
6170
/// pub item1: u32,
62-
/// #[cfg(not(feature = "transparent_api"))]
63-
/// pub(crate) item1: u32,
6471
/// item2: u64
6572
/// }
6673
/// */

data_model/derive/src/partially_tagged.rs

-2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ pub fn impl_partially_tagged_serialize(enum_: &PartiallyTaggedEnum) -> TokenStre
152152

153153
#[derive(::serde::Serialize)]
154154
#[serde(untagged)]
155-
#[allow(variant_size_differences)]
156155
enum SerializeHelper<'re> {
157156
#(
158157
#(
@@ -215,7 +214,6 @@ pub fn impl_partially_tagged_deserialize(enum_: &PartiallyTaggedEnum) -> TokenSt
215214

216215
#[derive(::serde::Deserialize)]
217216
#[serde(untagged)]
218-
#[allow(variant_size_differences)]
219217
enum DeserializeHelper {
220218
#(
221219
#(

data_model/derive/tests/ui_fail/transparent_api_private_field.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use iroha_data_model::account::Id as AccountId;
1+
use iroha_data_model::account::AccountId;
22

33
fn main() {
44
let account_id: AccountId = "alice@wonderland".parse().expect("Valid account id");

data_model/derive/tests/ui_fail/transparent_api_private_field.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0616]: field `name` of struct `iroha_data_model::account::Id` is private
1+
error[E0616]: field `name` of struct `iroha_data_model::account::AccountId` is private
22
--> tests/ui_fail/transparent_api_private_field.rs:5:35
33
|
44
5 | println!("ID: {}", account_id.name);

data_model/src/account.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ use parity_scale_codec::{Decode, Encode};
2020
use serde::{Deserialize, Serialize};
2121
use serde_with::{DeserializeFromStr, SerializeDisplay};
2222

23-
#[cfg(feature = "transparent_api")]
24-
use crate::Registrable;
2523
use crate::{
2624
asset::{
2725
prelude::{Asset, AssetId},
@@ -58,15 +56,15 @@ model! {
5856
/// # Examples
5957
///
6058
/// ```rust
61-
/// use iroha_data_model::account::Id;
59+
/// use iroha_data_model::account::AccountId;
6260
///
63-
/// let id = "user@company".parse::<Id>().expect("Valid");
61+
/// let id = "user@company".parse::<AccountId>().expect("Valid");
6462
/// ```
6563
#[derive(Debug, Display, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Constructor, Getters, Decode, Encode, DeserializeFromStr, SerializeDisplay, IntoSchema)]
6664
#[display(fmt = "{name}@{domain_id}")]
6765
#[getset(get = "pub")]
6866
#[ffi_type]
69-
pub struct Id {
67+
pub struct AccountId {
7068
/// [`Account`]'s name.
7169
pub name: Name,
7270
/// [`Account`]'s [`Domain`](`crate::domain::Domain`) id.
@@ -80,7 +78,7 @@ model! {
8078
#[ffi_type]
8179
pub struct Account {
8280
/// An Identification of the [`Account`].
83-
pub id: Id,
81+
pub id: AccountId,
8482
/// Assets in this [`Account`].
8583
pub assets: AssetsMap,
8684
/// [`Account`]'s signatories.
@@ -116,14 +114,14 @@ model! {
116114
pub struct SignatureCheckCondition(pub EvaluatesTo<bool>);
117115
}
118116

119-
impl Id {
120-
#[cfg(feature = "transparent_api")]
117+
impl AccountId {
118+
#[cfg(any(test, feature = "transparent_api"))]
121119
const GENESIS_ACCOUNT_NAME: &str = "genesis";
122120

123121
/// Construct [`Id`] of the genesis account.
124122
#[inline]
125123
#[must_use]
126-
#[cfg(feature = "transparent_api")]
124+
#[cfg(any(test, feature = "transparent_api"))]
127125
pub fn genesis() -> Self {
128126
Self {
129127
name: Self::GENESIS_ACCOUNT_NAME.parse().expect("Valid"),
@@ -180,7 +178,7 @@ impl Account {
180178
}
181179
}
182180

183-
#[cfg(feature = "transparent_api")]
181+
#[cfg(any(test, feature = "transparent_api"))]
184182
impl Account {
185183
/// Add [`Asset`] into the [`Account`] returning previous asset stored under the same id
186184
#[inline]
@@ -282,8 +280,8 @@ impl Default for SignatureCheckCondition {
282280
}
283281
}
284282

285-
#[cfg(feature = "transparent_api")]
286-
impl Registrable for NewAccount {
283+
#[cfg(any(test, feature = "transparent_api"))]
284+
impl crate::Registrable for NewAccount {
287285
type Target = Account;
288286

289287
#[must_use]
@@ -326,7 +324,7 @@ impl FromIterator<Account> for crate::Value {
326324
}
327325

328326
/// Account Identification is represented by `name@domain_name` string.
329-
impl FromStr for Id {
327+
impl FromStr for AccountId {
330328
type Err = ParseError;
331329

332330
fn from_str(string: &str) -> Result<Self, Self::Err> {
@@ -335,7 +333,7 @@ impl FromStr for Id {
335333
Some(("", _)) => Err(ParseError {
336334
reason: "`AccountId` cannot be empty",
337335
}),
338-
Some((name, domain_id)) if !name.is_empty() && !domain_id.is_empty() => Ok(Id {
336+
Some((name, domain_id)) if !name.is_empty() && !domain_id.is_empty() => Ok(AccountId {
339337
name: name.parse()?,
340338
domain_id: domain_id.parse()?,
341339
}),
@@ -348,5 +346,5 @@ impl FromStr for Id {
348346

349347
/// The prelude re-exports most commonly used traits, structs and macros from this crate.
350348
pub mod prelude {
351-
pub use super::{Account, Id as AccountId, SignatureCheckCondition};
349+
pub use super::{Account, AccountId, SignatureCheckCondition};
352350
}

0 commit comments

Comments
 (0)