Skip to content

Commit

Permalink
Feat: add return type assertion (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
indirection42 authored Sep 25, 2024
1 parent b973132 commit fb4e3d1
Show file tree
Hide file tree
Showing 20 changed files with 483 additions and 158 deletions.
4 changes: 3 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ clap = { version = "4.5.4", features = ["derive"] }
env_logger = { version = "0.11.3" }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }

impl-trait-for-tuples = "0.2"
fortuples = "0.9"

# proc macros
Expand Down
103 changes: 100 additions & 3 deletions poc/guests/Cargo.lock

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

4 changes: 2 additions & 2 deletions poc/guests/sum-balance-percent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ static GLOBAL: polkavm_derive::LeakingAllocator = polkavm_derive::LeakingAllocat
use alloc::vec::Vec;
#[xcq_api::program]
mod sum_balance {
#[xcq::call_def]
#[xcq::call_def(extension_id = 0x92F353DB95824F9Du64, call_index = 1)]
fn balance(asset: u32, who: [u8; 32]) -> u64 {}
#[xcq::call_def]
#[xcq::call_def(extension_id = 0x92F353DB95824F9Du64, call_index = 0)]
fn total_supply(asset: u32) -> u64 {}

#[xcq::entrypoint]
Expand Down
4 changes: 2 additions & 2 deletions poc/guests/sum-balance/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#[global_allocator]
static GLOBAL: polkavm_derive::LeakingAllocator = polkavm_derive::LeakingAllocator;
use alloc::vec::Vec;
// An example instance of xcq program with specific arg types
#[xcq_api::program]
mod sum_balance {
#[xcq::call_def]
#[xcq::call_def(extension_id = 0x92F353DB95824F9Du64, call_index = 1)]
fn balance(asset: u32, who: [u8; 32]) -> u64 {}

#[xcq::entrypoint]
fn sum_balance(calls: Vec<BalanceCall>) -> u64 {
let mut sum = 0;
Expand Down
2 changes: 1 addition & 1 deletion poc/guests/total-supply/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
static GLOBAL: polkavm_derive::LeakingAllocator = polkavm_derive::LeakingAllocator;
#[xcq_api::program]
mod query_total_supply {
#[xcq::call_def]
#[xcq::call_def(extension_id = 10588899351449456541u64, call_index = 0)]
fn total_supply(asset: u32) -> u64 {}

#[xcq::entrypoint]
Expand Down
2 changes: 2 additions & 0 deletions xcq-api/procedural/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +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 }
7 changes: 5 additions & 2 deletions xcq-api/procedural/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
/// Declare the calls used in XCQ program
/// ```ignore
/// #[xcq::program]
/// mod query_fungibles {
/// #[xcq::call(extern_types = [AssetId, AccountId, Balance]])]]
/// #[xcq::call_def(extension_id = 123456, extern_types = [AssetId, AccountId, Balance])]
/// fn balance(asset: AssetId, who: AccountId) -> Balance;
///
/// #[xcq(entrypoint)]
/// #[xcq::entrypoint]
/// fn sum_balance(calls: Vec<Call>) -> u64 {
/// let mut sum = 0;
/// for call in calls {
/// // calculation requires a known balance type, we can use assert-type here
/// sum += call.call();
/// }
/// sum
/// }
/// }
/// ```
///
mod program;
use proc_macro::TokenStream;
Expand Down
Loading

0 comments on commit fb4e3d1

Please sign in to comment.