Skip to content

Commit

Permalink
extract FFI conversion logic to a separate module
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <marin.versic101@gmail.com>
  • Loading branch information
mversic committed Jun 3, 2022
1 parent 74fdadb commit 96ed308
Show file tree
Hide file tree
Showing 19 changed files with 819 additions and 781 deletions.
19 changes: 10 additions & 9 deletions data_model/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use core::{
#[cfg(feature = "std")]
use std::collections::btree_map;

use getset::{Getters, MutGetters, Setters};
use getset::{Getters, MutGetters};
#[cfg(feature = "ffi_api")]
use iroha_ffi::ffi_bindgen;
use iroha_macro::FromVariant;
use iroha_schema::IntoSchema;
use parity_scale_codec::{Decode, Encode};
Expand Down Expand Up @@ -48,7 +50,7 @@ pub type AssetDefinitionsMap =
)]
#[getset(get = "pub")]
#[allow(clippy::multiple_inherent_impl)]
#[cfg_attr(feature = "ffi_api", iroha_ffi::ffi_bindgen)]
#[cfg_attr(feature = "ffi_api", ffi_bindgen)]
pub struct AssetDefinitionEntry {
/// Asset definition.
#[cfg_attr(feature = "mutable_api", getset(get_mut = "pub"))]
Expand All @@ -71,7 +73,7 @@ impl Ord for AssetDefinitionEntry {
}
}

#[cfg_attr(feature = "ffi_api", iroha_ffi::ffi_bindgen)]
#[cfg_attr(feature = "ffi_api", ffi_bindgen)]
impl AssetDefinitionEntry {
/// Constructor.
pub const fn new(
Expand Down Expand Up @@ -104,7 +106,6 @@ impl AssetDefinitionEntry {
Eq,
Getters,
MutGetters,
Setters,
Decode,
Encode,
Deserialize,
Expand All @@ -113,7 +114,7 @@ impl AssetDefinitionEntry {
)]
#[getset(get = "pub")]
#[allow(clippy::multiple_inherent_impl)]
#[cfg_attr(feature = "ffi_api", iroha_ffi::ffi_bindgen)]
#[cfg_attr(feature = "ffi_api", ffi_bindgen)]
pub struct AssetDefinition {
/// An Identification of the [`AssetDefinition`].
id: <Self as Identifiable>::Id,
Expand Down Expand Up @@ -173,7 +174,7 @@ pub enum Mintable {
Debug, Clone, PartialEq, Eq, Getters, Decode, Encode, Deserialize, Serialize, IntoSchema,
)]
#[getset(get = "pub")]
#[cfg_attr(feature = "ffi_api", iroha_ffi::ffi_bindgen)]
#[cfg_attr(feature = "ffi_api", ffi_bindgen)]
pub struct Asset {
/// Component Identification.
id: <Self as Identifiable>::Id,
Expand Down Expand Up @@ -394,7 +395,7 @@ impl NewAssetDefinition {
}
}

#[cfg_attr(feature = "ffi_api", iroha_ffi::ffi_bindgen)]
#[cfg_attr(feature = "ffi_api", ffi_bindgen)]
impl NewAssetDefinition {
/// Set mintability to [`Mintable::Once`]
#[inline]
Expand All @@ -413,7 +414,7 @@ impl NewAssetDefinition {
}
}

#[cfg_attr(feature = "ffi_api", iroha_ffi::ffi_bindgen)]
#[cfg_attr(feature = "ffi_api", ffi_bindgen)]
impl AssetDefinition {
/// Construct builder for [`AssetDefinition`] identifiable by [`Id`].
#[must_use]
Expand Down Expand Up @@ -461,7 +462,7 @@ impl AssetDefinition {
}
}

#[cfg_attr(feature = "ffi_api", iroha_ffi::ffi_bindgen)]
#[cfg_attr(feature = "ffi_api", ffi_bindgen)]
impl Asset {
/// Constructor
pub fn new(
Expand Down
9 changes: 9 additions & 0 deletions data_model/src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,12 @@ pub struct Domain {
#[getset(skip)]
asset_definitions: AssetDefinitionsMap,
/// IPFS link to the `Domain` logo
// FIXME: Getter implemented manually because `getset`
// returns &Option<T> when it should return Option<&T>
#[getset(skip)]
logo: Option<IpfsPath>,
/// [`Metadata`] of this `Domain` as a key-value store.
#[getset(get = "pub")]
#[cfg_attr(feature = "mutable_api", getset(get_mut = "pub"))]
metadata: Metadata,
}
Expand Down Expand Up @@ -195,6 +199,11 @@ impl Domain {
<Self as Identifiable>::RegisteredWith::new(id)
}

/// IPFS link to the `Domain` logo
pub fn logo(&self) -> Option<&IpfsPath> {
self.logo.as_ref()
}

/// Return a reference to the [`Account`] corresponding to the account id.
#[inline]
pub fn account(&self, account_id: &<Account as Identifiable>::Id) -> Option<&Account> {
Expand Down
1 change: 1 addition & 0 deletions data_model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ pub unsafe extern "C" fn Name__from_str(
let candidate = core::slice::from_raw_parts(candidate, candidate_len);

let method_res = match core::str::from_utf8(candidate) {
// TODO: Implement error handling (https://github.com/hyperledger/iroha/issues/2252)
Err(_error) => return iroha_ffi::FfiResult::Utf8Error,
Ok(candidate) => Name::from_str(candidate),
};
Expand Down
6 changes: 4 additions & 2 deletions data_model/src/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use alloc::{
use std::collections::{btree_map, btree_set};

use getset::Getters;
#[cfg(feature = "ffi_api")]
use iroha_ffi::ffi_bindgen;
use iroha_schema::IntoSchema;
use parity_scale_codec::{Decode, Encode};
use serde::{Deserialize, Serialize};
Expand All @@ -25,7 +27,7 @@ pub type Permissions = btree_set::BTreeSet<PermissionToken>;
Debug, Clone, PartialEq, Eq, Getters, Decode, Encode, Deserialize, Serialize, IntoSchema,
)]
#[getset(get = "pub")]
#[cfg_attr(feature = "ffi_api", iroha_ffi::ffi_bindgen)]
#[cfg_attr(feature = "ffi_api", ffi_bindgen)]
pub struct PermissionToken {
/// Name of the permission rule given to account.
name: Name,
Expand All @@ -48,7 +50,7 @@ impl Ord for PermissionToken {
}
}

#[cfg_attr(feature = "ffi_api", iroha_ffi::ffi_bindgen)]
#[cfg_attr(feature = "ffi_api", ffi_bindgen)]
impl PermissionToken {
/// Constructor.
#[inline]
Expand Down
Loading

0 comments on commit 96ed308

Please sign in to comment.