mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-05 09:47:25 +00:00
Run cargo fmt on the whole code base (#9394)
* Run cargo fmt on the whole code base * Second run * Add CI check * Fix compilation * More unnecessary braces * Handle weights * Use --all * Use correct attributes... * Fix UI tests * AHHHHHHHHH * 🤦 * Docs * Fix compilation * 🤷 * Please stop * 🤦 x 2 * More * make rustfmt.toml consistent with polkadot Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -21,30 +21,33 @@
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use std::{sync::Arc, convert::TryInto};
|
||||
use log::warn;
|
||||
use std::{convert::TryInto, sync::Arc};
|
||||
|
||||
use sp_blockchain::HeaderBackend;
|
||||
|
||||
use rpc::futures::{Sink, Future, future::result};
|
||||
use futures::{StreamExt as _, compat::Compat};
|
||||
use futures::future::{ready, FutureExt, TryFutureExt};
|
||||
use sc_rpc_api::DenyUnsafe;
|
||||
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId, manager::SubscriptionManager};
|
||||
use codec::{Encode, Decode};
|
||||
use sp_core::Bytes;
|
||||
use sp_keystore::{SyncCryptoStorePtr, SyncCryptoStore};
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
use sp_runtime::generic;
|
||||
use sc_transaction_pool_api::{
|
||||
TransactionPool, InPoolTransaction, TransactionStatus, TransactionSource,
|
||||
BlockHash, TxHash, TransactionFor, error::IntoPoolError,
|
||||
use codec::{Decode, Encode};
|
||||
use futures::{
|
||||
compat::Compat,
|
||||
future::{ready, FutureExt, TryFutureExt},
|
||||
StreamExt as _,
|
||||
};
|
||||
use jsonrpc_pubsub::{manager::SubscriptionManager, typed::Subscriber, SubscriptionId};
|
||||
use rpc::futures::{future::result, Future, Sink};
|
||||
use sc_rpc_api::DenyUnsafe;
|
||||
use sc_transaction_pool_api::{
|
||||
error::IntoPoolError, BlockHash, InPoolTransaction, TransactionFor, TransactionPool,
|
||||
TransactionSource, TransactionStatus, TxHash,
|
||||
};
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
use sp_core::Bytes;
|
||||
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
|
||||
use sp_runtime::generic;
|
||||
use sp_session::SessionKeys;
|
||||
|
||||
use self::error::{Error, FutureResult, Result};
|
||||
/// Re-export the API for backward compatibility.
|
||||
pub use sc_rpc_api::author::*;
|
||||
use self::error::{Error, FutureResult, Result};
|
||||
|
||||
/// Authoring API
|
||||
pub struct Author<P, Client> {
|
||||
@@ -69,13 +72,7 @@ impl<P, Client> Author<P, Client> {
|
||||
keystore: SyncCryptoStorePtr,
|
||||
deny_unsafe: DenyUnsafe,
|
||||
) -> Self {
|
||||
Author {
|
||||
client,
|
||||
pool,
|
||||
subscriptions,
|
||||
keystore,
|
||||
deny_unsafe,
|
||||
}
|
||||
Author { client, pool, subscriptions, keystore, deny_unsafe }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,19 +84,14 @@ impl<P, Client> Author<P, Client> {
|
||||
const TX_SOURCE: TransactionSource = TransactionSource::External;
|
||||
|
||||
impl<P, Client> AuthorApi<TxHash<P>, BlockHash<P>> for Author<P, Client>
|
||||
where
|
||||
P: TransactionPool + Sync + Send + 'static,
|
||||
Client: HeaderBackend<P::Block> + ProvideRuntimeApi<P::Block> + Send + Sync + 'static,
|
||||
Client::Api: SessionKeys<P::Block>,
|
||||
where
|
||||
P: TransactionPool + Sync + Send + 'static,
|
||||
Client: HeaderBackend<P::Block> + ProvideRuntimeApi<P::Block> + Send + Sync + 'static,
|
||||
Client::Api: SessionKeys<P::Block>,
|
||||
{
|
||||
type Metadata = crate::Metadata;
|
||||
|
||||
fn insert_key(
|
||||
&self,
|
||||
key_type: String,
|
||||
suri: String,
|
||||
public: Bytes,
|
||||
) -> Result<()> {
|
||||
fn insert_key(&self, key_type: String, suri: String, public: Bytes) -> Result<()> {
|
||||
self.deny_unsafe.check_if_safe()?;
|
||||
|
||||
let key_type = key_type.as_str().try_into().map_err(|_| Error::BadKeyType)?;
|
||||
@@ -112,20 +104,22 @@ impl<P, Client> AuthorApi<TxHash<P>, BlockHash<P>> for Author<P, Client>
|
||||
self.deny_unsafe.check_if_safe()?;
|
||||
|
||||
let best_block_hash = self.client.info().best_hash;
|
||||
self.client.runtime_api().generate_session_keys(
|
||||
&generic::BlockId::Hash(best_block_hash),
|
||||
None,
|
||||
).map(Into::into).map_err(|e| Error::Client(Box::new(e)))
|
||||
self.client
|
||||
.runtime_api()
|
||||
.generate_session_keys(&generic::BlockId::Hash(best_block_hash), None)
|
||||
.map(Into::into)
|
||||
.map_err(|e| Error::Client(Box::new(e)))
|
||||
}
|
||||
|
||||
fn has_session_keys(&self, session_keys: Bytes) -> Result<bool> {
|
||||
self.deny_unsafe.check_if_safe()?;
|
||||
|
||||
let best_block_hash = self.client.info().best_hash;
|
||||
let keys = self.client.runtime_api().decode_session_keys(
|
||||
&generic::BlockId::Hash(best_block_hash),
|
||||
session_keys.to_vec(),
|
||||
).map_err(|e| Error::Client(Box::new(e)))?
|
||||
let keys = self
|
||||
.client
|
||||
.runtime_api()
|
||||
.decode_session_keys(&generic::BlockId::Hash(best_block_hash), session_keys.to_vec())
|
||||
.map_err(|e| Error::Client(Box::new(e)))?
|
||||
.ok_or_else(|| Error::InvalidSessionKeys)?;
|
||||
|
||||
Ok(SyncCryptoStore::has_keys(&*self.keystore, &keys))
|
||||
@@ -144,12 +138,15 @@ impl<P, Client> AuthorApi<TxHash<P>, BlockHash<P>> for Author<P, Client>
|
||||
Err(err) => return Box::new(result(Err(err.into()))),
|
||||
};
|
||||
let best_block_hash = self.client.info().best_hash;
|
||||
Box::new(self.pool
|
||||
.submit_one(&generic::BlockId::hash(best_block_hash), TX_SOURCE, xt)
|
||||
.compat()
|
||||
.map_err(|e| e.into_pool_error()
|
||||
.map(Into::into)
|
||||
.unwrap_or_else(|e| error::Error::Verification(Box::new(e)).into()))
|
||||
Box::new(
|
||||
self.pool
|
||||
.submit_one(&generic::BlockId::hash(best_block_hash), TX_SOURCE, xt)
|
||||
.compat()
|
||||
.map_err(|e| {
|
||||
e.into_pool_error()
|
||||
.map(Into::into)
|
||||
.unwrap_or_else(|e| error::Error::Verification(Box::new(e)).into())
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -163,7 +160,8 @@ impl<P, Client> AuthorApi<TxHash<P>, BlockHash<P>> for Author<P, Client>
|
||||
) -> Result<Vec<TxHash<P>>> {
|
||||
self.deny_unsafe.check_if_safe()?;
|
||||
|
||||
let hashes = bytes_or_hash.into_iter()
|
||||
let hashes = bytes_or_hash
|
||||
.into_iter()
|
||||
.map(|x| match x {
|
||||
hash::ExtrinsicOrHash::Hash(h) => Ok(h),
|
||||
hash::ExtrinsicOrHash::Extrinsic(bytes) => {
|
||||
@@ -173,32 +171,31 @@ impl<P, Client> AuthorApi<TxHash<P>, BlockHash<P>> for Author<P, Client>
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
|
||||
Ok(
|
||||
self.pool
|
||||
.remove_invalid(&hashes)
|
||||
.into_iter()
|
||||
.map(|tx| tx.hash().clone())
|
||||
.collect()
|
||||
)
|
||||
Ok(self
|
||||
.pool
|
||||
.remove_invalid(&hashes)
|
||||
.into_iter()
|
||||
.map(|tx| tx.hash().clone())
|
||||
.collect())
|
||||
}
|
||||
|
||||
fn watch_extrinsic(&self,
|
||||
fn watch_extrinsic(
|
||||
&self,
|
||||
_metadata: Self::Metadata,
|
||||
subscriber: Subscriber<TransactionStatus<TxHash<P>, BlockHash<P>>>,
|
||||
xt: Bytes,
|
||||
) {
|
||||
let submit = || -> Result<_> {
|
||||
let best_block_hash = self.client.info().best_hash;
|
||||
let dxt = TransactionFor::<P>::decode(&mut &xt[..])
|
||||
.map_err(error::Error::from)?;
|
||||
Ok(
|
||||
self.pool
|
||||
.submit_and_watch(&generic::BlockId::hash(best_block_hash), TX_SOURCE, dxt)
|
||||
.map_err(|e| e.into_pool_error()
|
||||
let dxt = TransactionFor::<P>::decode(&mut &xt[..]).map_err(error::Error::from)?;
|
||||
Ok(self
|
||||
.pool
|
||||
.submit_and_watch(&generic::BlockId::hash(best_block_hash), TX_SOURCE, 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();
|
||||
@@ -211,8 +208,7 @@ impl<P, Client> AuthorApi<TxHash<P>, BlockHash<P>> for Author<P, Client>
|
||||
.map(move |result| match result {
|
||||
Ok(watcher) => {
|
||||
subscriptions.add(subscriber, move |sink| {
|
||||
sink
|
||||
.sink_map_err(|e| log::debug!("Subscription sink failed: {:?}", e))
|
||||
sink.sink_map_err(|e| log::debug!("Subscription sink failed: {:?}", e))
|
||||
.send_all(Compat::new(watcher))
|
||||
.map(|_| ())
|
||||
});
|
||||
@@ -224,14 +220,20 @@ impl<P, Client> AuthorApi<TxHash<P>, BlockHash<P>> for Author<P, Client>
|
||||
},
|
||||
});
|
||||
|
||||
let res = self.subscriptions.executor()
|
||||
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<Self::Metadata>, id: SubscriptionId) -> Result<bool> {
|
||||
fn unwatch_extrinsic(
|
||||
&self,
|
||||
_metadata: Option<Self::Metadata>,
|
||||
id: SubscriptionId,
|
||||
) -> Result<bool> {
|
||||
Ok(self.subscriptions.cancel(id))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user