Skip to content

Commit 62474c7

Browse files
committed
Fix decoding of GeodeState
1 parent 2a6371b commit 62474c7

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

rpc/src/geode.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ use sc_client_api::StorageChangeSet;
1515
use sp_core::storage::StorageKey;
1616
use sp_core::{blake2_128, twox_128};
1717

18-
use futures::{StreamExt, TryStreamExt};
19-
use jsonrpc_core::futures::{
20-
future::Future as Future01, sink::Sink as Sink01, stream, stream::Stream as Stream01,
21-
};
18+
use futures::{future, StreamExt, TryStreamExt};
19+
use jsonrpc_core::futures::{future::Future, sink::Sink, stream, stream::Stream};
2220
use jsonrpc_pubsub::{manager::SubscriptionManager, typed::Subscriber, SubscriptionId};
2321
use log::warn;
2422

@@ -220,13 +218,16 @@ where
220218
};
221219

222220
let stream = stream
223-
.map(|(_block, changes)| Ok::<_, ()>(get_geode_state(changes)))
221+
.filter_map(move |(_block, changes)| match get_geode_state(changes) {
222+
Ok(state) => future::ready(Some(Ok::<_, ()>(Ok(state)))),
223+
Err(_) => future::ready(None),
224+
})
224225
.compat();
225226

226227
self.manager.add(subscriber, |sink| {
227-
let stream = stream.map(|res| Ok(res));
228228
sink.sink_map_err(|e| warn!("Error sending notifications: {:?}", e))
229229
.send_all(stream::iter_result(vec![Ok(initial)]).chain(stream))
230+
// we ignore the resulting Stream (if the first stream is over we are unsubscribed)
230231
.map(|_| ())
231232
});
232233
}
@@ -259,22 +260,22 @@ fn blake2_128_concat(d: &[u8]) -> Vec<u8> {
259260
v
260261
}
261262

262-
fn get_geode_state(changes: StorageChangeSet) -> GeodeState {
263+
fn get_geode_state(changes: StorageChangeSet) -> Result<GeodeState> {
263264
for (_, _, data) in changes.iter() {
264265
match data {
265266
Some(data) => {
266267
let mut value: &[u8] = &data.0.clone();
267-
match GeodeState::decode(&mut value) {
268-
Ok(state) => {
269-
return state;
268+
match Geode::<AccountId, Hash>::decode(&mut value) {
269+
Ok(geode) => {
270+
return Ok(geode.state);
270271
}
271-
Err(_) => warn!("unable to decode GeodeState"),
272+
Err(_) => warn!("unable to decode Geode"),
272273
}
273274
}
274275
None => warn!("empty change set"),
275276
};
276277
}
277-
GeodeState::Null
278+
Err(Error::internal_error())
278279
}
279280

280281
fn client_err(_: sp_blockchain::Error) -> Error {

0 commit comments

Comments
 (0)