Skip to content

Commit

Permalink
refactor: generic extension crate to de-duplicate code between runtim…
Browse files Browse the repository at this point in the history
…es (#163)
  • Loading branch information
chungquantin committed Sep 6, 2024
1 parent 29f1dad commit 45d7508
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 62 deletions.
33 changes: 5 additions & 28 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -147,33 +147,10 @@ xcm = { version = "14.0.3", package = "staging-xcm", default-features = false }
xcm-builder = { version = "15.0.0", package = "staging-xcm-builder", default-features = false }
xcm-executor = { version = "15.0.0", package = "staging-xcm-executor", default-features = false }

# Cumulus
asset-hub-rococo-runtime = { version = "0.19.0", default-features = false }
asset-test-utils = { version = "15.0.0", default-features = false }
color-print = "0.3.4"
cumulus-client-cli = "0.15.0"
cumulus-client-collator = "0.15.0"
cumulus-client-consensus-aura = "0.15.0"
cumulus-client-consensus-common = "0.15.0"
cumulus-client-consensus-proposer = "0.14.0"
cumulus-client-service = "0.15.0"
cumulus-pallet-aura-ext = { version = "0.15.0", default-features = false }
cumulus-pallet-parachain-system = { version = "0.15.0", default-features = false }
cumulus-pallet-session-benchmarking = { version = "17.0.0", default-features = false }
cumulus-pallet-xcm = { version = "0.15.0", default-features = false }
cumulus-pallet-xcmp-queue = { version = "0.15.0", default-features = false }
cumulus-primitives-aura = { version = "0.14.0", default-features = false }
cumulus-primitives-core = { version = "0.14.0", default-features = false }
cumulus-primitives-parachain-inherent = "0.14.0"
cumulus-primitives-storage-weight-reclaim = { version = "6.0.2", default-features = false }
cumulus-primitives-utility = { version = "0.15.0", default-features = false }
cumulus-relay-chain-interface = "0.15.0"
emulated-integration-tests-common = { version = "11.0.0", default-features = false }
pallet-collator-selection = { version = "17.0.0", default-features = false }
parachain-info = { version = "0.15.0", package = "staging-parachain-info", default-features = false }
parachains-common = { version = "15.0.0", default-features = false }

asset-hub-rococo-runtime = { version = "0.19.0", default-features = false } # Cumulus


# TODO: Paseo (note: using polkadot as stopgap until paseo updated to polkadot sdk v1.14.0)
asset-hub-paseo-runtime = { git = "https://github.com/polkadot-fellows/runtimes", default-features = false, package = "asset-hub-polkadot-runtime" }
paseo-runtime = { git = "https://github.com/polkadot-fellows/runtimes", default-features = false, package = "polkadot-runtime" }
paseo-runtime-constants = { git = "https://github.com/polkadot-fellows/runtimes", default-features = false, package = "polkadot-runtime-constants" }
paseo-runtime = { git = "https://github.com/paseo-network/runtimes/", tag = "v1.2.5-system-chains", default-features = false }
paseo-runtime-constants = { git = "https://github.com/paseo-network/runtimes/", tag = "v1.2.5-system-chains", default-features = false }
52 changes: 26 additions & 26 deletions extension/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[package]
name = "pop-chain-extension"
version = "0.1.0"
authors.workspace = true
description.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true
edition.workspace = true
homepage.workspace = true
license.workspace = true
name = "pop-chain-extension"
publish = false
repository.workspace = true
version = "0.1.0"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
targets = [ "x86_64-unknown-linux-gnu" ]

[dependencies]
codec.workspace = true
Expand All @@ -36,25 +36,25 @@ scale-info.workspace = true
sp-io.workspace = true

[features]
default = ["std"]
std = [
"log/std",
"codec/std",
"frame-support/std",
"frame-system/std",
"pallet-balances/std",
"pallet-contracts/std",
"pallet-timestamp/std",
"sp-runtime/std",
"sp-core/std",
"sp-io/std",
"sp-std/std",
]
default = [ "std" ]
runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-contracts/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-contracts/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
std = [
"codec/std",
"frame-support/std",
"frame-system/std",
"log/std",
"pallet-balances/std",
"pallet-contracts/std",
"pallet-timestamp/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
]
41 changes: 33 additions & 8 deletions runtime/devnet/src/config/api.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,47 @@
use crate::{config::assets::TrustBackedAssetsInstance, fungibles, Runtime, RuntimeCall};
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::traits::Contains;
use pop_chain_extension::{CallFilter, ReadState};
use sp_std::vec::Vec;

/// A query of runtime state.
#[derive(Encode, Decode, Debug, MaxEncodedLen)]
#[repr(u8)]
pub enum RuntimeRead<T: fungibles::Config> {
pub enum RuntimeRead {
/// Fungible token queries.
#[codec(index = 150)]
Fungibles(fungibles::Read<T>),
Fungibles(fungibles::Read<Runtime>),
}

/// A type to identify allowed calls to the Runtime from the API.
pub struct AllowedApiCalls;
/// A struct that implement requirements for the Pop API chain extension.
#[derive(Default)]
pub struct Extension;
impl ReadState for Extension {
type StateQuery = RuntimeRead;

impl Contains<RuntimeCall> for AllowedApiCalls {
/// Allowed runtime calls from the API.
fn contains(c: &RuntimeCall) -> bool {
fn contains(c: &Self::StateQuery) -> bool {
use fungibles::Read::*;
matches!(
c,
RuntimeRead::Fungibles(
TotalSupply(..)
| BalanceOf { .. } | Allowance { .. }
| TokenName(..) | TokenSymbol(..)
| TokenDecimals(..) | AssetExists(..)
)
)
}

fn read(read: RuntimeRead) -> Vec<u8> {
match read {
RuntimeRead::Fungibles(key) => fungibles::Pallet::read_state(key),
}
}
}

impl CallFilter for Extension {
type Call = RuntimeCall;

fn contains(c: &Self::Call) -> bool {
use fungibles::Call::*;
matches!(
c,
Expand Down

0 comments on commit 45d7508

Please sign in to comment.