Files
pezkuwi-subxt/examples/submit_and_watch.rs
T
Andrew Jones 253a7d8b0b Convert to std futures (#58)
* WIP

* Begin converting rpc layer to use std futures and jsonrpsee

* Convert metadata to async/await

* Convert block_hash to async/await

* Convert more methods to async/await

* Remove sp_rpc

* Fix more compilation errors

* Remove connect

* Starting to convert subscription functions

* Use jsonrpsee branch from PR for public client types

* Implement subscribe events with jsonrpsee subscription

* Converting subscriptions and wait_for_block_events

* WIP converting lib methods to async

* Use shared client reference directly for rpc call

`rpc_api!` macro currently only supports RawClient (which cannot be shared).
Also supports named params only which is not currently compatible with substrate rpd which accepts only positional params.

* Use &self instead of &mut self for shared Client

* Convert submit_and_watch to async/await

* Convert more Client fns to async

* Pin some trait futures

* Add serde error

* Fix client creation

* Fix client request compiler errors

* Unify metadata errors

* Add WS handshake error variant

* Fix some more compiler errors

* Fix more compiler errors

* Convert submit_extrinsic to async

* Convert submit and submit_and_watch

* Add Send + Sync constraints

* Clone clients

* Fix EventArg conversion error

* Fix remaining warnings/errors

* Replace deny warnings with specific lints

* Infallable subscription loops

* Use jsonrpsee wss branch

* Fix example

* Start to fix up tests

* Make contracts tests compile

* Make some more tests pass

* Fix up remaining tests

* Fmt

* Use correct event storage key type

* Fix finding events

* Use master jsonrpsee
2020-01-20 12:00:08 +00:00

67 lines
2.4 KiB
Rust

// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of substrate-subxt.
//
// subxt is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// subxt is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.
use sp_keyring::AccountKeyring;
use substrate_subxt::{
balances,
system::System,
DefaultNodeRuntime as Runtime,
ExtrinsicSuccess,
};
type AccountId = <Runtime as System>::AccountId;
type Balance = <Runtime as balances::Balances>::Balance;
fn main() {
let result: Result<ExtrinsicSuccess<_>, Box<dyn std::error::Error + 'static>> =
async_std::task::block_on(async move {
env_logger::init();
let signer = AccountKeyring::Alice.pair();
let dest = AccountKeyring::Bob.to_account_id();
let cli = substrate_subxt::ClientBuilder::<Runtime>::new()
.build()
.await?;
let xt = cli.xt(signer, None).await?;
let xt_result = xt
.watch()
.events_decoder(|decoder| {
// for any primitive event with no type size registered
decoder.register_type_size::<(u64, u64)>("IdentificationTuple")
})
.submit(balances::transfer::<Runtime>(dest.clone().into(), 10_000))
.await?;
Ok(xt_result)
});
match result {
Ok(extrinsic_success) => {
match extrinsic_success
.find_event::<(AccountId, AccountId, Balance, Balance)>(
"Balances", "Transfer",
) {
Some(Ok((_from, _to, value, _fees))) => {
println!("Balance transfer success: value: {:?}", value)
}
Some(Err(err)) => println!("Failed to decode code hash: {}", err),
None => println!("Failed to find Contracts::CodeStored Event"),
}
}
Err(err) => println!("Error: {:?}", err),
}
}