virto-sdk icon indicating copy to clipboard operation
virto-sdk copied to clipboard

Sube Examples: Multiple Queries At once for multiple Chains/Parachains

Open S0c5 opened this issue 3 years ago • 1 comments

As a developer in the Dotsama ecosystem, usually i have to interact with multiple parachains (including the Kusama relychain) at once, the main idea with this example is to show how to interact or make multiple queries at once.

let [account1, account2] = sube_multi!([
"http://kusama.node/balances/account/0x123123123",
"http://statemine.node/balances/account/0x123123123",
])
[
 sube!(""),
 sube!("")
]

S0c5 avatar Apr 04 '23 13:04 S0c5

I think we can adapt the sube! macro to change based on different combinations of parameters to fit the simple and more complex cases.

I think something along this lines should be possible

// simple usage for storage queries, under the hood uses the builder to create a type that
// implements `IntoFuture` that can be awaited(returns a scales::Value ?).
let account = sube!("balances/account/0x1234").await?;
// multi query
let (balanceKSM, balanceUSDT) = sube!(
    "balances/account/0x1234", 
    "statemine://assets/account/1984/0x1234",
).await?;
// subscribe to updates, the type returned by the builder has a method(e.g. `next`) to get updates
// when async itereators are supported there is a some form of for-await it will be even more convenient to use 
while let Some(n) = sube!("system/number").next().await {
    // handle update
}
// Single extrinsic
sube!("balances/transfer" => { dest: "0x1234", value: 100_000  }).await?;
// Multi extrinsic
sube!{
    "balances/transfer" => { dest: "0x1234", value: 100_000  },
    "statemine://assets/transfer" => { id: 1984, target: "0x1234", amount: 100_000  },
}.await?;

olanod avatar Apr 04 '23 16:04 olanod