Skip to content
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

support wasm #48

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
24 changes: 17 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,27 @@ edition = "2018"

[dependencies]
env_logger = { version = "0.7", optional = true }
ws = { version = "0.7", optional = true }
hex = { version = "0.4", default-features=false, optional = true }
log = { version = "0.4", optional = true }
serde = { version = "1.0", optional = true, features = ["derive"] }
serde_json = { version = "1.0", optional = true }
primitive-types = { version = "0.6", default-features = false, features = ["codec"] }
wasm-bindgen = "=0.2.55"
futures-signals = {git="https://github.com/alanpoon/rust-signals.git",branch="master"}

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
ws = { version = "0.7", optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies.web-sys]
version = "0.3.19"
features = [
'WebSocket',
'Response',
'EventTarget',
'Event',
'MessageEvent',
'ErrorEvent'
]

[dependencies.primitives]
git = "https://github.com/paritytech/substrate"
Expand Down Expand Up @@ -80,11 +95,6 @@ rev = "3bf9540e72df5ecb3955845764dfee7dcdbb26b5"
package = "sr-std"
default-features = false

[dev-dependencies.node_runtime]
git = "https://github.com/paritytech/substrate"
rev = "3bf9540e72df5ecb3955845764dfee7dcdbb26b5"
package = "node-runtime"

[dependencies.node_primitives]
git = "https://github.com/paritytech/substrate"
rev = "3bf9540e72df5ecb3955845764dfee7dcdbb26b5"
Expand All @@ -98,6 +108,7 @@ package = "pallet-contracts"

[dev-dependencies]
wabt = "0.9.0"
futures = "0.3.1"

[dev-dependencies.keyring]
git = "https://github.com/paritytech/substrate"
Expand All @@ -120,7 +131,6 @@ std = [
"balances/std",
"runtime_version/std",
"metadata/std",
"runtime_io/std",
"indices/std",
"primitives/std",
"serde/std",
Expand Down
4 changes: 2 additions & 2 deletions src/examples/example_generic_extrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ fn main() {

// call Balances::transfer
// the names are given as strings
let xt: UncheckedExtrinsicV4<_> = compose_extrinsic!(
let xt: UncheckedExtrinsicV3<_, sr25519::Pair> = compose_extrinsic!(
api.clone(),
"Balances",
"transfer",
GenericAddress::from(to.clone()),
GenericAddress::from(to.0.clone()),
Compact(42 as u128)
);

Expand Down
18 changes: 11 additions & 7 deletions src/examples/example_get_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,41 @@ use substrate_api_client::{
Api,
utils::hexstr_to_u256,
};

fn main() {
use futures::executor::block_on;
async fn run (){
env_logger::init();
let url = get_node_url_from_cli();

let mut api = Api::new(format!("ws://{}", url));
let mut api = Api::new(format!("ws://{}", url)).await;

// get some plain storage value
let result_str = api.get_storage("Balances", "TotalIssuance", None).unwrap();
let result_str = api.get_storage("Balances", "TotalIssuance", None).await.unwrap();
let result = hexstr_to_u256(result_str).unwrap();
println!("[+] TotalIssuance is {}", result);

// get Alice's AccountNonce
let accountid = AccountKeyring::Alice.to_account_id();
let result_str = api
.get_storage("System", "AccountNonce", Some(accountid.encode()))
.get_storage("System", "AccountNonce", Some(accountid.encode())).await
.unwrap();
let result = hexstr_to_u256(result_str).unwrap();
println!("[+] Alice's Account Nonce is {}", result.low_u32());

// get Alice's AccountNonce with the AccountKey
let signer = AccountKeyring::Alice.pair();
let result_str = api
.get_storage("System", "AccountNonce", Some(signer.public().encode()))
.get_storage("System", "AccountNonce", Some(signer.public().encode())).await
.unwrap();
let result = hexstr_to_u256(result_str).unwrap();
println!("[+] Alice's Account Nonce is {}", result.low_u32());

// get Alice's AccountNonce with api.get_nonce()
api.signer = Some(signer);
println!("[+] Alice's Account Nonce is {}", api.get_nonce().unwrap());
println!("[+] Alice's Account Nonce is {}", api.get_nonce().await.unwrap());
}
fn main() {
let future = run();
block_on(future);
}

pub fn get_node_url_from_cli() -> String {
Expand Down
4 changes: 2 additions & 2 deletions src/extrinsic/balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ where
P: Pair,
MultiSignature: From<P::Signature>,
{
pub fn balance_transfer(&self, to: GenericAddress, amount: u128) -> BalanceTransferXt {
pub async fn balance_transfer(&self, to: GenericAddress, amount: u128) -> BalanceTransferXt {
compose_extrinsic!(
self,
BALANCES_MODULE,
Expand All @@ -50,7 +50,7 @@ where
)
}

pub fn balance_set_balance(&self, who: GenericAddress, free_balance: u128, reserved_balance: u128) -> BalanceSetBalanceXt {
pub async fn balance_set_balance(&self, who: GenericAddress, free_balance: u128, reserved_balance: u128) -> BalanceSetBalanceXt {
compose_extrinsic!(
self,
BALANCES_MODULE,
Expand Down
6 changes: 3 additions & 3 deletions src/extrinsic/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ where
P: Pair,
MultiSignature: From<P::Signature>,
{
pub fn contract_put_code(&self, gas_limit: u64, code: Vec<u8>) -> ContractPutCodeXt {
pub async fn contract_put_code(&self, gas_limit: u64, code: Vec<u8>) -> ContractPutCodeXt {
compose_extrinsic!(
&self,
CONTRACTS_MODULE,
Expand All @@ -61,7 +61,7 @@ where
)
}

pub fn contract_create(
pub async fn contract_create(
&self,
endowment: u128,
gas_limit: u64,
Expand All @@ -80,7 +80,7 @@ where
)
}

pub fn contract_call(
pub async fn contract_call(
&self,
dest: GenericAddress,
value: u128,
Expand Down
2 changes: 1 addition & 1 deletion src/extrinsic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ macro_rules! compose_extrinsic {
$crate::compose_extrinsic_offline!(
signer,
call.clone(),
$api.get_nonce().unwrap(),
$api.get_nonce().await.unwrap(),
$api.genesis_hash,
$api.runtime_version.spec_version
)
Expand Down
Loading