Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jgutierrezre committed Oct 10, 2024
2 parents 6bc63c8 + 7c447e4 commit bd32ccf
Show file tree
Hide file tree
Showing 89 changed files with 5,941 additions and 6,778 deletions.
4,774 changes: 2,679 additions & 2,095 deletions Cargo.lock

Large diffs are not rendered by default.

303 changes: 151 additions & 152 deletions Cargo.toml

Large diffs are not rendered by default.

78 changes: 39 additions & 39 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
[package]
name = "virto-common"
version = "0.1.0"
edition = "2021"
name = "virto-common"
version = "0.1.0"
edition = "2021"

[dependencies]
bs58 = { version = "0.5.0", default-features = false }
wasm-bindgen = { version = "0.2.87", optional = true }
bs58 = { version = "0.5.0", default-features = false }
wasm-bindgen = { version = "0.2.87", optional = true }

cumulus-primitives-core = { workspace = true, optional = true }
frame-support = { workspace = true, optional = true }
pallet-payments = { workspace = true, optional = true }
parity-scale-codec = { workspace = true, optional = true }
scale-info = { workspace = true, optional = true }
serde = { workspace = true, optional = true, default-features = false }
sp-runtime = { workspace = true, optional = true }
xcm = { workspace = true, optional = true }
cumulus-primitives-core = { workspace = true, optional = true }
frame-support = { workspace = true, optional = true }
pallet-payments = { workspace = true, optional = true }
parity-scale-codec = { workspace = true, optional = true }
scale-info = { workspace = true, optional = true }
serde = { workspace = true, optional = true, default-features = false }
sp-runtime = { workspace = true, optional = true }
xcm = { workspace = true, optional = true }

[dev-dependencies]
frame-support = { workspace = true, features = ["std"] }
frame-support = { workspace = true, features = ["std"] }

[features]
default = ["std"]
std = [
"bs58/std",
"cumulus-primitives-core?/std",
"frame-support?/std",
"pallet-payments?/std",
"parity-scale-codec?/std",
"scale-info?/std",
"serde?/std",
"sp-runtime?/std",
"xcm?/std",
]
alloc = []
js = ["alloc", "wasm-bindgen"]
nightly = []
runtime = [
"dep:cumulus-primitives-core",
"dep:frame-support",
"dep:pallet-payments",
"dep:parity-scale-codec",
"dep:serde",
"dep:scale-info",
"dep:sp-runtime",
"dep:xcm",
]
default = ["std"]
std = [
"bs58/std",
"cumulus-primitives-core?/std",
"frame-support?/std",
"pallet-payments?/std",
"parity-scale-codec?/std",
"scale-info?/std",
"serde?/std",
"sp-runtime?/std",
"xcm?/std",
]
alloc = []
js = ["alloc", "wasm-bindgen"]
nightly = []
runtime = [
"dep:cumulus-primitives-core",
"dep:frame-support",
"dep:pallet-payments",
"dep:parity-scale-codec",
"dep:serde",
"dep:scale-info",
"dep:sp-runtime",
"dep:xcm",
]
98 changes: 44 additions & 54 deletions common/src/multilocation_asset_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ impl From<u32> for FungibleAssetLocation {
#[cfg(feature = "runtime")]
pub mod runtime {
use super::{FungibleAssetLocation, Para};
use cumulus_primitives_core::MultiLocation;
use sp_runtime::traits::MaybeEquivalence;
use xcm::v3::{
use xcm::latest::{
Junction::{GeneralIndex, GlobalConsensus, PalletInstance, Parachain},
Junctions, NetworkId,
Location, NetworkId,
};

impl TryFrom<NetworkId> for super::NetworkId {
Expand All @@ -83,72 +82,63 @@ pub mod runtime {
}

pub struct AsFungibleAssetLocation;
impl MaybeEquivalence<MultiLocation, FungibleAssetLocation> for AsFungibleAssetLocation {
fn convert(value: &MultiLocation) -> Option<FungibleAssetLocation> {
match *value {
MultiLocation {
parents: 2,
interior: Junctions::X1(GlobalConsensus(network)),
} => Some(FungibleAssetLocation::External {
network: network.try_into().ok()?,
impl MaybeEquivalence<Location, FungibleAssetLocation> for AsFungibleAssetLocation {
fn convert(value: &Location) -> Option<FungibleAssetLocation> {
match value.unpack() {
(2, [GlobalConsensus(network)]) => Some(FungibleAssetLocation::External {
network: (*network).try_into().ok()?,
child: None,
}),
MultiLocation {
parents: 2,
interior:
Junctions::X4(GlobalConsensus(network), Parachain(id), PalletInstance(pallet), GeneralIndex(index)),
} => Some(FungibleAssetLocation::External {
network: network.try_into().ok()?,
child: Some(Para {
id: id.try_into().ok()?,
pallet,
index: index.try_into().ok()?,
}),
}),
MultiLocation {
parents: 1,
interior: Junctions::X3(Parachain(id), PalletInstance(pallet), GeneralIndex(index)),
} => Some(FungibleAssetLocation::Sibling(Para {
id: id.try_into().ok()?,
pallet,
index: index.try_into().ok()?,
})),
MultiLocation {
parents: 0,
interior: Junctions::X2(PalletInstance(13), GeneralIndex(index)),
} => Some(FungibleAssetLocation::Here(
index.try_into().expect("as it is here, we the types will match; qed"),
(2, [GlobalConsensus(network), Parachain(id), PalletInstance(pallet), GeneralIndex(index)]) => {
Some(FungibleAssetLocation::External {
network: (*network).try_into().ok()?,
child: Some(Para {
id: (*id).try_into().ok()?,
pallet: *pallet,
index: (*index).try_into().ok()?,
}),
})
}
(1, [Parachain(id), PalletInstance(pallet), GeneralIndex(index)]) => {
Some(FungibleAssetLocation::Sibling(Para {
id: (*id).try_into().ok()?,
pallet: *pallet,
index: (*index).try_into().ok()?,
}))
}
(0, [PalletInstance(13), GeneralIndex(index)]) => Some(FungibleAssetLocation::Here(
(*index)
.try_into()
.expect("as it is here, we the types will match; qed"),
)),
_ => None,
}
}

fn convert_back(value: &FungibleAssetLocation) -> Option<MultiLocation> {
fn convert_back(value: &FungibleAssetLocation) -> Option<Location> {
match *value {
FungibleAssetLocation::Here(index) => Some(MultiLocation {
parents: 0,
interior: Junctions::X2(PalletInstance(13), GeneralIndex(index.into())),
}),
FungibleAssetLocation::Sibling(Para { id, pallet, index }) => Some(MultiLocation {
parents: 1,
interior: Junctions::X3(Parachain(id.into()), PalletInstance(pallet), GeneralIndex(index.into())),
}),
FungibleAssetLocation::External { network, child: None } => Some(MultiLocation {
parents: 2,
interior: Junctions::X1(GlobalConsensus(network.into())),
}),
FungibleAssetLocation::Here(index) => {
Some(Location::new(0, [PalletInstance(13), GeneralIndex(index.into())]))
}
FungibleAssetLocation::Sibling(Para { id, pallet, index }) => Some(Location::new(
1,
[Parachain(id.into()), PalletInstance(pallet), GeneralIndex(index.into())],
)),
FungibleAssetLocation::External { network, child: None } => {
Some(Location::new(2, [GlobalConsensus(network.into())]))
}
FungibleAssetLocation::External {
network,
child: Some(Para { id, pallet, index }),
} => Some(MultiLocation {
parents: 2,
interior: Junctions::X4(
} => Some(Location::new(
2,
[
GlobalConsensus(network.into()),
Parachain(id.into()),
PalletInstance(pallet),
GeneralIndex(index.into()),
),
}),
],
)),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ benchmark pallet="" extrinsic="*":

build-container:
#!/usr/bin/env nu
'FROM docker.io/paritytech/ci-linux:production as builder
'FROM docker.io/paritytech/ci-unified:latest as builder
WORKDIR /virto
COPY . /virto
RUN cargo build --release
FROM debian:bookworm-slim
FROM debian:bullseye-slim
VOLUME /data
COPY --from=builder /virto/{{ node }} /usr/bin
ENTRYPOINT ["/usr/bin/virto-node"]
Expand Down
Loading

0 comments on commit bd32ccf

Please sign in to comment.