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:
Bastian Köcher
2021-07-21 16:32:32 +02:00
committed by GitHub
parent d451c38c1c
commit 7b56ab15b4
1010 changed files with 53339 additions and 51208 deletions
+45 -68
View File
@@ -16,25 +16,21 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use std::{
str::FromStr,
sync::Arc,
convert::TryFrom,
thread::sleep,
collections::HashSet,
};
use std::{collections::HashSet, convert::TryFrom, str::FromStr, sync::Arc, thread::sleep};
use crate::NetworkProvider;
use codec::{Decode, Encode};
use futures::Future;
use sc_network::{PeerId, Multiaddr};
use codec::{Encode, Decode};
use sp_core::OpaquePeerId;
use sp_core::offchain::{
self, HttpRequestId, Timestamp, HttpRequestStatus, HttpError,
OffchainStorage, OpaqueNetworkState, OpaqueMultiaddr, StorageKind,
pub use http::SharedClient;
use sc_network::{Multiaddr, PeerId};
use sp_core::{
offchain::{
self, HttpError, HttpRequestId, HttpRequestStatus, OffchainStorage, OpaqueMultiaddr,
OpaqueNetworkState, StorageKind, Timestamp,
},
OpaquePeerId,
};
pub use sp_offchain::STORAGE_PREFIX;
pub use http::SharedClient;
#[cfg(not(target_os = "unknown"))]
mod http;
@@ -71,16 +67,15 @@ impl<Storage: OffchainStorage> Db<Storage> {
}
/// Create new instance of Offchain DB, backed by given backend.
pub fn factory_from_backend<Backend, Block>(backend: &Backend) -> Option<
Box<dyn sc_client_api::execution_extensions::DbExternalitiesFactory>
> where
pub fn factory_from_backend<Backend, Block>(
backend: &Backend,
) -> Option<Box<dyn sc_client_api::execution_extensions::DbExternalitiesFactory>>
where
Backend: sc_client_api::Backend<Block, OffchainStorage = Storage>,
Block: sp_runtime::traits::Block,
Storage: 'static,
{
sc_client_api::Backend::offchain_storage(backend).map(|db|
Box::new(Self::new(db)) as _
)
sc_client_api::Backend::offchain_storage(backend).map(|db| Box::new(Self::new(db)) as _)
}
}
@@ -123,9 +118,8 @@ impl<Storage: OffchainStorage> offchain::DbExternalities for Db<Storage> {
old_value.as_ref().map(hex::encode),
);
match kind {
StorageKind::PERSISTENT => {
self.persistent.compare_and_set(STORAGE_PREFIX, key, old_value, new_value)
},
StorageKind::PERSISTENT =>
self.persistent.compare_and_set(STORAGE_PREFIX, key, old_value, new_value),
StorageKind::LOCAL => unavailable_yet(LOCAL_DB),
}
}
@@ -167,10 +161,7 @@ impl offchain::Externalities for Api {
fn network_state(&self) -> Result<OpaqueNetworkState, ()> {
let external_addresses = self.network_provider.external_addresses();
let state = NetworkState::new(
self.network_provider.local_peer_id(),
external_addresses,
);
let state = NetworkState::new(self.network_provider.local_peer_id(), external_addresses);
Ok(OpaqueNetworkState::from(state))
}
@@ -190,7 +181,7 @@ impl offchain::Externalities for Api {
&mut self,
method: &str,
uri: &str,
_meta: &[u8]
_meta: &[u8],
) -> Result<HttpRequestId, ()> {
self.http.request_start(method, uri)
}
@@ -199,7 +190,7 @@ impl offchain::Externalities for Api {
&mut self,
request_id: HttpRequestId,
name: &str,
value: &str
value: &str,
) -> Result<(), ()> {
self.http.request_add_header(request_id, name, value)
}
@@ -208,7 +199,7 @@ impl offchain::Externalities for Api {
&mut self,
request_id: HttpRequestId,
chunk: &[u8],
deadline: Option<Timestamp>
deadline: Option<Timestamp>,
) -> Result<(), HttpError> {
self.http.request_write_body(request_id, chunk, deadline)
}
@@ -216,15 +207,12 @@ impl offchain::Externalities for Api {
fn http_response_wait(
&mut self,
ids: &[HttpRequestId],
deadline: Option<Timestamp>
deadline: Option<Timestamp>,
) -> Vec<HttpRequestStatus> {
self.http.response_wait(ids, deadline)
}
fn http_response_headers(
&mut self,
request_id: HttpRequestId
) -> Vec<(Vec<u8>, Vec<u8>)> {
fn http_response_headers(&mut self, request_id: HttpRequestId) -> Vec<(Vec<u8>, Vec<u8>)> {
self.http.response_headers(request_id)
}
@@ -232,15 +220,14 @@ impl offchain::Externalities for Api {
&mut self,
request_id: HttpRequestId,
buffer: &mut [u8],
deadline: Option<Timestamp>
deadline: Option<Timestamp>,
) -> Result<usize, HttpError> {
self.http.response_read_body(request_id, buffer, deadline)
}
fn set_authorized_nodes(&mut self, nodes: Vec<OpaquePeerId>, authorized_only: bool) {
let peer_ids: HashSet<PeerId> = nodes.into_iter()
.filter_map(|node| PeerId::from_bytes(&node.0).ok())
.collect();
let peer_ids: HashSet<PeerId> =
nodes.into_iter().filter_map(|node| PeerId::from_bytes(&node.0).ok()).collect();
self.network_provider.set_authorized_peers(peer_ids);
self.network_provider.set_authorized_only(authorized_only);
@@ -256,10 +243,7 @@ pub struct NetworkState {
impl NetworkState {
fn new(peer_id: PeerId, external_addresses: Vec<Multiaddr>) -> Self {
NetworkState {
peer_id,
external_addresses,
}
NetworkState { peer_id, external_addresses }
}
}
@@ -277,10 +261,7 @@ impl From<NetworkState> for OpaqueNetworkState {
})
.collect();
OpaqueNetworkState {
peer_id,
external_addresses,
}
OpaqueNetworkState { peer_id, external_addresses }
}
}
@@ -293,7 +274,8 @@ impl TryFrom<OpaqueNetworkState> for NetworkState {
let bytes: Vec<u8> = Decode::decode(&mut &inner_vec[..]).map_err(|_| ())?;
let peer_id = PeerId::from_bytes(&bytes).map_err(|_| ())?;
let external_addresses: Result<Vec<Multiaddr>, Self::Error> = state.external_addresses
let external_addresses: Result<Vec<Multiaddr>, Self::Error> = state
.external_addresses
.iter()
.map(|enc_multiaddr| -> Result<Multiaddr, Self::Error> {
let inner_vec = &enc_multiaddr.0;
@@ -305,10 +287,7 @@ impl TryFrom<OpaqueNetworkState> for NetworkState {
.collect();
let external_addresses = external_addresses?;
Ok(NetworkState {
peer_id,
external_addresses,
})
Ok(NetworkState { peer_id, external_addresses })
}
}
@@ -329,15 +308,9 @@ impl AsyncApi {
) -> (Api, Self) {
let (http_api, http_worker) = http::http(shared_client);
let api = Api {
network_provider,
is_validator,
http: http_api,
};
let api = Api { network_provider, is_validator, http: http_api };
let async_api = Self {
http: Some(http_worker),
};
let async_api = Self { http: Some(http_worker) };
(api, async_api)
}
@@ -355,8 +328,11 @@ mod tests {
use super::*;
use sc_client_db::offchain::LocalStorage;
use sc_network::{NetworkStateInfo, PeerId};
use sp_core::offchain::{Externalities, DbExternalities};
use std::{convert::{TryFrom, TryInto}, time::SystemTime};
use sp_core::offchain::{DbExternalities, Externalities};
use std::{
convert::{TryFrom, TryInto},
time::SystemTime,
};
struct TestNetwork();
@@ -385,11 +361,7 @@ mod tests {
let mock = Arc::new(TestNetwork());
let shared_client = SharedClient::new();
AsyncApi::new(
mock,
false,
shared_client,
)
AsyncApi::new(mock, false, shared_client)
}
fn offchain_db() -> Db<LocalStorage> {
@@ -402,7 +374,12 @@ mod tests {
// Get timestamp from std.
let now = SystemTime::now();
let d: u64 = now.duration_since(SystemTime::UNIX_EPOCH).unwrap().as_millis().try_into().unwrap();
let d: u64 = now
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_millis()
.try_into()
.unwrap();
// Get timestamp from offchain api.
let timestamp = api.timestamp();