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" }
headers-relay = { path = "../headers" }
hex-literal = "0.3"
jsonrpsee-proc-macros = "0.2.0-alpha.2"
jsonrpsee-types = "0.2.0-alpha.2"
jsonrpsee-ws-client = "0.2.0-alpha.2"
jsonrpsee-proc-macros = "=0.2.0-alpha.3"
jsonrpsee-types = "=0.2.0-alpha.3"
jsonrpsee-ws-client = "=0.2.0-alpha.3"
libsecp256k1 = { version = "0.3.4", default-features = false, features = ["hmac"] }
log = "0.4.11"
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-trait = "0.1.40"
codec = { package = "parity-scale-codec", version = "2.0.0" }
jsonrpsee-proc-macros = "0.2.0-alpha.2"
jsonrpsee-types = "0.2.0-alpha.2"
jsonrpsee-ws-client = "0.2.0-alpha.2"
jsonrpsee-proc-macros = "=0.2.0-alpha.3"
jsonrpsee-types = "=0.2.0-alpha.3"
jsonrpsee-ws-client = "=0.2.0-alpha.3"
log = "0.4.11"
num-traits = "0.2"
rand = "0.7"
+21 -20
View File
@@ -50,7 +50,7 @@ pub struct Client<C: Chain> {
/// Client connection params.
params: ConnectionParams,
/// Substrate RPC client.
client: RpcClient,
client: Arc<RpcClient>,
/// Genesis block hash.
genesis_hash: C::Hash,
/// 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 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 {
params,
@@ -101,7 +101,7 @@ impl<C: Chain> Client<C> {
}
/// 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!(
"{}://{}:{}",
if params.secure { "wss" } else { "ws" },
@@ -111,14 +111,15 @@ impl<C: Chain> Client<C> {
let mut config = RpcConfig::with_url(&uri);
config.max_notifs_per_subscription = MAX_SUBSCRIPTION_CAPACITY;
let client = RpcClient::new(config).await?;
Ok(client)
Ok(Arc::new(client))
}
}
impl<C: Chain> Client<C> {
/// Returns true if client is connected to at least one peer and is in synced state.
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);
if is_synced {
Ok(())
@@ -134,7 +135,7 @@ impl<C: Chain> Client<C> {
/// Return hash of the best finalized block.
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.
@@ -142,12 +143,12 @@ impl<C: Chain> Client<C> {
where
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.
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.
@@ -155,12 +156,12 @@ impl<C: Chain> Client<C> {
where
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.
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.
@@ -174,12 +175,12 @@ impl<C: Chain> Client<C> {
/// Return runtime version.
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.
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?
.map(|encoded_value| T::decode(&mut &encoded_value.0[..]).map_err(Error::ResponseParseFailed))
.transpose()
@@ -191,7 +192,7 @@ impl<C: Chain> Client<C> {
C: ChainWithBalances,
{
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?
.ok_or(Error::AccountDoesNotExist)?;
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.
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.
///
/// Note: The given transaction needs to be SCALE encoded beforehand.
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);
Ok(tx_hash)
}
@@ -231,7 +232,7 @@ impl<C: Chain> Client<C> {
let _guard = self.submit_signed_extrinsic_lock.lock().await;
let transaction_nonce = self.next_account_index(extrinsic_signer).await?;
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);
Ok(tx_hash)
}
@@ -241,7 +242,7 @@ impl<C: Chain> Client<C> {
let call = SUB_API_GRANDPA_AUTHORITIES.to_string();
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;
Ok(authority_list)
@@ -249,7 +250,7 @@ impl<C: Chain> Client<C> {
/// Execute runtime call at given block.
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
.map_err(Into::into)
}
@@ -264,7 +265,7 @@ impl<C: Chain> Client<C> {
at_block: C::Hash,
) -> Result<StorageProof> {
let encoded_trie_nodes = SubstrateMessages::<C>::prove_messages(
&self.client,
&*self.client,
instance,
lane,
*range.start(),
@@ -287,7 +288,7 @@ impl<C: Chain> Client<C> {
at_block: C::Hash,
) -> Result<Vec<Vec<u8>>> {
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
.map_err(Error::RpcError)?;
let decoded_trie_nodes: Vec<Vec<u8>> =