mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 15:11:03 +00:00
return none if subscription returns early (#250)
* return none if subscription returns early Signed-off-by: Gregory Hill <gregorydhill@outlook.com> * add comment on subscription close Signed-off-by: Gregory Hill <gregorydhill@outlook.com> * no need for jsonrpsee error enum Signed-off-by: Gregory Hill <gregorydhill@outlook.com>
This commit is contained in:
+8
-16
@@ -14,7 +14,6 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.
|
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use jsonrpsee_types::error::Error as RpcError;
|
|
||||||
use jsonrpsee_ws_client::WsSubscription as Subscription;
|
use jsonrpsee_ws_client::WsSubscription as Subscription;
|
||||||
use sp_core::{
|
use sp_core::{
|
||||||
storage::{
|
storage::{
|
||||||
@@ -95,14 +94,8 @@ impl<'a, T: Runtime> EventSubscription<'a, T> {
|
|||||||
if self.finished {
|
if self.finished {
|
||||||
return None
|
return None
|
||||||
}
|
}
|
||||||
let change_set = match self.subscription.next().await {
|
// always return None if subscription has closed
|
||||||
Some(c) => c,
|
let change_set = self.subscription.next().await?;
|
||||||
None => {
|
|
||||||
return Some(Err(
|
|
||||||
RpcError::Custom("RPC subscription dropped".into()).into()
|
|
||||||
))
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if let Some(hash) = self.block.as_ref() {
|
if let Some(hash) = self.block.as_ref() {
|
||||||
if &change_set.block == hash {
|
if &change_set.block == hash {
|
||||||
self.finished = true;
|
self.finished = true;
|
||||||
@@ -184,13 +177,12 @@ impl<T: Runtime> FinalizedEventStorageSubscription<T> {
|
|||||||
return Some(storage_change)
|
return Some(storage_change)
|
||||||
}
|
}
|
||||||
let header: T::Header = self.subscription.next().await?;
|
let header: T::Header = self.subscription.next().await?;
|
||||||
if let Ok(storage_changes) = self
|
self.storage_changes.extend(
|
||||||
.rpc
|
self.rpc
|
||||||
.query_storage_at(&[self.storage_key.clone()], Some(header.hash()))
|
.query_storage_at(&[self.storage_key.clone()], Some(header.hash()))
|
||||||
.await
|
.await
|
||||||
{
|
.ok()?,
|
||||||
self.storage_changes.extend(storage_changes);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user