mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 15:41:02 +00:00
Double map and plain storage support, introduce macros (#93)
* Support custom clients. * Simplify trait bounds. * Plain and double map storage support. * Simplify more trait bounds. * Add proc macro. * Add Call, Event and Store traits. * Update proc-macros. * Add with_system for proc-macro. * proc-macro: test: support signature and extra fields. * proc-macro: test: support sharing state accross steps. * proc-macro: test: fetch state sequentially. * Elide lifetimes. * Add test for plain storage. * Run rustfmt.
This commit is contained in:
@@ -35,7 +35,7 @@ fn main() {
|
||||
|
||||
async fn transfer_balance() -> Result<sp_core::H256, Error> {
|
||||
let signer = AccountKeyring::Alice.pair();
|
||||
let dest = AccountKeyring::Bob.to_account_id();
|
||||
let dest = AccountKeyring::Bob.to_account_id().into();
|
||||
|
||||
// note use of `KusamaRuntime`
|
||||
substrate_subxt::ClientBuilder::<KusamaRuntime>::new()
|
||||
@@ -43,9 +43,9 @@ async fn transfer_balance() -> Result<sp_core::H256, Error> {
|
||||
.await?
|
||||
.xt(signer, None)
|
||||
.await?
|
||||
.submit(balances::transfer::<KusamaRuntime>(
|
||||
dest.clone().into(),
|
||||
10_000,
|
||||
))
|
||||
.submit(balances::TransferCall {
|
||||
to: &dest,
|
||||
amount: 10_000,
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
@@ -17,49 +17,31 @@
|
||||
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;
|
||||
#[async_std::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
env_logger::init();
|
||||
|
||||
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().into();
|
||||
|
||||
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)>("Balances", "Transfer")
|
||||
{
|
||||
Some(Ok((_from, _to, value))) => {
|
||||
println!("Balance transfer success: value: {:?}", value)
|
||||
}
|
||||
Some(Err(err)) => println!("Failed to decode code hash: {}", err),
|
||||
None => println!("Failed to find Balances::Transfer Event"),
|
||||
}
|
||||
}
|
||||
Err(err) => println!("Error: {:?}", err),
|
||||
let cli = substrate_subxt::ClientBuilder::<Runtime>::new()
|
||||
.build()
|
||||
.await?;
|
||||
let xt = cli.xt(signer, None).await?;
|
||||
let xt_result = xt
|
||||
.watch()
|
||||
.submit(balances::TransferCall {
|
||||
to: &dest,
|
||||
amount: 10_000,
|
||||
})
|
||||
.await?;
|
||||
if let Some(event) = xt_result.find_event::<balances::TransferEvent<_>>()? {
|
||||
println!("Balance transfer success: value: {:?}", event.amount);
|
||||
} else {
|
||||
println!("Failed to find Balances::Transfer Event");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user