Skip to content

Commit

Permalink
Feat(xcq-api): basic support (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
indirection42 authored Aug 23, 2024
1 parent 115b552 commit 1efa323
Show file tree
Hide file tree
Showing 29 changed files with 872 additions and 126 deletions.
14 changes: 14 additions & 0 deletions Cargo.lock

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

7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ GUEST_RUST_FLAGS="-C relocation-model=pie -C link-arg=--emit-relocs -C link-arg=
run: chainspec
bunx @acala-network/chopsticks@latest --config poc/runtime/chopsticks.yml --genesis output/chainspec.json

poc-host-%: poc-guest-%
RUST_LOG=trace cargo run -p poc-host-$*
poc-guests: poc-guest-sum-balance poc-guest-sum-balance-percent poc-guest-total-supply poc-guest-transparent-call

poc-guests: poc-guest-query-balance poc-guest-query-balance-fungibles poc-guest-transparent-call

dummy-poc-guests: dummy-poc-guest-query-balance dummy-poc-guest-query-balance-fungibles dummy-poc-guest-transparent-call
dummy-poc-guests: dummy-poc-guest-sum-balance dummy-poc-guest-sum-balance-percent dummy-poc-guest-total-supply dummy-poc-guest-transparent-call

poc-guest-%:
cd poc/guests; RUSTFLAGS=$(GUEST_RUST_FLAGS) cargo build -q --release --bin poc-guest-$* -p poc-guest-$*
Expand Down
145 changes: 142 additions & 3 deletions poc/guests/Cargo.lock

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

8 changes: 7 additions & 1 deletion poc/guests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
[workspace]
members = ["query-balance", "query-balance-fungibles", "transparent-call"]
members = [
"sum-balance",
"sum-balance-percent",
"total-supply",
"transparent-call",
]
resolver = "2"


[workspace.dependencies]
polkavm-derive = { path = "../../vendor/polkavm/crates/polkavm-derive" }
xcq-api = { path = "../../xcq-api", default-features = false }
41 changes: 0 additions & 41 deletions poc/guests/query-balance-fungibles/src/main.rs

This file was deleted.

35 changes: 0 additions & 35 deletions poc/guests/query-balance/src/main.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[package]
name = "poc-guest-query-balance"
name = "poc-guest-sum-balance-percent"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
polkavm-derive = { workspace = true }
xcq-api = { workspace = true }
21 changes: 21 additions & 0 deletions poc/guests/sum-balance-percent/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#![no_std]
#![no_main]
#[global_allocator]
static GLOBAL: polkavm_derive::LeakingAllocator = polkavm_derive::LeakingAllocator;
use alloc::vec::Vec;
#[xcq_api::program]
mod sum_balance {
#[xcq::call_def]
fn balance(asset: u32, who: [u8; 32]) -> u64 {}
#[xcq::call_def]
fn total_supply(asset: u32) -> u64 {}

#[xcq::entrypoint]
fn sum_balance(balances: Vec<BalanceCall>, total_supply: TotalSupplyCall) -> u64 {
let mut sum_balance = 0;
for call in balances {
sum_balance += call.call();
}
sum_balance * 100 / total_supply.call()
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[package]
name = "poc-guest-query-balance-fungibles"
name = "poc-guest-sum-balance"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
polkavm-derive = { workspace = true }
xcq-api = { workspace = true }
19 changes: 19 additions & 0 deletions poc/guests/sum-balance/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![no_std]
#![no_main]
#[global_allocator]
static GLOBAL: polkavm_derive::LeakingAllocator = polkavm_derive::LeakingAllocator;
use alloc::vec::Vec;
#[xcq_api::program]
mod sum_balance {
#[xcq::call_def]
fn balance(asset: u32, who: [u8; 32]) -> u64 {}

#[xcq::entrypoint]
fn sum_balance(calls: Vec<BalanceCall>) -> u64 {
let mut sum = 0;
for call in calls {
sum += call.call();
}
sum
}
}
Loading

0 comments on commit 1efa323

Please sign in to comment.