Skip to content

Commit

Permalink
Metadata sgx compatible (#259)
Browse files Browse the repository at this point in the history
* make metadata compatible with no_std

* include node-metadata in api-client root crate without std

* Clippy changes

Co-authored-by: echevrier <[email protected]>
  • Loading branch information
echevrier and echevrier authored Jul 6, 2022
1 parent b406701 commit 431e030
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 21 deletions.
17 changes: 14 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ members = [
[dependencies]
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
log = { version = "0.4.14", optional = true }
metadata = { version = "15.0.0", default-features = false, package = "frame-metadata", features = ["v14"] }
#TODO get from parity when our changes are accepted
metadata = { version = "15.0.0", default-features = false, git = "https://github.com/integritee-network/frame-metadata", package = "frame-metadata", features = ["v14", "full_derive"] }
#metadata = { version = "15.0.0", default-features = false, package = "frame-metadata", features = ["v14"] }
primitive-types = { version = "0.11.1", optional = true, features = ["codec"] }
serde = { version = "1.0.136", optional = true, features = ["derive"] }
serde_json = { version = "1.0.79", optional = true }
Expand All @@ -43,7 +45,7 @@ sp-runtime-interface = { version = "6.0.0", default-features = false, git = "htt

# local deps
ac-compose-macros = { path = "compose-macros", default-features = false }
ac-node-api = { path = "node-api", optional = true }
ac-node-api = { path = "node-api", default-features = false }
ac-primitives = { path = "primitives", default-features = false }

[dev-dependencies]
Expand Down Expand Up @@ -82,7 +84,7 @@ std = [
"transaction-payment/std",
# local deps
"ac-compose-macros/std",
"ac-node-api",
"ac-node-api/std",
"ac-primitives/std",
]
ws-client = ["ws"]
Expand Down
4 changes: 3 additions & 1 deletion node-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ edition = "2021"
[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", features = ['derive'], default-features = false }
derive_more = { version = "0.99.17" }
frame-metadata = { version = "15.0.0", features = ["v14"], default-features = false }
#TODO get from parity when our changes are accepted
frame-metadata = { version = "15.0.0", default-features = false, git = "https://github.com/integritee-network/frame-metadata", features = ["v14", "full_derive"] }
#frame-metadata = { version = "15.0.0", features = ["v14"], default-features = false }
hex = { version = "0.4.3", default-features = false }
log = { version = "0.4.14", default-features = false }
scale-info = { version = "2.0.1", features = ["derive", "decode"] , default-features = false }
Expand Down
3 changes: 1 addition & 2 deletions node-api/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ pub struct RawEvent {
///
/// In subxt, this was generic over a `Config` type, but it's sole usage was to derive the
/// hash type. We omitted this here and use the `ac_primitives::Hash` instead.
#[derive(Clone)]
#[cfg_attr(feature = "std", derive(Debug))]
#[derive(Clone, Debug)]
pub struct EventsDecoder {
metadata: Metadata,
marker: PhantomData<()>,
Expand Down
5 changes: 5 additions & 0 deletions node-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ use alloc::{borrow::ToOwned, vec::Vec};

use codec::{Decode, Encode};

pub use error::*;
pub use events::*;
pub use metadata::*;
pub use storage::*;

pub mod error;
pub mod events;
pub mod metadata;
Expand Down
6 changes: 2 additions & 4 deletions node-api/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ pub enum MetadataError {
}

/// Runtime metadata.
#[derive(Clone)]
#[cfg_attr(feature = "std", derive(Debug))]
#[derive(Clone, Debug, Encode, Decode)]
pub struct Metadata {
pub metadata: RuntimeMetadataLastVersion,
pub pallets: BTreeMap<String, PalletMetadata>,
Expand Down Expand Up @@ -154,8 +153,7 @@ impl Metadata {
}
}

#[derive(Clone)]
#[cfg_attr(feature = "std", derive(Debug))]
#[derive(Clone, Debug, Encode, Decode)]
pub struct PalletMetadata {
pub index: u8,
pub name: String,
Expand Down
6 changes: 2 additions & 4 deletions node-api/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ impl StorageValue {
}
}

#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug))]
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct StorageMap<K> {
_marker: PhantomData<K>,
module_prefix: Vec<u8>,
Expand All @@ -57,8 +56,7 @@ impl<K: Encode> StorageMap<K> {
}
}

#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug))]
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct StorageDoubleMap<K, Q> {
_marker: PhantomData<K>,
_marker2: PhantomData<Q>,
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub use crate::std::*;

pub use ac_primitives::*;

pub use ac_node_api::*;

#[cfg(feature = "std")]
pub use ac_compose_macros::compose_extrinsic;

Expand Down
2 changes: 1 addition & 1 deletion src/std/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::std::rpc::XtStatus;
pub use ac_node_api::metadata::{InvalidMetadataError, MetadataError};
use ac_node_api::metadata::{InvalidMetadataError, MetadataError};

pub type ApiResult<T> = Result<T, Error>;

Expand Down
4 changes: 2 additions & 2 deletions src/std/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub use crate::error::{ApiResult, Error as ApiClientError};
pub use crate::std::error::{ApiResult, Error as ApiClientError};
pub use crate::std::rpc::XtStatus;
pub use crate::utils::FromHexString;
pub use ac_node_api::metadata::{InvalidMetadataError, Metadata, MetadataError};
use ac_node_api::metadata::{Metadata, MetadataError};
use ac_primitives::{AccountData, AccountInfo, Balance, ExtrinsicParams};
pub use metadata::RuntimeMetadataPrefixed;
pub use serde_json::Value;
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#[cfg(not(feature = "std"))]
extern crate alloc;
#[cfg(not(feature = "std"))]
use alloc::{string::String, string::ToString, vec::Vec};
use alloc::{string::String, vec::Vec};

use hex::FromHexError;
use sp_core::storage::StorageKey;
Expand Down

0 comments on commit 431e030

Please sign in to comment.