Skip to content

Commit

Permalink
Stabilize transactionBroadcast methods (#1540)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandru Vasile <[email protected]>
Co-authored-by: Niklas Adolfsson <[email protected]>
  • Loading branch information
lexnv and niklasad1 authored Apr 20, 2024
1 parent 240080a commit c57df08
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
12 changes: 6 additions & 6 deletions subxt/src/backend/unstable/rpc_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,24 +280,24 @@ impl<T: Config> UnstableRpcMethods<T> {
}

/// Broadcast the transaction on the p2p network until the
/// [`Self::transaction_unstable_stop`] is called.
/// [`Self::transaction_v1_stop`] is called.
///
/// Returns an operation ID that can be used to stop the broadcasting process.
/// Returns `None` if the server cannot handle the request at the moment.
pub async fn transaction_unstable_broadcast(&self, tx: &[u8]) -> Result<Option<String>, Error> {
pub async fn transaction_v1_broadcast(&self, tx: &[u8]) -> Result<Option<String>, Error> {
self.client
.request("transaction_unstable_broadcast", rpc_params![to_hex(tx)])
.request("transaction_v1_broadcast", rpc_params![to_hex(tx)])
.await
}

/// Stop the broadcasting process of the transaction.
///
/// The operation ID is obtained from the [`Self::transaction_unstable_broadcast`] method.
/// The operation ID is obtained from the [`Self::transaction_v1_broadcast`] method.
///
/// Returns an error if the operation ID does not correspond to any active transaction for this connection.
pub async fn transaction_unstable_stop(&self, operation_id: &str) -> Result<(), Error> {
pub async fn transaction_v1_stop(&self, operation_id: &str) -> Result<(), Error> {
self.client
.request("transaction_unstable_stop", rpc_params![operation_id])
.request("transaction_v1_stop", rpc_params![operation_id])
.await
}
}
Expand Down
17 changes: 7 additions & 10 deletions testing/integration-tests/src/full_client/client/unstable_rpcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ async fn next_operation_event<
}

#[tokio::test]
async fn transaction_unstable_broadcast() {
async fn transaction_v1_broadcast() {
let bob = dev::bob();
let bob_address: MultiAddress<AccountId32, u32> = bob.public_key().into();

Expand Down Expand Up @@ -346,7 +346,7 @@ async fn transaction_unstable_broadcast() {

// Submit the transaction.
let _operation_id = rpc
.transaction_unstable_broadcast(&tx_bytes)
.transaction_v1_broadcast(&tx_bytes)
.await
.unwrap()
.expect("Server is not overloaded by 1 tx; qed");
Expand Down Expand Up @@ -383,7 +383,7 @@ async fn transaction_unstable_broadcast() {
}

#[tokio::test]
async fn transaction_unstable_stop() {
async fn transaction_v1_stop() {
let bob = dev::bob();
let bob_address: MultiAddress<AccountId32, u32> = bob.public_key().into();

Expand All @@ -392,7 +392,7 @@ async fn transaction_unstable_stop() {

// Cannot stop an operation that was not started.
let _err = rpc
.transaction_unstable_stop("non-existent-operation-id")
.transaction_v1_stop("non-existent-operation-id")
.await
.unwrap_err();

Expand All @@ -409,15 +409,12 @@ async fn transaction_unstable_stop() {

// Submit the transaction.
let operation_id = rpc
.transaction_unstable_broadcast(&tx_bytes)
.transaction_v1_broadcast(&tx_bytes)
.await
.unwrap()
.expect("Server is not overloaded by 1 tx; qed");

rpc.transaction_unstable_stop(&operation_id).await.unwrap();
rpc.transaction_v1_stop(&operation_id).await.unwrap();
// Cannot stop it twice.
let _err = rpc
.transaction_unstable_stop(&operation_id)
.await
.unwrap_err();
let _err = rpc.transaction_v1_stop(&operation_id).await.unwrap_err();
}

0 comments on commit c57df08

Please sign in to comment.