deps: update jsonrpsee 0.2.0 (#285)

* deps: update jsonrpsee 0.2.0

The motivation is to avoid pinning certain alpha versions and to avoid
breaking users builds without having to some `Cargo.lock` updating.

* cargo fmt

* fix tests

* fix a few clippy lints

* cargo fmt
This commit is contained in:
Niklas Adolfsson
2021-06-08 19:15:12 +02:00
committed by GitHub
parent 490836fa2d
commit 08a3e6574d
7 changed files with 73 additions and 50 deletions
+28 -3
View File
@@ -14,7 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.
use jsonrpsee_ws_client::Subscription;
use jsonrpsee_types::{
DeserializeOwned,
Subscription,
};
use sp_core::{
storage::{
StorageChangeSet,
@@ -176,7 +179,9 @@ impl<T: Runtime> FinalizedEventStorageSubscription<T> {
if let Some(storage_change) = self.storage_changes.pop_front() {
return Some(storage_change)
}
let header: T::Header = self.subscription.next().await?;
let header: T::Header =
read_subscription_response("HeaderSubscription", &mut self.subscription)
.await?;
self.storage_changes.extend(
self.rpc
.query_storage_at(&[self.storage_key.clone()], Some(header.hash()))
@@ -199,8 +204,28 @@ impl<T: Runtime> EventStorageSubscription<T> {
/// Gets the next change_set from the subscription.
pub async fn next(&mut self) -> Option<StorageChangeSet<T::Hash>> {
match self {
Self::Imported(event_sub) => event_sub.next().await,
Self::Imported(event_sub) => {
read_subscription_response("StorageChangeSetSubscription", event_sub)
.await
}
Self::Finalized(event_sub) => event_sub.next().await,
}
}
}
async fn read_subscription_response<T>(
sub_name: &str,
sub: &mut Subscription<T>,
) -> Option<T>
where
T: DeserializeOwned,
{
match sub.next().await {
Ok(Some(next)) => Some(next),
Ok(None) => None,
Err(e) => {
log::error!("Subscription {} failed: {:?} dropping", sub_name, e);
None
}
}
}