Bump jsonrpsee to Alpha.3 (#892)

* Bump `jsonrpsee` to `alpha.3`

* Arc-ify `WsClient`
This commit is contained in:
Hernando Castano
2021-04-12 17:22:24 -04:00
committed by Bastian Köcher
parent fe4c899594
commit b569f201cf
3 changed files with 27 additions and 26 deletions
+3 -3
View File
@@ -10,9 +10,9 @@ bp-eth-poa = { path = "../../primitives/ethereum-poa" }
codec = { package = "parity-scale-codec", version = "2.0.0" } codec = { package = "parity-scale-codec", version = "2.0.0" }
headers-relay = { path = "../headers" } headers-relay = { path = "../headers" }
hex-literal = "0.3" hex-literal = "0.3"
jsonrpsee-proc-macros = "0.2.0-alpha.2" jsonrpsee-proc-macros = "=0.2.0-alpha.3"
jsonrpsee-types = "0.2.0-alpha.2" jsonrpsee-types = "=0.2.0-alpha.3"
jsonrpsee-ws-client = "0.2.0-alpha.2" jsonrpsee-ws-client = "=0.2.0-alpha.3"
libsecp256k1 = { version = "0.3.4", default-features = false, features = ["hmac"] } libsecp256k1 = { version = "0.3.4", default-features = false, features = ["hmac"] }
log = "0.4.11" log = "0.4.11"
relay-utils = { path = "../utils" } relay-utils = { path = "../utils" }
+3 -3
View File
@@ -9,9 +9,9 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
async-std = "1.6.5" async-std = "1.6.5"
async-trait = "0.1.40" async-trait = "0.1.40"
codec = { package = "parity-scale-codec", version = "2.0.0" } codec = { package = "parity-scale-codec", version = "2.0.0" }
jsonrpsee-proc-macros = "0.2.0-alpha.2" jsonrpsee-proc-macros = "=0.2.0-alpha.3"
jsonrpsee-types = "0.2.0-alpha.2" jsonrpsee-types = "=0.2.0-alpha.3"
jsonrpsee-ws-client = "0.2.0-alpha.2" jsonrpsee-ws-client = "=0.2.0-alpha.3"
log = "0.4.11" log = "0.4.11"
num-traits = "0.2" num-traits = "0.2"
rand = "0.7" rand = "0.7"
+21 -20
View File
@@ -50,7 +50,7 @@ pub struct Client<C: Chain> {
/// Client connection params. /// Client connection params.
params: ConnectionParams, params: ConnectionParams,
/// Substrate RPC client. /// Substrate RPC client.
client: RpcClient, client: Arc<RpcClient>,
/// Genesis block hash. /// Genesis block hash.
genesis_hash: C::Hash, genesis_hash: C::Hash,
/// If several tasks are submitting their transactions simultaneously using `submit_signed_extrinsic` /// If several tasks are submitting their transactions simultaneously using `submit_signed_extrinsic`
@@ -84,7 +84,7 @@ impl<C: Chain> Client<C> {
let client = Self::build_client(params.clone()).await?; let client = Self::build_client(params.clone()).await?;
let number: C::BlockNumber = Zero::zero(); let number: C::BlockNumber = Zero::zero();
let genesis_hash = Substrate::<C>::chain_get_block_hash(&client, number).await?; let genesis_hash = Substrate::<C>::chain_get_block_hash(&*client, number).await?;
Ok(Self { Ok(Self {
params, params,
@@ -101,7 +101,7 @@ impl<C: Chain> Client<C> {
} }
/// Build client to use in connection. /// Build client to use in connection.
async fn build_client(params: ConnectionParams) -> Result<RpcClient> { async fn build_client(params: ConnectionParams) -> Result<Arc<RpcClient>> {
let uri = format!( let uri = format!(
"{}://{}:{}", "{}://{}:{}",
if params.secure { "wss" } else { "ws" }, if params.secure { "wss" } else { "ws" },
@@ -111,14 +111,15 @@ impl<C: Chain> Client<C> {
let mut config = RpcConfig::with_url(&uri); let mut config = RpcConfig::with_url(&uri);
config.max_notifs_per_subscription = MAX_SUBSCRIPTION_CAPACITY; config.max_notifs_per_subscription = MAX_SUBSCRIPTION_CAPACITY;
let client = RpcClient::new(config).await?; let client = RpcClient::new(config).await?;
Ok(client)
Ok(Arc::new(client))
} }
} }
impl<C: Chain> Client<C> { impl<C: Chain> Client<C> {
/// Returns true if client is connected to at least one peer and is in synced state. /// Returns true if client is connected to at least one peer and is in synced state.
pub async fn ensure_synced(&self) -> Result<()> { pub async fn ensure_synced(&self) -> Result<()> {
let health = Substrate::<C>::system_health(&self.client).await?; let health = Substrate::<C>::system_health(&*self.client).await?;
let is_synced = !health.is_syncing && (!health.should_have_peers || health.peers > 0); let is_synced = !health.is_syncing && (!health.should_have_peers || health.peers > 0);
if is_synced { if is_synced {
Ok(()) Ok(())
@@ -134,7 +135,7 @@ impl<C: Chain> Client<C> {
/// Return hash of the best finalized block. /// Return hash of the best finalized block.
pub async fn best_finalized_header_hash(&self) -> Result<C::Hash> { pub async fn best_finalized_header_hash(&self) -> Result<C::Hash> {
Ok(Substrate::<C>::chain_get_finalized_head(&self.client).await?) Ok(Substrate::<C>::chain_get_finalized_head(&*self.client).await?)
} }
/// Returns the best Substrate header. /// Returns the best Substrate header.
@@ -142,12 +143,12 @@ impl<C: Chain> Client<C> {
where where
C::Header: DeserializeOwned, C::Header: DeserializeOwned,
{ {
Ok(Substrate::<C>::chain_get_header(&self.client, None).await?) Ok(Substrate::<C>::chain_get_header(&*self.client, None).await?)
} }
/// Get a Substrate block from its hash. /// Get a Substrate block from its hash.
pub async fn get_block(&self, block_hash: Option<C::Hash>) -> Result<C::SignedBlock> { pub async fn get_block(&self, block_hash: Option<C::Hash>) -> Result<C::SignedBlock> {
Ok(Substrate::<C>::chain_get_block(&self.client, block_hash).await?) Ok(Substrate::<C>::chain_get_block(&*self.client, block_hash).await?)
} }
/// Get a Substrate header by its hash. /// Get a Substrate header by its hash.
@@ -155,12 +156,12 @@ impl<C: Chain> Client<C> {
where where
C::Header: DeserializeOwned, C::Header: DeserializeOwned,
{ {
Ok(Substrate::<C>::chain_get_header(&self.client, block_hash).await?) Ok(Substrate::<C>::chain_get_header(&*self.client, block_hash).await?)
} }
/// Get a Substrate block hash by its number. /// Get a Substrate block hash by its number.
pub async fn block_hash_by_number(&self, number: C::BlockNumber) -> Result<C::Hash> { pub async fn block_hash_by_number(&self, number: C::BlockNumber) -> Result<C::Hash> {
Ok(Substrate::<C>::chain_get_block_hash(&self.client, number).await?) Ok(Substrate::<C>::chain_get_block_hash(&*self.client, number).await?)
} }
/// Get a Substrate header by its number. /// Get a Substrate header by its number.
@@ -174,12 +175,12 @@ impl<C: Chain> Client<C> {
/// Return runtime version. /// Return runtime version.
pub async fn runtime_version(&self) -> Result<RuntimeVersion> { pub async fn runtime_version(&self) -> Result<RuntimeVersion> {
Ok(Substrate::<C>::runtime_version(&self.client).await?) Ok(Substrate::<C>::runtime_version(&*self.client).await?)
} }
/// Read value from runtime storage. /// Read value from runtime storage.
pub async fn storage_value<T: Decode>(&self, storage_key: StorageKey) -> Result<Option<T>> { pub async fn storage_value<T: Decode>(&self, storage_key: StorageKey) -> Result<Option<T>> {
Substrate::<C>::get_storage(&self.client, storage_key) Substrate::<C>::get_storage(&*self.client, storage_key)
.await? .await?
.map(|encoded_value| T::decode(&mut &encoded_value.0[..]).map_err(Error::ResponseParseFailed)) .map(|encoded_value| T::decode(&mut &encoded_value.0[..]).map_err(Error::ResponseParseFailed))
.transpose() .transpose()
@@ -191,7 +192,7 @@ impl<C: Chain> Client<C> {
C: ChainWithBalances, C: ChainWithBalances,
{ {
let storage_key = C::account_info_storage_key(&account); let storage_key = C::account_info_storage_key(&account);
let encoded_account_data = Substrate::<C>::get_storage(&self.client, storage_key) let encoded_account_data = Substrate::<C>::get_storage(&*self.client, storage_key)
.await? .await?
.ok_or(Error::AccountDoesNotExist)?; .ok_or(Error::AccountDoesNotExist)?;
let decoded_account_data = let decoded_account_data =
@@ -204,14 +205,14 @@ impl<C: Chain> Client<C> {
/// ///
/// Note: It's the caller's responsibility to make sure `account` is a valid ss58 address. /// Note: It's the caller's responsibility to make sure `account` is a valid ss58 address.
pub async fn next_account_index(&self, account: C::AccountId) -> Result<C::Index> { pub async fn next_account_index(&self, account: C::AccountId) -> Result<C::Index> {
Ok(Substrate::<C>::system_account_next_index(&self.client, account).await?) Ok(Substrate::<C>::system_account_next_index(&*self.client, account).await?)
} }
/// Submit unsigned extrinsic for inclusion in a block. /// Submit unsigned extrinsic for inclusion in a block.
/// ///
/// Note: The given transaction needs to be SCALE encoded beforehand. /// Note: The given transaction needs to be SCALE encoded beforehand.
pub async fn submit_unsigned_extrinsic(&self, transaction: Bytes) -> Result<C::Hash> { pub async fn submit_unsigned_extrinsic(&self, transaction: Bytes) -> Result<C::Hash> {
let tx_hash = Substrate::<C>::author_submit_extrinsic(&self.client, transaction).await?; let tx_hash = Substrate::<C>::author_submit_extrinsic(&*self.client, transaction).await?;
log::trace!(target: "bridge", "Sent transaction to Substrate node: {:?}", tx_hash); log::trace!(target: "bridge", "Sent transaction to Substrate node: {:?}", tx_hash);
Ok(tx_hash) Ok(tx_hash)
} }
@@ -231,7 +232,7 @@ impl<C: Chain> Client<C> {
let _guard = self.submit_signed_extrinsic_lock.lock().await; let _guard = self.submit_signed_extrinsic_lock.lock().await;
let transaction_nonce = self.next_account_index(extrinsic_signer).await?; let transaction_nonce = self.next_account_index(extrinsic_signer).await?;
let extrinsic = prepare_extrinsic(transaction_nonce); let extrinsic = prepare_extrinsic(transaction_nonce);
let tx_hash = Substrate::<C>::author_submit_extrinsic(&self.client, extrinsic).await?; let tx_hash = Substrate::<C>::author_submit_extrinsic(&*self.client, extrinsic).await?;
log::trace!(target: "bridge", "Sent transaction to {} node: {:?}", C::NAME, tx_hash); log::trace!(target: "bridge", "Sent transaction to {} node: {:?}", C::NAME, tx_hash);
Ok(tx_hash) Ok(tx_hash)
} }
@@ -241,7 +242,7 @@ impl<C: Chain> Client<C> {
let call = SUB_API_GRANDPA_AUTHORITIES.to_string(); let call = SUB_API_GRANDPA_AUTHORITIES.to_string();
let data = Bytes(Vec::new()); let data = Bytes(Vec::new());
let encoded_response = Substrate::<C>::state_call(&self.client, call, data, Some(block)).await?; let encoded_response = Substrate::<C>::state_call(&*self.client, call, data, Some(block)).await?;
let authority_list = encoded_response.0; let authority_list = encoded_response.0;
Ok(authority_list) Ok(authority_list)
@@ -249,7 +250,7 @@ impl<C: Chain> Client<C> {
/// Execute runtime call at given block. /// Execute runtime call at given block.
pub async fn state_call(&self, method: String, data: Bytes, at_block: Option<C::Hash>) -> Result<Bytes> { pub async fn state_call(&self, method: String, data: Bytes, at_block: Option<C::Hash>) -> Result<Bytes> {
Substrate::<C>::state_call(&self.client, method, data, at_block) Substrate::<C>::state_call(&*self.client, method, data, at_block)
.await .await
.map_err(Into::into) .map_err(Into::into)
} }
@@ -264,7 +265,7 @@ impl<C: Chain> Client<C> {
at_block: C::Hash, at_block: C::Hash,
) -> Result<StorageProof> { ) -> Result<StorageProof> {
let encoded_trie_nodes = SubstrateMessages::<C>::prove_messages( let encoded_trie_nodes = SubstrateMessages::<C>::prove_messages(
&self.client, &*self.client,
instance, instance,
lane, lane,
*range.start(), *range.start(),
@@ -287,7 +288,7 @@ impl<C: Chain> Client<C> {
at_block: C::Hash, at_block: C::Hash,
) -> Result<Vec<Vec<u8>>> { ) -> Result<Vec<Vec<u8>>> {
let encoded_trie_nodes = let encoded_trie_nodes =
SubstrateMessages::<C>::prove_messages_delivery(&self.client, instance, lane, Some(at_block)) SubstrateMessages::<C>::prove_messages_delivery(&*self.client, instance, lane, Some(at_block))
.await .await
.map_err(Error::RpcError)?; .map_err(Error::RpcError)?;
let decoded_trie_nodes: Vec<Vec<u8>> = let decoded_trie_nodes: Vec<Vec<u8>> =