Skip to content

Commit

Permalink
Fix compile errors of standalone features (#677)
Browse files Browse the repository at this point in the history
* fix ws-client and tungstenite-client feature

* fix no-std build

* add ci checks

* taplo fmt

* fix examples

* taplo fmt
  • Loading branch information
haerdib authored Nov 28, 2023
1 parent 511be68 commit e58919a
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 9 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ jobs:
cargo build --release -p test-no-std --features node-api,
cargo build --release -p test-no-std --features primitives,

# Check build of stand-alone features.
cargo check --no-default-features,
cargo check --no-default-features --features sync-api,
cargo check --no-default-features --features jsonrpsee-client,
cargo check --no-default-features --features tungstenite-client,
cargo check --no-default-features --features ws-client,
cargo check --no-default-features --features staking-xt,
cargo check --no-default-features --features contracts-xt,
cargo check --no-default-features --features std,

# Test for 32 bit and wasm32-unknown-unknown compatibility
cargo build --target wasm32-unknown-unknown --no-default-features --features sync-api,

Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

17 changes: 14 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ async-trait = "0.1.68"
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ['derive'] }
derive_more = { version = "0.99.5" }
frame-metadata = { version = "16.0", default-features = false, features = ["current", "serde_full", "decode"] }
futures-util = { version = "0.3", default-features = false }
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
log = { version = "0.4.14", default-features = false }
maybe-async = { version = "0.2.7" }
serde = { version = "1.0.136", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.79", default-features = false }


# crates.io std only
url = { version = "2.0.0", optional = true }

Expand Down Expand Up @@ -71,27 +73,35 @@ default = ["std", "jsonrpsee-client", "sync-api"]
disable_target_static_assertions = [
"sp-runtime-interface/disable_target_static_assertions",
]
# If this is active all the code compiles in synchronous mode. Otherwise `async` is supported.

# If this is active all the code compiles in synchronous mode. If not selected, code will compile to async mode.
sync-api = ["ac-compose-macros/sync-api", "maybe-async/is_sync"]

# Use the `jsonrpsee` crate for websocket communication. Does provide sync and async support but needs a tokio runtime.
# Provides convenience functions such as subscription callbacks.
# Most examples use the `jsonrpsee` feature and can be used for reference.
jsonrpsee-client = ["std", "jsonrpsee", "futures"]

# Use the `tungstenite` crate for websocket communication. No async support but has some reconnection capabilities.
# See the example `transfer_with_tungstenite_client` on how to use it.
tungstenite-client = ["std", "tungstenite"]
tungstenite-client = ["std", "tungstenite", "sync-api"]

# Use the `ws` crate for websocket communication. No async support.
# Establishes a new connection for each request and therefore is limited in terms of performance.
# See the example `transfer_with_ws_client` on how to use it.
ws-client = ["std", "ws"]
ws-client = ["std", "ws", "sync-api"]

# Enables functionality that helps to create extrinsics for `pallet-staking`.
# See the `StakingExtrinsics` trait and the `staking_batch_payout` example to get an understanding
# of the functionality this feature provides
staking-xt = ["std", "ac-primitives/staking-xt"]

# Enables functionality that helps to create extrinsics for `pallet-contracts`.
# See the `ContractsExtrinsics` trait and the `contract_instantiate_with_code` example to get an understanding
# of the functionality this feature provides.
contracts-xt = ["std", "ac-primitives/contracts-xt"]

# Enables all std features of dependencies in case of std build.
std = [
# crates.io no_std
"codec/std",
Expand All @@ -100,6 +110,7 @@ std = [
"log/std",
"serde/std",
"serde_json/std",
"futures-util/std",
# crates.io std only
"url",
# substrate no_std
Expand Down
9 changes: 7 additions & 2 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ sp-version = { git = "https://github.com/paritytech/polkadot-sdk.git", branch =
sp-weights = { default-features = false, features = ["serde"], git = "https://github.com/paritytech/polkadot-sdk.git", branch = "master" }

# local deps
substrate-api-client = { path = "..", default-features = false, features = ["jsonrpsee-client", "tungstenite-client", "ws-client", "staking-xt", "contracts-xt"] }
substrate-api-client = { path = "..", default-features = false, features = ["jsonrpsee-client", "staking-xt", "contracts-xt"] }

[features]
default = ["sync-examples"]
sync-examples = ["substrate-api-client/std", "substrate-api-client/sync-api"]
sync-examples = [
"substrate-api-client/std",
"substrate-api-client/sync-api",
"substrate-api-client/tungstenite-client",
"substrate-api-client/ws-client",
]

[dependencies]
tokio-util = "0.7.8"
7 changes: 4 additions & 3 deletions src/api/api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ use crate::{
use ac_compose_macros::rpc_params;
use ac_node_api::metadata::Metadata;
use ac_primitives::{Config, ExtrinsicParams, SignExtrinsic};
#[cfg(not(feature = "sync-api"))]
use alloc::boxed::Box;
use codec::Decode;
use core::convert::TryFrom;
use frame_metadata::RuntimeMetadataPrefixed;
use log::{debug, info};
use sp_core::Bytes;
use sp_version::RuntimeVersion;

/// Api to talk with substrate-nodes
///
/// It is generic over the `Request` trait, so you can use any rpc-backend you like.
Expand Down Expand Up @@ -180,7 +181,7 @@ where
let metadata_future = Self::get_metadata(&client);
let runtime_version_future = Self::get_runtime_version(&client);

let (genesis_hash, metadata, runtime_version) = futures::future::try_join3(
let (genesis_hash, metadata, runtime_version) = futures_util::future::try_join3(
genesis_hash_future,
metadata_future,
runtime_version_future,
Expand Down Expand Up @@ -240,7 +241,7 @@ where
let runtime_version_future = Self::get_runtime_version(&self.client);

let (metadata, runtime_version) =
futures::future::try_join(metadata_future, runtime_version_future).await?;
futures_util::future::try_join(metadata_future, runtime_version_future).await?;

debug!("Metadata: {:?}", metadata);
info!("Runtime Version: {:?}", runtime_version);
Expand Down
2 changes: 2 additions & 0 deletions src/api/rpc_api/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ use crate::{
};
use ac_compose_macros::rpc_params;
use ac_primitives::{config::Config, UncheckedExtrinsicV4};
#[cfg(not(feature = "sync-api"))]
use alloc::boxed::Box;
use codec::{Decode, Encode};
use log::*;
use serde::de::DeserializeOwned;
Expand Down
2 changes: 2 additions & 0 deletions src/api/rpc_api/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use crate::{
};
use ac_compose_macros::rpc_params;
use ac_primitives::config::Config;
#[cfg(not(feature = "sync-api"))]
use alloc::boxed::Box;
use alloc::vec::Vec;
use log::*;
use serde::de::DeserializeOwned;
Expand Down
2 changes: 2 additions & 0 deletions src/api/rpc_api/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use crate::{
use ac_compose_macros::rpc_params;
use ac_node_api::{metadata::Metadata, EventDetails, EventRecord, Events, Phase};
use ac_primitives::config::Config;
#[cfg(not(feature = "sync-api"))]
use alloc::boxed::Box;
use alloc::{vec, vec::Vec};
use codec::Decode;
use core::marker::PhantomData;
Expand Down
2 changes: 2 additions & 0 deletions src/api/rpc_api/frame_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use crate::{
};
use ac_compose_macros::rpc_params;
use ac_primitives::{config::Config, AccountInfo};
#[cfg(not(feature = "sync-api"))]
use alloc::boxed::Box;
use alloc::{string::String, vec::Vec};
use log::*;
use sp_storage::StorageKey;
Expand Down
2 changes: 2 additions & 0 deletions src/api/rpc_api/pallet_balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use crate::{
rpc::Request,
};
use ac_primitives::config::Config;
#[cfg(not(feature = "sync-api"))]
use alloc::boxed::Box;

/// Interface to common calls of the substrate balances pallet.
#[maybe_async::maybe_async(?Send)]
Expand Down
3 changes: 2 additions & 1 deletion src/api/rpc_api/pallet_transaction_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ use crate::{
};
use ac_compose_macros::rpc_params;
use ac_primitives::{config::Config, FeeDetails, InclusionFee, NumberOrHex, RuntimeDispatchInfo};
#[cfg(not(feature = "sync-api"))]
use alloc::boxed::Box;
use core::str::FromStr;
use sp_core::Bytes;

/// Interface to common calls of the substrate transaction payment pallet.
#[maybe_async::maybe_async(?Send)]
pub trait GetTransactionPayment {
Expand Down
2 changes: 2 additions & 0 deletions src/api/rpc_api/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use crate::{
use ac_compose_macros::rpc_params;
use ac_node_api::MetadataError;
use ac_primitives::config::Config;
#[cfg(not(feature = "sync-api"))]
use alloc::boxed::Box;
use alloc::{borrow::ToOwned, string::String, vec, vec::Vec};
use codec::{Decode, Encode};
use core::cmp;
Expand Down
2 changes: 2 additions & 0 deletions src/extrinsic/balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ use ac_primitives::{
UncheckedExtrinsicV4,
};
use alloc::borrow::ToOwned;
#[cfg(not(feature = "sync-api"))]
use alloc::boxed::Box;
use codec::{Compact, Encode};

pub const BALANCES_MODULE: &str = "Balances";
Expand Down
2 changes: 2 additions & 0 deletions src/extrinsic/utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ use ac_primitives::{
config::Config, extrinsic_params::ExtrinsicParams, extrinsics::CallIndex, SignExtrinsic,
UncheckedExtrinsicV4,
};
#[cfg(not(feature = "sync-api"))]
use alloc::boxed::Box;
use alloc::{borrow::ToOwned, vec::Vec};
use codec::{Decode, Encode};

Expand Down
2 changes: 2 additions & 0 deletions src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/

use ac_primitives::RpcParams;
#[cfg(not(feature = "sync-api"))]
use alloc::boxed::Box;
use alloc::string::{String, ToString};
use serde::de::DeserializeOwned;

Expand Down

0 comments on commit e58919a

Please sign in to comment.