Skip to content

Feat: add return type assertion #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
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 = 10588899351449456541u64, call_index = 1)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe is better to specify extension_id by hex? e.g. 0x12345u64 so that it is shorter

fn balance(asset: u32, who: [u8; 32]) -> u64 {}
#[xcq::call_def]
#[xcq::call_def(extension_id = 10588899351449456541u64, 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 = 10588899351449456541u64, 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 }
5 changes: 3 additions & 2 deletions xcq-api/procedural/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/// Declare the calls used in XCQ program
/// #[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
Expand Down
Loading
Loading