From b7cebe12388f26b58839c77e88a7424ad2789656 Mon Sep 17 00:00:00 2001 From: Frank Bell Date: Mon, 22 Apr 2024 12:07:04 +0100 Subject: [PATCH] build(deps): allow specifying ink version via feature --- pop-api/Cargo.toml | 6 ++-- pop-api/examples/balance-transfer/Cargo.toml | 4 +-- pop-api/examples/nfts/Cargo.toml | 4 +-- pop-api/examples/place-spot-order/Cargo.toml | 4 +-- .../examples/read-runtime-state/Cargo.toml | 4 +-- pop-api/src/lib.rs | 28 +++++++++++++++++++ 6 files changed, 40 insertions(+), 10 deletions(-) diff --git a/pop-api/Cargo.toml b/pop-api/Cargo.toml index b1490902..d5b5d790 100644 --- a/pop-api/Cargo.toml +++ b/pop-api/Cargo.toml @@ -7,7 +7,8 @@ edition = "2021" [dependencies] enumflags2 = { version = "0.7.7" } -ink = { version = "5.0.0-rc.3", default-features = false } +inkv4 = { package = "ink", version = "4.3.0", default-features = false, optional = true } +inkv5 = { package = "ink", version = "5.0.0", default-features = false, optional = true } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale-info = { version = "2.6", default-features = false, features = ["derive"] } sp-io = { version = "23.0.0", default-features = false, features = ["disable_panic_handler", "disable_oom", "disable_allocator"] } @@ -24,10 +25,11 @@ crate-type = ["rlib"] default = ["std"] std = [ "enumflags2/std", - "ink/std", "pop-primitives/std", "scale/std", "scale-info/std", "sp-io/std", "sp-runtime/std", ] +inkv4 = ["dep:inkv4"] +inkv5 = ["dep:inkv5"] diff --git a/pop-api/examples/balance-transfer/Cargo.toml b/pop-api/examples/balance-transfer/Cargo.toml index fcac5e73..d6ecf218 100755 --- a/pop-api/examples/balance-transfer/Cargo.toml +++ b/pop-api/examples/balance-transfer/Cargo.toml @@ -5,8 +5,8 @@ authors = ["[your_name] <[your_email]>"] edition = "2021" [dependencies] -ink = { version = "5.0.0-rc.3", default-features = false } -pop-api = { path = "../../../pop-api", default-features = false } +ink = { version = "4.3.0", default-features = false } +pop-api = { path = "../../../pop-api", default-features = false, features = ["inkv4"] } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } diff --git a/pop-api/examples/nfts/Cargo.toml b/pop-api/examples/nfts/Cargo.toml index 49c49f64..f8e6d947 100755 --- a/pop-api/examples/nfts/Cargo.toml +++ b/pop-api/examples/nfts/Cargo.toml @@ -5,8 +5,8 @@ authors = ["[your_name] <[your_email]>"] edition = "2021" [dependencies] -ink = { version = "5.0.0-rc.3", default-features = false } -pop-api = { path = "../../../pop-api", default-features = false } +ink = { version = "5.0.0", default-features = false } +pop-api = { path = "../../../pop-api", default-features = false, features = ["inkv5"] } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } diff --git a/pop-api/examples/place-spot-order/Cargo.toml b/pop-api/examples/place-spot-order/Cargo.toml index a596805d..dfe62a30 100755 --- a/pop-api/examples/place-spot-order/Cargo.toml +++ b/pop-api/examples/place-spot-order/Cargo.toml @@ -5,8 +5,8 @@ authors = ["[your_name] <[your_email]>"] edition = "2021" [dependencies] -ink = { version = "5.0.0-rc.3", default-features = false } -pop-api = { path = "../../../pop-api", default-features = false } +ink = { version = "5.0.0", default-features = false } +pop-api = { path = "../../../pop-api", default-features = false, features = ["inkv5"] } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } diff --git a/pop-api/examples/read-runtime-state/Cargo.toml b/pop-api/examples/read-runtime-state/Cargo.toml index e1c898a3..d499973d 100755 --- a/pop-api/examples/read-runtime-state/Cargo.toml +++ b/pop-api/examples/read-runtime-state/Cargo.toml @@ -5,8 +5,8 @@ authors = ["[your_name] <[your_email]>"] edition = "2021" [dependencies] -ink = { version = "5.0.0-rc.3", default-features = false } -pop-api = { path = "../../../pop-api", default-features = false } +ink = { version = "4.3.0", default-features = false } +pop-api = { path = "../../../pop-api", default-features = false, features = ["inkv4"] } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } diff --git a/pop-api/src/lib.rs b/pop-api/src/lib.rs index e4590c89..59b2dcb9 100644 --- a/pop-api/src/lib.rs +++ b/pop-api/src/lib.rs @@ -3,6 +3,15 @@ pub mod primitives; pub mod v0; +#[cfg(feature = "inkv4")] +extern crate inkv4 as ink; +#[cfg(feature = "inkv5")] +extern crate inkv5 as ink; +#[cfg(all(feature = "inkv4", feature = "inkv5"))] +compile_error!("feature \"inkv4\" and feature \"inkv5\" cannot be enabled at the same time"); +#[cfg(not(any(feature = "inkv4", feature = "inkv5")))] +compile_error!("feature \"inkv4\" or feature \"inkv5\" must be enabled"); + use crate::PopApiError::{Balances, Nfts, UnknownStatusCode}; use ink::{prelude::vec::Vec, ChainExtensionInstance}; use primitives::{cross_chain::*, storage_keys::*}; @@ -65,6 +74,25 @@ impl ink::env::Environment for Environment { type ChainExtension = PopApi; } +#[cfg(feature = "inkv4")] +#[ink::chain_extension] +pub trait PopApi { + type ErrorCode = PopApiError; + + #[ink(extension = 0)] + #[allow(private_interfaces)] + fn dispatch(call: RuntimeCall) -> Result<()>; + + #[ink(extension = 1)] + #[allow(private_interfaces)] + fn read_state(key: RuntimeStateKeys) -> Result>; + + #[ink(extension = 2)] + #[allow(private_interfaces)] + fn send_xcm(xcm: CrossChainMessage) -> Result<()>; +} + +#[cfg(feature = "inkv5")] #[ink::chain_extension(extension = 909)] pub trait PopApi { type ErrorCode = PopApiError;