mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 08:21:05 +00:00
fix some nits
This commit is contained in:
+8
-6
@@ -35,6 +35,7 @@ use core::{
|
||||
use frame_metadata::RuntimeMetadataPrefixed;
|
||||
pub use jsonrpsee::{
|
||||
client_transport::ws::{
|
||||
InvalidUri,
|
||||
Receiver as WsReceiver,
|
||||
Sender as WsSender,
|
||||
Uri,
|
||||
@@ -650,23 +651,24 @@ impl<T: Config> ExtrinsicSuccess<T> {
|
||||
|
||||
/// Example to check that `From<(Sender, Receiver) for RpcClient` works.
|
||||
pub async fn build_ws_client_default(url: &str) -> Result<RpcClient, RpcError> {
|
||||
let client = ws_transport(url).await.into();
|
||||
let client = ws_transport(url).await?.into();
|
||||
Ok(client)
|
||||
}
|
||||
|
||||
/// Build WS RPC client from URL
|
||||
pub async fn build_ws_client(url: &str) -> Result<RpcClient, RpcError> {
|
||||
let (sender, receiver) = ws_transport(url).await;
|
||||
let (sender, receiver) = ws_transport(url).await?;
|
||||
Ok(RpcClientBuilder::default()
|
||||
.max_notifs_per_subscription(4096)
|
||||
.build(sender, receiver))
|
||||
}
|
||||
|
||||
async fn ws_transport(url: &str) -> (WsSender, WsReceiver) {
|
||||
// fix unwraps because I'm lazy.
|
||||
let url: Uri = url.parse().unwrap();
|
||||
async fn ws_transport(url: &str) -> Result<(WsSender, WsReceiver), RpcError> {
|
||||
let url: Uri = url
|
||||
.parse()
|
||||
.map_err(|e: InvalidUri| RpcError::Transport(e.into()))?;
|
||||
WsTransportClientBuilder::default()
|
||||
.build(url)
|
||||
.await
|
||||
.unwrap()
|
||||
.map_err(|e| RpcError::Transport(e.into()))
|
||||
}
|
||||
|
||||
@@ -12,3 +12,4 @@ codec = { package = "parity-scale-codec", version = "2", default-features = fals
|
||||
subxt = { path = ".." }
|
||||
async-std = { version = "1.9.0", features = ["attributes"] }
|
||||
sp-core = { package = "sp-core", git = "https://github.com/paritytech/substrate/", branch = "master" }
|
||||
jsonrpsee-http-client = { git = "https://github.com/paritytech/jsonrpsee/", branch = "extract-async-client" }
|
||||
|
||||
+10
-11
@@ -14,6 +14,10 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with subxt. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use jsonrpsee_http_client::{
|
||||
types::traits::Client,
|
||||
HttpClientBuilder,
|
||||
};
|
||||
use std::{
|
||||
env,
|
||||
fs,
|
||||
@@ -27,11 +31,6 @@ use std::{
|
||||
thread,
|
||||
time,
|
||||
};
|
||||
use subxt::rpc::{
|
||||
build_ws_client,
|
||||
rpc_params,
|
||||
Client as _,
|
||||
};
|
||||
|
||||
static SUBSTRATE_BIN_ENV_VAR: &str = "SUBSTRATE_NODE_PATH";
|
||||
|
||||
@@ -47,7 +46,7 @@ async fn main() {
|
||||
let cmd = Command::new(&substrate_bin)
|
||||
.arg("--dev")
|
||||
.arg("--tmp")
|
||||
.arg(format!("--ws-port={}", port))
|
||||
.arg(format!("--rpc-port={}", port))
|
||||
.spawn();
|
||||
let mut cmd = match cmd {
|
||||
Ok(cmd) => cmd,
|
||||
@@ -61,15 +60,15 @@ async fn main() {
|
||||
const MAX_RETRIES: usize = 20;
|
||||
let mut retries = 0;
|
||||
let mut wait_secs = 1;
|
||||
let rpc_client = HttpClientBuilder::default()
|
||||
.build(&format!("http://localhost:{}", port))
|
||||
.expect("valid URL; qed");
|
||||
|
||||
loop {
|
||||
if retries >= MAX_RETRIES {
|
||||
panic!("Cannot connect to substrate node after {} retries", retries);
|
||||
}
|
||||
let res = build_ws_client(&format!("ws://localhost:{}", port))
|
||||
.await
|
||||
.expect("should only error if malformed URL for an HTTP connection")
|
||||
.request("state_getMetadata", rpc_params![])
|
||||
.await;
|
||||
let res = rpc_client.request("state_getMetadata", None).await;
|
||||
match res {
|
||||
Ok(res) => {
|
||||
let _ = cmd.kill();
|
||||
|
||||
Reference in New Issue
Block a user