mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 10:31:04 +00:00
Split RPCs into a separate crate (#1910)
* WIP extract RPCs into separate crate * fmt * Fix test * Remove unused deps * fix import * WIP: Fix up errors and most tests. Start extracintg some tests/code to rpc crate * MockRpcClient sync or async * MockRpcClient only async but better type inference * WIP MockRpcClient FnMuts and some test updates to use it * Get all but one test working with new MockRpcClient * WIP trying to debug failure * WIP, Tests mostly fixed, need to add back oen more * Get mock RPC tests working * fmt * fmt * Clippy and comment tweak * update CI to explicitly check subxt-rpc features * clippy * small tweaks after pass over * feature flag rename * update some docs * Fix some examples * fmt * Fix features flags to work with web/wasm32 * Fix unused dep warning * explicit targets in wasm CI * Add better crate level docs * fmt * Address review comments * Comment out flaky test for now and make more obvious how similar POlkadot and Substrate configs are * Not a doc comment * Remove unused imports
This commit is contained in:
+2
-27
@@ -5,8 +5,6 @@
|
||||
//! Miscellaneous utility helpers.
|
||||
|
||||
use crate::macros::cfg_jsonrpsee;
|
||||
use crate::{error::RpcError, Error};
|
||||
use url::Url;
|
||||
|
||||
pub use subxt_core::utils::{
|
||||
bits, strip_compact_prefix, to_hex, AccountId32, Encoded, Era, KeyedVec, MultiAddress,
|
||||
@@ -14,32 +12,9 @@ pub use subxt_core::utils::{
|
||||
H256, H512,
|
||||
};
|
||||
|
||||
pub use subxt_rpcs::utils::url_is_secure;
|
||||
|
||||
cfg_jsonrpsee! {
|
||||
mod fetch_chain_spec;
|
||||
pub use fetch_chain_spec::{fetch_chainspec_from_rpc_node, FetchChainspecError};
|
||||
}
|
||||
|
||||
/// A URL is considered secure if it uses a secure scheme ("https" or "wss") or is referring to localhost.
|
||||
///
|
||||
/// Returns an error if the string could not be parsed into a URL.
|
||||
pub fn url_is_secure(url: &str) -> Result<bool, Error> {
|
||||
let url = Url::parse(url).map_err(|e| Error::Rpc(RpcError::ClientError(Box::new(e))))?;
|
||||
|
||||
let secure_scheme = url.scheme() == "https" || url.scheme() == "wss";
|
||||
let is_localhost = url.host().is_some_and(|e| match e {
|
||||
url::Host::Domain(e) => e == "localhost",
|
||||
url::Host::Ipv4(e) => e.is_loopback(),
|
||||
url::Host::Ipv6(e) => e.is_loopback(),
|
||||
});
|
||||
|
||||
Ok(secure_scheme || is_localhost)
|
||||
}
|
||||
|
||||
/// Validates, that the given Url is secure ("https" or "wss" scheme) or is referring to localhost.
|
||||
pub fn validate_url_is_secure(url: &str) -> Result<(), Error> {
|
||||
if !url_is_secure(url)? {
|
||||
Err(Error::Rpc(crate::error::RpcError::InsecureUrl(url.into())))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user