Skip to content

Commit

Permalink
Documentation and test example
Browse files Browse the repository at this point in the history
  • Loading branch information
Niederb committed Aug 22, 2024
1 parent eacc1da commit 0a87648
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
7 changes: 5 additions & 2 deletions examples/async/examples/compose_extrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use substrate_api_client::{
GenericAdditionalParams, SignExtrinsic,
},
rpc::JsonrpseeClient,
Api, GetChainInfo, SubmitAndWatch, XtStatus,
Api, GetChainInfo, SubmitAndWatch, TransactionStatusDeterminant, XtStatus,
};

type AssetExtrinsicSigner = <AssetRuntimeConfig as Config>::ExtrinsicSigner;
Expand Down Expand Up @@ -139,7 +139,10 @@ async fn main() {

println!("[+] Composed Extrinsic:\n {:?}", xt);
let hash = api
.submit_and_watch_extrinsic_until(xt, XtStatus::InBlock)
.submit_and_watch_opaque_extrinsic_until_final(
xt.encode().into(),
&[TransactionStatusDeterminant::InBlock],
)
.await
.unwrap()
.block_hash
Expand Down
13 changes: 1 addition & 12 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,17 @@ pub enum UnexpectedTxStatus {
Invalid,
}

/// See `TransactionStatus` for a description of the different enum values
pub enum TransactionStatusDeterminant {
/// Transaction is part of the future queue.
Future,
/// Transaction is part of the ready queue.
Ready,
/// The transaction has been broadcast to the given peers.
Broadcast,
/// Transaction has been included in block with given hash.
InBlock,
/// The block this transaction was included in has been retracted.
Retracted,
/// Maximum number of finality watchers has been reached,
/// old watchers are being removed.
FinalityTimeout,
/// Transaction has been finalized by a finality-gadget, e.g GRANDPA
Finalized,
/// Transaction has been replaced in the pool, by another transaction
/// that provides the same tags. (e.g. same (sender, nonce)).
Usurped,
/// Transaction has been dropped from the pool because of the limit.
Dropped,
/// Transaction is no longer valid in the current state.
Invalid,
}

Expand Down
5 changes: 5 additions & 0 deletions src/api/rpc_api/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ pub trait SubmitAndWatch {
watch_until: XtStatus,
) -> Result<ExtrinsicReport<Self::Hash>>;

/// Submit the extrinsic and watch it until it reaches one of the `expected_status`.
/// The method also returns if the transaction reaches a final state (regardless of contents of `expected_status`)
///
/// This method is blocking if the sync-api feature is activated
async fn submit_and_watch_extrinsic_until_status<Address, Call, Signature, SignedExtra>(
&self,
extrinsic: UncheckedExtrinsicV4<Address, Call, Signature, SignedExtra>,
Expand All @@ -224,6 +228,7 @@ pub trait SubmitAndWatch {
Signature: Encode,
SignedExtra: Encode;

/// Query the events for the specified `report` and attach them.
async fn populate_events(
&self,
report: ExtrinsicReport<Self::Hash>,
Expand Down

0 comments on commit 0a87648

Please sign in to comment.