mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 08:51:09 +00:00
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
This commit is contained in:
@@ -14,37 +14,41 @@
|
||||
// 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 futures::future::Future;
|
||||
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() {
|
||||
env_logger::init();
|
||||
let signer = AccountKeyring::Alice.pair();
|
||||
let result: Result<ExtrinsicSuccess<_>, Box<dyn std::error::Error + 'static>> =
|
||||
async_std::task::block_on(async move {
|
||||
env_logger::init();
|
||||
|
||||
let dest = AccountKeyring::Bob.to_account_id();
|
||||
let signer = AccountKeyring::Alice.pair();
|
||||
|
||||
let fut = substrate_subxt::ClientBuilder::<Runtime>::new()
|
||||
.build()
|
||||
.and_then(|cli| cli.xt(signer, None))
|
||||
.and_then(move |xt| {
|
||||
xt.watch()
|
||||
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)
|
||||
});
|
||||
|
||||
let mut rt = tokio::runtime::Runtime::new().unwrap();
|
||||
match rt.block_on(fut) {
|
||||
match result {
|
||||
Ok(extrinsic_success) => {
|
||||
match extrinsic_success
|
||||
.find_event::<(AccountId, AccountId, Balance, Balance)>(
|
||||
@@ -57,6 +61,6 @@ fn main() {
|
||||
None => println!("Failed to find Contracts::CodeStored Event"),
|
||||
}
|
||||
}
|
||||
Err(err) => println!("Error: {}", err),
|
||||
Err(err) => println!("Error: {:?}", err),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user