mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-19 22:45:40 +00:00
Implement new API for sign_and_submit_then_watch (#354)
* WIP Implementing new event subscription API * back to lifetimes, fix example * no more need for accept_weak_inclusion * thread lifetime through to prevent 'temporary dropped' issue * make working with events a little nicer * Get tests compiling * fmt and clippy * _name back to name * dont take ownership, just have stronger note * Attempt to fix test * remove commented-out code * Add a couple more helper methods and a test * Remove custom ExtrinsicFailed handling; treat them like other events * Handle runtime errors in TransactionProgress related bits * cargo fmt + clippy * Fix some of the failing tests * remove unused import * fix transfer_error test * Fix compile errors against new substrate latest * Comment tweaks, and force test-runtime rebuild * Drop the TransactionProgress subscription when we hit 'end' statuses * cargo fmt * find_event to find_first_event and helper to return all matching events * TransactionProgressStatus to TransactionStatus * Copy and improve docs on TransactionStatus from substrate * debug impl for Client to avoid manual debug impls elsewhere * Add and tweak comments, specifically a note about block inclusion on errors * clippy + fmt * Fix docs * Ignore 'error' statuses and adhere to the substrate docs * tweak and improve some comments per @dvdplm's suggestions * Break transaction* structs into separate file * fmt and fix doc link
This commit is contained in:
@@ -35,8 +35,8 @@ use subxt::{
|
||||
Client,
|
||||
Config,
|
||||
Error,
|
||||
ExtrinsicSuccess,
|
||||
PairSigner,
|
||||
TransactionProgress,
|
||||
};
|
||||
|
||||
struct ContractsTestContext {
|
||||
@@ -73,7 +73,7 @@ impl ContractsTestContext {
|
||||
"#;
|
||||
let code = wabt::wat2wasm(CONTRACT).expect("invalid wabt");
|
||||
|
||||
let result = self
|
||||
let events = self
|
||||
.cxt
|
||||
.api
|
||||
.tx()
|
||||
@@ -81,26 +81,29 @@ impl ContractsTestContext {
|
||||
.instantiate_with_code(
|
||||
100_000_000_000_000_000, // endowment
|
||||
500_000_000_000, // gas_limit
|
||||
None, // storage_deposit_limit
|
||||
code,
|
||||
vec![], // data
|
||||
vec![], // salt
|
||||
)
|
||||
.sign_and_submit_then_watch(&self.signer)
|
||||
.await?
|
||||
.wait_for_finalized_success()
|
||||
.await?;
|
||||
|
||||
let code_stored = result
|
||||
.find_event::<events::CodeStored>()?
|
||||
let code_stored = events
|
||||
.find_first_event::<events::CodeStored>()?
|
||||
.ok_or_else(|| Error::Other("Failed to find a CodeStored event".into()))?;
|
||||
let instantiated = result
|
||||
.find_event::<events::Instantiated>()?
|
||||
let instantiated = events
|
||||
.find_first_event::<events::Instantiated>()?
|
||||
.ok_or_else(|| Error::Other("Failed to find a Instantiated event".into()))?;
|
||||
let _extrinsic_success = result
|
||||
.find_event::<system::events::ExtrinsicSuccess>()?
|
||||
let _extrinsic_success = events
|
||||
.find_first_event::<system::events::ExtrinsicSuccess>()?
|
||||
.ok_or_else(|| {
|
||||
Error::Other("Failed to find a ExtrinsicSuccess event".into())
|
||||
})?;
|
||||
|
||||
log::info!(" Block hash: {:?}", result.block);
|
||||
log::info!(" Block hash: {:?}", events.block_hash());
|
||||
log::info!(" Code hash: {:?}", code_stored.code_hash);
|
||||
log::info!(" Contract address: {:?}", instantiated.contract);
|
||||
Ok((code_stored.code_hash, instantiated.contract))
|
||||
@@ -118,16 +121,19 @@ impl ContractsTestContext {
|
||||
.instantiate(
|
||||
100_000_000_000_000_000, // endowment
|
||||
500_000_000_000, // gas_limit
|
||||
None, // storage_deposit_limit
|
||||
code_hash,
|
||||
data,
|
||||
salt,
|
||||
)
|
||||
.sign_and_submit_then_watch(&self.signer)
|
||||
.await?
|
||||
.wait_for_finalized_success()
|
||||
.await?;
|
||||
|
||||
log::info!("Instantiate result: {:?}", result);
|
||||
let instantiated = result
|
||||
.find_event::<events::Instantiated>()?
|
||||
.find_first_event::<events::Instantiated>()?
|
||||
.ok_or_else(|| Error::Other("Failed to find a Instantiated event".into()))?;
|
||||
|
||||
Ok(instantiated.contract)
|
||||
@@ -137,7 +143,7 @@ impl ContractsTestContext {
|
||||
&self,
|
||||
contract: AccountId,
|
||||
input_data: Vec<u8>,
|
||||
) -> Result<ExtrinsicSuccess<DefaultConfig>, Error> {
|
||||
) -> Result<TransactionProgress<'_, DefaultConfig>, Error> {
|
||||
log::info!("call: {:?}", contract);
|
||||
let result = self
|
||||
.contracts_tx()
|
||||
@@ -145,6 +151,7 @@ impl ContractsTestContext {
|
||||
MultiAddress::Id(contract),
|
||||
0, // value
|
||||
500_000_000, // gas_limit
|
||||
None, // storage_deposit_limit
|
||||
input_data,
|
||||
)
|
||||
.sign_and_submit_then_watch(&self.signer)
|
||||
|
||||
Reference in New Issue
Block a user