,
/// Subscriptions manager
subscriptions: Subscriptions,
/// The key store.
keystore: BareCryptoStorePtr,
}
impl Author {
/// Create new instance of Authoring API.
pub fn new(
client: Arc ,
subscriptions: Subscriptions,
keystore: BareCryptoStorePtr,
) -> Self {
Author {
client,
pool,
subscriptions,
keystore,
}
}
}
impl AuthorApi >
for Author::Block, RA>
where
B: sc_client_api::backend::Backend< ::Block> + Send + Sync + 'static,
E: sc_client::CallExecutor< ::Block> + Send + Sync + 'static,
P: TransactionPool + Sync + Send + 'static,
P::Block: traits::Block,
P::Error: 'static,
RA: Send + Sync + 'static,
Client: ProvideRuntimeApi >>,
xt: Bytes,
) {
let submit = || -> Result<_> {
let best_block_hash = self.client.chain_info().best_hash;
let dxt = TransactionFor:: ::decode(&mut &xt[..])
.map_err(error::Error::from)?;
Ok(
self.pool
.submit_and_watch(&generic::BlockId::hash(best_block_hash), dxt)
.map_err(|e| e.into_pool_error()
.map(error::Error::from)
.unwrap_or_else(|e| error::Error::Verification(Box::new(e)).into())
)
)
};
let subscriptions = self.subscriptions.clone();
let future = ready(submit())
.and_then(|res| res)
// convert the watcher into a `Stream`
.map(|res| res.map(|stream| stream.map(|v| Ok::<_, ()>(Ok(v)))))
// now handle the import result,
// start a new subscrition
.map(move |result| match result {
Ok(watcher) => {
subscriptions.add(subscriber, move |sink| {
sink
.sink_map_err(|_| unimplemented!())
.send_all(Compat::new(watcher))
.map(|_| ())
});
},
Err(err) => {
warn!("Failed to submit extrinsic: {}", err);
// reject the subscriber (ignore errors - we don't care if subscriber is no longer there).
let _ = subscriber.reject(err.into());
},
});
let res = self.subscriptions.executor()
.execute(Box::new(Compat::new(future.map(|_| Ok(())))));
if res.is_err() {
warn!("Error spawning subscription RPC task.");
}
}
fn unwatch_extrinsic(&self, _metadata: Option