-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b7f2b4
commit 5d42cb0
Showing
16 changed files
with
433 additions
and
34 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,47 @@ | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
use parity_scale_codec::{Decode, Encode}; | ||
use xcq_extension::Vec; | ||
use xcq_extension::{DispatchError, Dispatchable}; | ||
use xcq_extension::{ExtensionId, ExtensionIdTy}; | ||
|
||
pub fn add(left: usize, right: usize) -> usize { | ||
left + right | ||
pub trait ExtensionCore { | ||
type Config: Config; | ||
fn has_extension(id: <Self::Config as Config>::ExtensionId) -> bool; | ||
// crypto functions | ||
// fn blake2_64(data: Vec<u8>) -> [u8; 8]; | ||
// fn blake2_128(data: Vec<u8>) -> [u8; 16]; | ||
// fn blake2_256(data: Vec<u8>) -> [u8; 32]; | ||
// fn twox_64(data: Vec<u8>) -> [u8; 8]; | ||
// fn read_storage(key: Vec<u8>) -> Option<Vec<u8>>; | ||
} | ||
pub trait Config { | ||
type ExtensionId: Decode; | ||
} | ||
|
||
// #[extension(ExtensionCore)] | ||
// type Call; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
mod generated_by_extension_decl { | ||
use super::*; | ||
|
||
#[test] | ||
fn it_works() { | ||
let result = add(2, 2); | ||
assert_eq!(result, 4); | ||
type ExtensionIdOf<T> = <<T as ExtensionCore>::Config as Config>::ExtensionId; | ||
#[derive(Decode)] | ||
pub enum ExtensionCoreCall<Impl: ExtensionCore> { | ||
HasExtension { id: ExtensionIdOf<Impl> }, | ||
} | ||
|
||
impl<Impl: ExtensionCore> Dispatchable for ExtensionCoreCall<Impl> { | ||
fn dispatch(self) -> Result<Vec<u8>, DispatchError> { | ||
match self { | ||
Self::HasExtension { id } => Ok(Impl::has_extension(id).encode()), | ||
} | ||
} | ||
} | ||
|
||
impl<Impl: ExtensionCore> ExtensionId for ExtensionCoreCall<Impl> { | ||
const EXTENSION_ID: ExtensionIdTy = 0u64; | ||
} | ||
|
||
pub type Call<Impl> = ExtensionCoreCall<Impl>; | ||
} | ||
|
||
pub use generated_by_extension_decl::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,63 @@ | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
use parity_scale_codec::{Decode, Encode}; | ||
use xcq_extension::Vec; | ||
use xcq_extension::{DispatchError, Dispatchable}; | ||
use xcq_extension::{ExtensionId, ExtensionIdTy}; | ||
|
||
pub fn add(left: usize, right: usize) -> usize { | ||
left + right | ||
pub type AccountIdFor<T> = <<T as ExtensionFungibles>::Config as Config>::AccountId; | ||
pub type BalanceFor<T> = <<T as ExtensionFungibles>::Config as Config>::Balance; | ||
pub type AssetIdFor<T> = <<T as ExtensionFungibles>::Config as Config>::AssetId; | ||
|
||
pub trait ExtensionFungibles { | ||
type Config: Config; | ||
// fungibles::Inspect (not extensive) | ||
// fn total_inssuance(asset: AssetIdFor<Self>) -> BalanceFor<Self>; | ||
// fn minimum_balance(asset: AssetIdFor<Self>) -> BalanceFor<Self>; | ||
fn total_supply(asset: AssetIdFor<Self>) -> BalanceFor<Self>; | ||
fn balance(asset: AssetIdFor<Self>, who: AccountIdFor<Self>) -> BalanceFor<Self>; | ||
// fungibles::InspectEnumerable | ||
// fn asset_ids() -> Vec<AccountIdFor<Self>>; | ||
// fn account_balances(who: AccountIdFor<Self>) -> Vec<(AssetIdFor<Self>, BalanceFor<Self>)>; | ||
} | ||
|
||
pub trait Config { | ||
type AccountId: Decode; | ||
type AssetId: Decode; | ||
type Balance: Encode; | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
// #[extension(ExtensionFungibles)] | ||
// type Call; | ||
|
||
mod generated_by_extension_decl { | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn it_works() { | ||
let result = add(2, 2); | ||
assert_eq!(result, 4); | ||
#[derive(Decode)] | ||
pub enum ExtensionFungiblesCall<Impl: ExtensionFungibles> { | ||
// TODO: not extensive | ||
Balance { | ||
asset: AssetIdFor<Impl>, | ||
who: AccountIdFor<Impl>, | ||
}, | ||
TotalSupply { | ||
asset: AssetIdFor<Impl>, | ||
}, | ||
} | ||
|
||
impl<Impl: ExtensionFungibles> Dispatchable for ExtensionFungiblesCall<Impl> { | ||
fn dispatch(self) -> Result<Vec<u8>, DispatchError> { | ||
match self { | ||
Self::Balance { asset, who } => Ok(Impl::balance(asset, who).encode()), | ||
Self::TotalSupply { asset } => Ok(Impl::total_supply(asset).encode()), | ||
} | ||
} | ||
} | ||
|
||
impl<Impl: ExtensionFungibles> ExtensionId for ExtensionFungiblesCall<Impl> { | ||
const EXTENSION_ID: ExtensionIdTy = 1u64; | ||
} | ||
|
||
pub type Call<Impl> = ExtensionFungiblesCall<Impl>; | ||
} | ||
|
||
pub use generated_by_extension_decl::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use crate::Vec; | ||
pub trait Dispatchable { | ||
fn dispatch(self) -> Result<Vec<u8>, DispatchError>; | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum DispatchError { | ||
PhantomData, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// TODO: contain source error | ||
use crate::DispatchError; | ||
use parity_scale_codec::Error as CodeCError; | ||
#[derive(Debug)] | ||
pub enum ExtensionError { | ||
PermissionError, | ||
PolkavmError, | ||
DecodeError(CodeCError), | ||
DispatchError(DispatchError), | ||
UnsupportedExtension, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub type ExtensionIdTy = u64; | ||
|
||
pub trait ExtensionId { | ||
const EXTENSION_ID: ExtensionIdTy; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use scale_info::prelude::string::String; | ||
pub trait Guest { | ||
fn program(&self) -> &[u8]; | ||
} | ||
|
||
pub type Method = String; | ||
|
||
pub trait Input { | ||
fn method(&self) -> Method; | ||
fn args(&self) -> &[u8]; | ||
} |
Oops, something went wrong.