difftreelog
feat add proxy pallet
in: master
3 files changed
pallets/rmrk-proxy/Cargo.tomldiffbeforeafterboth--- /dev/null
+++ b/pallets/rmrk-proxy/Cargo.toml
@@ -0,0 +1,49 @@
+[package]
+name = "pallet-rmrk-proxy"
+version = "0.1.0"
+license = "GPLv3"
+edition = "2021"
+
+[dependencies.codec]
+default-features = false
+features = ['derive']
+package = 'parity-scale-codec'
+version = '3.1.2'
+
+[dependencies]
+frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
+frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
+sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
+sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
+sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
+pallet-common = { default-features = false, path = '../common' }
+pallet-nonfungible = { default-features = false, path = "../../pallets/nonfungible" }
+# pallet-structure = { default-features = false, path = '../structure' }
+up-data-structs = { default-features = false, path = '../../primitives/data-structs' }
+# evm-coder = { default-features = false, path = '../../crates/evm-coder' }
+# pallet-evm-coder-substrate = { default-features = false, path = '../evm-coder-substrate' }
+pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.21-logs" }
+frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
+scale-info = { version = "2.0.1", default-features = false, features = ["derive"] }
+
+[features]
+default = ["std"]
+std = [
+ "frame-support/std",
+ "frame-system/std",
+ "sp-runtime/std",
+ "sp-std/std",
+ "up-data-structs/std",
+ "pallet-common/std",
+ "pallet-nonfungible/std",
+ "pallet-evm/std",
+ # "pallet-structure/std",
+ # "evm-coder/std",
+ # "pallet-evm-coder-substrate/std",
+ 'frame-benchmarking/std',
+]
+runtime-benchmarks = [
+ 'frame-benchmarking',
+ 'frame-support/runtime-benchmarks',
+ 'frame-system/runtime-benchmarks',
+]
pallets/rmrk-proxy/src/lib.rsdiffbeforeafterbothno changes
pallets/rmrk-proxy/src/misc.rsdiffbeforeafterboth--- /dev/null
+++ b/pallets/rmrk-proxy/src/misc.rs
@@ -0,0 +1,93 @@
+use super::*;
+use codec::{Encode, Decode};
+use pallet_nonfungible::NonfungibleHandle;
+
+#[macro_export]
+macro_rules! rmrk_property {
+ ($key:ident, $value:expr) => {
+ Property {
+ key: rmrk_property!($key),
+ value: $value.into()
+ }
+ };
+
+ ($key:ident) => {
+ RmrkProperty::$key.to_key()
+ };
+}
+
+macro_rules! impl_rmrk_value {
+ ($enum_name:path, decode_error: $error:ident) => {
+ impl Into<PropertyValue> for $enum_name {
+ fn into(self) -> PropertyValue {
+ self.encode().try_into().unwrap()
+ }
+ }
+
+ impl TryFrom<&PropertyValue> for $enum_name {
+ type Error = MiscError;
+
+ fn try_from(value: &PropertyValue) -> Result<Self, Self::Error> {
+ let mut value = value.as_slice();
+
+ <$enum_name>::decode(&mut value)
+ .map_err(|_| MiscError::$error)
+ }
+ }
+
+ };
+}
+
+pub enum MiscError {
+ CorruptedCollectionType,
+}
+
+impl<T: Config> From<MiscError> for Error<T> {
+ fn from(error: MiscError) -> Self {
+ match error {
+ MiscError::CorruptedCollectionType => Self::CorruptedCollectionType,
+ }
+ }
+}
+
+pub trait IntoNftCollection<T: Config> {
+ fn into_nft_collection(self) -> Result<NonfungibleHandle<T>, Error<T>>;
+}
+
+impl<T: Config> IntoNftCollection<T> for CollectionHandle<T> {
+ fn into_nft_collection(self) -> Result<NonfungibleHandle<T>, Error<T>> {
+ match self.mode {
+ CollectionMode::NFT => Ok(NonfungibleHandle::cast(self)),
+ _ => Err(<Error<T>>::NotRmrkCollection)
+ }
+ }
+}
+
+pub enum RmrkProperty {
+ Metadata,
+ CollectionType,
+}
+
+impl RmrkProperty {
+ pub fn to_key(self) -> PropertyKey {
+ let key = |str_key: &str| {
+ PropertyKey::try_from(
+ str_key.bytes().collect::<Vec<_>>()
+ ).unwrap()
+ };
+
+ match self {
+ Self::Metadata => key("metadata"),
+ Self::CollectionType => key("collection-type"),
+ }
+ }
+}
+
+#[derive(Encode, Decode, PartialEq, Eq)]
+pub enum CollectionType {
+ Regular,
+ Resource,
+ Base,
+}
+
+impl_rmrk_value!(CollectionType, decode_error: CorruptedCollectionType);