From 71abf7ee53bfda58d184341d99d7a166095f7b69 Mon Sep 17 00:00:00 2001 From: haerdib Date: Tue, 4 Feb 2025 08:53:02 +0100 Subject: [PATCH 1/2] deprecated ws client and remove example and tests --- .../sync/examples/transfer_with_ws_client.rs | 92 ------------------- src/rpc/ws_client/client.rs | 1 + testing/sync/examples/ws_client_test.rs | 64 ------------- 3 files changed, 1 insertion(+), 156 deletions(-) delete mode 100755 examples/sync/examples/transfer_with_ws_client.rs delete mode 100755 testing/sync/examples/ws_client_test.rs diff --git a/examples/sync/examples/transfer_with_ws_client.rs b/examples/sync/examples/transfer_with_ws_client.rs deleted file mode 100755 index b52ccad6e..000000000 --- a/examples/sync/examples/transfer_with_ws_client.rs +++ /dev/null @@ -1,92 +0,0 @@ -/* - Copyright 2019 Supercomputing Systems AG - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -//! Very simple example that shows how to use a predefined extrinsic from the extrinsic module. - -use sp_core::{ - crypto::{Pair, Ss58Codec}, - sr25519, -}; -use sp_runtime::MultiAddress; -use substrate_api_client::{ - ac_primitives::RococoRuntimeConfig, extrinsic::BalancesExtrinsics, rpc::WsRpcClient, Api, - GetAccountInformation, SubmitAndWatch, XtStatus, -}; - -// To test this example with CI we run it against the Polkadot Rococo node. Remember to switch the Config to match your -// own runtime if it uses different parameter configurations. Several pre-compiled runtimes are available in the ac-primitives crate. - -fn main() { - env_logger::init(); - - // Alice's seed: subkey inspect //Alice. - let alice: sr25519::Pair = Pair::from_string( - "0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a", - None, - ) - .unwrap(); - println!("signer account: {}", alice.public().to_ss58check()); - - // Initialize api and set the signer (sender) that is used to sign the extrinsics. - let client = WsRpcClient::with_default_url(); - let mut api = Api::::new(client).unwrap(); - api.set_signer(alice.clone().into()); - - // Retrieve bobs current balance. - let bob = sr25519::Public::from_ss58check("5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty") - .unwrap(); - let bob_balance = api.get_account_data(&bob.into()).unwrap().unwrap_or_default().free; - println!("[+] Bob's Free Balance is {}\n", bob_balance); - - // We first generate an extrinsic that will fail to be executed due to missing funds. - let xt = api - .balance_transfer_allow_death(MultiAddress::Id(bob.into()), bob_balance + 1) - .unwrap(); - println!( - "Sending an extrinsic from Alice (Key = {}),\n\nto Bob (Key = {})\n", - alice.public(), - bob - ); - println!("[+] Composed extrinsic: {:?}\n", xt); - - // Send and watch extrinsic until it fails onchain. - let result = api.submit_and_watch_extrinsic_until(xt, XtStatus::InBlock); - assert!(result.is_err()); - println!("[+] Extrinsic did not get included due to: {:?}\n", result); - - // This time, we generate an extrinsic that will succeed. - let xt = api - .balance_transfer_allow_death(MultiAddress::Id(bob.into()), bob_balance / 2) - .unwrap(); - println!( - "Sending an extrinsic from Alice (Key = {}),\n\nto Bob (Key = {})\n", - alice.public(), - bob - ); - println!("[+] Composed extrinsic: {:?}\n", xt); - - // Send and watch extrinsic until in block. - let block_hash = api - .submit_and_watch_extrinsic_until(xt, XtStatus::InBlock) - .unwrap() - .block_hash - .unwrap(); - println!("[+] Extrinsic got included. Block Hash: {:?}\n", block_hash); - - // Verify that Bob's free Balance increased. - let bob_new_balance = api.get_account_data(&bob.into()).unwrap().unwrap().free; - println!("[+] Bob's Free Balance is now {}\n", bob_new_balance); - assert!(bob_new_balance > bob_balance); -} diff --git a/src/rpc/ws_client/client.rs b/src/rpc/ws_client/client.rs index fe218eae1..bb940ca67 100644 --- a/src/rpc/ws_client/client.rs +++ b/src/rpc/ws_client/client.rs @@ -31,6 +31,7 @@ use std::{ use url::Url; use ws::{connect, Result as WsResult, Sender as WsSender}; +#[deprecated = "Use JsonrpseeClient or TungsteniteRpcClient instead."] #[derive(Debug, Clone)] pub struct WsRpcClient { url: Url, diff --git a/testing/sync/examples/ws_client_test.rs b/testing/sync/examples/ws_client_test.rs deleted file mode 100755 index 13e4a7939..000000000 --- a/testing/sync/examples/ws_client_test.rs +++ /dev/null @@ -1,64 +0,0 @@ -/* - Copyright 2019 Supercomputing Systems AG - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -use sp_core::{ - crypto::{Pair, Ss58Codec}, - sr25519, -}; -use sp_runtime::MultiAddress; -use substrate_api_client::{ - ac_primitives::RococoRuntimeConfig, extrinsic::BalancesExtrinsics, rpc::WsRpcClient, Api, - GetAccountInformation, SubmitAndWatch, XtStatus, -}; - -fn main() { - // Setup - let alice: sr25519::Pair = Pair::from_string( - "0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a", - None, - ) - .unwrap(); - let client = WsRpcClient::with_default_url(); - let mut api = Api::::new(client).unwrap(); - api.set_signer(alice.clone().into()); - - let bob = sr25519::Public::from_ss58check("5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty") - .unwrap(); - let bob_balance = api.get_account_data(&bob.into()).unwrap().unwrap_or_default().free; - - // Check for failed extrinsic failed onchain - let xt = api - .balance_transfer_allow_death(MultiAddress::Id(bob.into()), bob_balance + 1) - .unwrap(); - let result = api.submit_and_watch_extrinsic_until(xt.clone(), XtStatus::InBlock); - assert!(format!("{:?}", result).contains("FundsUnavailable")); - - // Check directly failed extrinsic (before actually submitted to a block) - let result = api.submit_and_watch_extrinsic_until(xt, XtStatus::InBlock); - assert!(result.is_err()); - assert!(format!("{:?}", result).contains("ExtrinsicFailed")); - - // Check for successful extrinisc - let xt = api - .balance_transfer_allow_death(MultiAddress::Id(bob.into()), bob_balance / 2) - .unwrap(); - let _block_hash = api - .submit_and_watch_extrinsic_until(xt, XtStatus::InBlock) - .unwrap() - .block_hash - .unwrap(); - let bob_new_balance = api.get_account_data(&bob.into()).unwrap().unwrap().free; - assert!(bob_new_balance > bob_balance); -} From ac6f041063db40ea316ce40baca0606bc786b3df Mon Sep 17 00:00:00 2001 From: haerdib Date: Tue, 4 Feb 2025 09:18:14 +0100 Subject: [PATCH 2/2] remove ws client from CI --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ee9f1e6d..82c98a33a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -215,7 +215,6 @@ jobs: sudo, new_json_rpc_api_calls, transfer_with_tungstenite_client, - transfer_with_ws_client, author_tests, chain_tests, dispatch_errors_tests, @@ -226,7 +225,6 @@ jobs: pallet_transaction_payment_tests, runtime_api_tests, tungstenite_client_test, - ws_client_test, state_tests, query_runtime_api, runtime_update_sync,