Skip to content

Commit

Permalink
build(deps): allow specifying ink version via feature
Browse files Browse the repository at this point in the history
  • Loading branch information
evilrobot-01 committed Apr 22, 2024
1 parent 2229bae commit b7cebe1
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
6 changes: 4 additions & 2 deletions pop-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand All @@ -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"]
4 changes: 2 additions & 2 deletions pop-api/examples/balance-transfer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
4 changes: 2 additions & 2 deletions pop-api/examples/nfts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
4 changes: 2 additions & 2 deletions pop-api/examples/place-spot-order/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
4 changes: 2 additions & 2 deletions pop-api/examples/read-runtime-state/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
28 changes: 28 additions & 0 deletions pop-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*};
Expand Down Expand Up @@ -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<Vec<u8>>;

#[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;
Expand Down

0 comments on commit b7cebe1

Please sign in to comment.