Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 2 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ members = [
"xcq-primitives",
"xcq-runtime-api",
"xcq-test-runner",
"xcq-types",

"examples/example-fungibles",
"examples/example-helloworld",
Expand All @@ -40,7 +39,6 @@ xcq-extension = { path = "xcq-extension", default-features = false }
xcq-primitives = { path = "xcq-primitives", default-features = false }
xcq-runtime-api = { path = "xcq-runtime-api", default-features = false }
xcq-test-runner = { path = "xcq-test-runner", default-features = false }
xcq-types = { path = "xcq-types", default-features = false }

# polkavm
polkavm = { path = "vendor/polkavm/crates/polkavm", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fmt:
cargo fmt --all

check-wasm:
cargo check --no-default-features --target=wasm32-unknown-unknown -p xcq-api -p xcq-executor -p xcq-extension-core -p xcq-extension-fungibles -p xcq-extension -p xcq-primitives -p xcq-runtime-api -p xcq-types
cargo check --no-default-features --target=wasm32-unknown-unknown -p xcq-api -p xcq-executor -p xcq-extension-core -p xcq-extension-fungibles -p xcq-extension -p xcq-primitives -p xcq-runtime-api
SKIP_WASM_BUILD= cargo check --no-default-features --target=wasm32-unknown-unknown -p poc-runtime

check: check-wasm
Expand Down
69 changes: 41 additions & 28 deletions poc/guests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions poc/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ std = [

"xcq-executor/std",
"xcq-extension/std",
"xcq-primitives/std",
"xcq-extension-core/std",
"xcq-extension-fungibles/std",
]
8 changes: 3 additions & 5 deletions poc/runtime/src/xcq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ use frame::deps::scale_info::prelude::{format, string::String};
use frame::deps::sp_api::decl_runtime_apis;
use frame::prelude::*;

pub type XcqResponse = Vec<u8>;
pub type XcqError = String;
pub type XcqResult = Result<XcqResponse, XcqError>;
use xcq_extension::metadata::Metadata;
pub use xcq_primitives::XcqResult;

use xcq_extension::{impl_extensions, ExtensionsExecutor, Guest, Input, InvokeSource, Method};
use xcq_primitives::metadata::Metadata;
decl_runtime_apis! {
pub trait XcqApi {
fn execute_query(query: Vec<u8>, input: Vec<u8>) -> XcqResult;
Expand Down Expand Up @@ -86,7 +84,7 @@ pub fn execute_query(query: Vec<u8>, input: Vec<u8>) -> XcqResult {
}

pub fn metadata() -> Metadata {
ExtensionImpl::runtime_metadata().into()
ExtensionImpl::metadata()
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion xcq-api/procedural/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ syn = { workspace = true }
proc-macro2 = { workspace = true }
proc-macro-crate = { workspace = true }
Inflector = { workspace = true }
xcq-types = { workspace = true }
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }
53 changes: 37 additions & 16 deletions xcq-api/procedural/src/program/expand/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use inflector::Inflector;
use parity_scale_codec::Encode;
use proc_macro2::TokenStream as TokenStream2;
use quote::{format_ident, quote, ToTokens};
use scale_info::{meta_type, PortableRegistry, Registry};
use syn::{ItemFn, PathArguments, Result};
pub fn expand(def: Def) -> Result<TokenStream2> {
let preludes = generate_preludes();
Expand Down Expand Up @@ -48,7 +49,6 @@ fn generate_call(item: &ItemFn) -> Result<TokenStream2> {
}
impl #call_name {
pub fn call(&self) -> #return_ty {
// TODO: use xcq-types to represent the return type
let res = unsafe {
host_call(self.extension_id, self.call_ptr, self.call_size)
};
Expand Down Expand Up @@ -100,33 +100,53 @@ fn generate_return_ty_assertion(call_def: &CallDef) -> Result<TokenStream2> {
.ok_or_else(|| syn::Error::new_spanned(path, "expected function return type to be a path"))?;
match last_segment.ident.to_string().as_str() {
"u8" => {
let encoded_ty_bytes = xcq_types::XcqType::Primitive(xcq_types::PrimitiveType::U8).encode();
let ty = meta_type::<u8>();
let mut registry = Registry::new();
registry.register_type(&ty);
let portable_registry = PortableRegistry::from(registry);
let ty_bytes = portable_registry.encode();
quote! {
&[#(#encoded_ty_bytes),*]
&[#(#ty_bytes),*]
}
}
"u16" => {
let encoded_ty_bytes = xcq_types::XcqType::Primitive(xcq_types::PrimitiveType::U16).encode();
let ty = meta_type::<u16>();
let mut registry = Registry::new();
registry.register_type(&ty);
let portable_registry = PortableRegistry::from(registry);
let ty_bytes = portable_registry.encode();
quote! {
&[#(#encoded_ty_bytes),*]
&[#(#ty_bytes),*]
}
}
"u32" => {
let encoded_ty_bytes = xcq_types::XcqType::Primitive(xcq_types::PrimitiveType::U32).encode();
let ty = meta_type::<u32>();
let mut registry = Registry::new();
registry.register_type(&ty);
let portable_registry = PortableRegistry::from(registry);
let ty_bytes = portable_registry.encode();
quote! {
&[#(#encoded_ty_bytes),*]
&[#(#ty_bytes),*]
}
}
"u64" => {
let encoded_ty_bytes = xcq_types::XcqType::Primitive(xcq_types::PrimitiveType::U64).encode();
let ty = meta_type::<u64>();
let mut registry = Registry::new();
registry.register_type(&ty);
let portable_registry = PortableRegistry::from(registry);
let ty_bytes = portable_registry.encode();
quote! {
&[#(#encoded_ty_bytes),*]
&[#(#ty_bytes),*]
}
}
"u128" => {
let encoded_ty_bytes = xcq_types::XcqType::Primitive(xcq_types::PrimitiveType::U128).encode();
let ty = meta_type::<u128>();
let mut registry = Registry::new();
registry.register_type(&ty);
let portable_registry = PortableRegistry::from(registry);
let ty_bytes = portable_registry.encode();
quote! {
&[#(#encoded_ty_bytes),*]
&[#(#ty_bytes),*]
}
}
"Vec" => {
Expand All @@ -136,12 +156,13 @@ fn generate_return_ty_assertion(call_def: &CallDef) -> Result<TokenStream2> {
Some(syn::GenericArgument::Type(syn::Type::Path(path)))
if path.path.is_ident("u8") =>
{
let encoded_ty_bytes = xcq_types::XcqType::Sequence(Box::new(
xcq_types::XcqType::Primitive(xcq_types::PrimitiveType::U8),
))
.encode();
let ty = meta_type::<Vec<u8>>();
let mut registry = Registry::new();
registry.register_type(&ty);
let portable_registry = PortableRegistry::from(registry);
let ty_bytes = portable_registry.encode();
quote! {
&[#(#encoded_ty_bytes),*]
&[#(#ty_bytes),*]
}
}
_ => quote! { &[0u8] },
Expand Down
3 changes: 1 addition & 2 deletions xcq-extension-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ version.workspace = true
parity-scale-codec = { workspace = true }
xcq-extension = { workspace = true }
scale-info = { workspace = true }
xcq-primitives = { workspace = true }

[features]
default = ["std"]
std = ["parity-scale-codec/std", "xcq-extension/std"]
std = ["parity-scale-codec/std", "scale-info/std", "xcq-extension/std"]
3 changes: 1 addition & 2 deletions xcq-extension-fungibles/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ version.workspace = true
parity-scale-codec = { workspace = true }
xcq-extension = { workspace = true }
scale-info = { workspace = true }
xcq-primitives = { workspace = true }

[features]
default = ["std"]
std = ["parity-scale-codec/std", "xcq-extension/std"]
std = ["parity-scale-codec/std", "scale-info/std", "xcq-extension/std"]
8 changes: 5 additions & 3 deletions xcq-extension/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ repository.workspace = true
version.workspace = true

[dependencies]
parity-scale-codec = { workspace = true }
polkavm = { workspace = true }
scale-info = { workspace = true }
xcq-executor = { workspace = true }
fortuples = { workspace = true }
tracing = { workspace = true }
xcq-extension-procedural = { path = "procedural" }
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }
xcq-primitives = { workspace = true }

[features]
default = ["std"]
std = [
"polkavm/std",
"xcq-executor/std",
"xcq-primitives/std",
"parity-scale-codec/std",
"scale-info/std",
"xcq-executor/std",
"tracing/std",
]
Loading