Run RustFmt as part of the CI (#37)

* Run RustFmt as part of the CI

* Format repo

* Run RustFmt before the default Travis build step

Apparently if you override `script` you also need to make
sure to `build` and `test` the code yourself.

* Format repo
This commit is contained in:
Hernando Castano
2020-03-19 13:35:48 -04:00
committed by Bastian Köcher
parent d904a282c8
commit e5f998d7d9
21 changed files with 832 additions and 633 deletions
+44 -82
View File
@@ -30,29 +30,16 @@
// You should have received a copy of the GNU General Public License
// along with Parity-Bridge. If not, see <http://www.gnu.org/licenses/>.
use codec::{Encode, Decode};
use crate::ethereum_sync_loop::MaybeConnectionError;
use crate::ethereum_types::{Bytes, HeaderId as EthereumHeaderId, QueuedHeader as QueuedEthereumHeader, H256};
use crate::substrate_types::{into_substrate_ethereum_header, into_substrate_ethereum_receipts, TransactionHash};
use codec::{Decode, Encode};
use jsonrpsee::common::Params;
use jsonrpsee::raw::{
RawClient, RawClientError
};
use jsonrpsee::transport::http::{
HttpTransportClient, RequestError
};
use jsonrpsee::raw::{RawClient, RawClientError};
use jsonrpsee::transport::http::{HttpTransportClient, RequestError};
use serde_json::{from_value, to_value};
use sp_core::crypto::Pair;
use sp_runtime::traits::IdentifyAccount;
use crate::ethereum_sync_loop::MaybeConnectionError;
use crate::ethereum_types::{
Bytes,
H256,
HeaderId as EthereumHeaderId,
QueuedHeader as QueuedEthereumHeader,
};
use crate::substrate_types::{
TransactionHash,
into_substrate_ethereum_header,
into_substrate_ethereum_receipts,
};
/// Substrate client type.
pub struct Client {
@@ -105,7 +92,8 @@ pub async fn best_ethereum_block(client: Client) -> (Client, Result<EthereumHead
to_value("EthereumHeadersApi_best_block").unwrap(),
to_value("0x").unwrap(),
]),
).await;
)
.await;
(client, result.map(|(num, hash)| EthereumHeaderId(num, hash)))
}
@@ -124,8 +112,12 @@ pub async fn ethereum_receipts_required(
to_value("EthereumHeadersApi_is_import_requires_receipts").unwrap(),
to_value(Bytes(encoded_header)).unwrap(),
]),
).await;
(client, receipts_required.map(|receipts_required| (id, receipts_required)))
)
.await;
(
client,
receipts_required.map(|receipts_required| (id, receipts_required)),
)
}
/// Returns true if Ethereum header is known to Substrate runtime.
@@ -147,7 +139,8 @@ pub async fn ethereum_header_known(
to_value("EthereumHeadersApi_is_known_block").unwrap(),
to_value(Bytes(encoded_id)).unwrap(),
]),
).await;
)
.await;
(client, is_known_block.map(|is_known_block| (id, is_known_block)))
}
@@ -167,7 +160,7 @@ pub async fn submit_ethereum_headers(
};
client.genesis_hash = Some(genesis_hash);
(client, genesis_hash)
},
}
};
let account_id = client.signer.public().as_array_ref().clone().into();
let (client, nonce) = next_account_index(client, account_id).await;
@@ -175,20 +168,14 @@ pub async fn submit_ethereum_headers(
Ok(nonce) => nonce,
Err(err) => return (client, Err(err)),
};
let transaction = create_submit_transaction(
headers,
&client.signer,
nonce,
genesis_hash,
);
let transaction = create_submit_transaction(headers, &client.signer, nonce, genesis_hash);
let encoded_transaction = transaction.encode();
let (client, transaction_hash) = call_rpc(
client,
"author_submitExtrinsic",
Params::Array(vec![
to_value(Bytes(encoded_transaction)).unwrap(),
]),
).await;
Params::Array(vec![to_value(Bytes(encoded_transaction)).unwrap()]),
)
.await;
(client, transaction_hash.map(|transaction_hash| (transaction_hash, ids)))
}
@@ -197,10 +184,9 @@ async fn block_hash_by_number(client: Client, number: u64) -> (Client, Result<H2
call_rpc(
client,
"chain_getBlockHash",
Params::Array(vec![
to_value(number).unwrap(),
]),
).await
Params::Array(vec![to_value(number).unwrap()]),
)
.await
}
/// Get substrate account nonce.
@@ -213,24 +199,15 @@ async fn next_account_index(
let (client, index) = call_rpc_u64(
client,
"system_accountNextIndex",
Params::Array(vec![
to_value(account.to_ss58check()).unwrap(),
]),
).await;
Params::Array(vec![to_value(account.to_ss58check()).unwrap()]),
)
.await;
(client, index.map(|index| index as _))
}
/// Calls RPC on Substrate node that returns Bytes.
async fn call_rpc<T: Decode>(
mut client: Client,
method: &'static str,
params: Params,
) -> (Client, Result<T, Error>) {
async fn do_call_rpc<T: Decode>(
client: &mut Client,
method: &'static str,
params: Params,
) -> Result<T, Error> {
async fn call_rpc<T: Decode>(mut client: Client, method: &'static str, params: Params) -> (Client, Result<T, Error>) {
async fn do_call_rpc<T: Decode>(client: &mut Client, method: &'static str, params: Params) -> Result<T, Error> {
let request_id = client
.rpc_client
.start_request(method, params)
@@ -253,16 +230,8 @@ async fn call_rpc<T: Decode>(
}
/// Calls RPC on Substrate node that returns u64.
async fn call_rpc_u64(
mut client: Client,
method: &'static str,
params: Params,
) -> (Client, Result<u64, Error>) {
async fn do_call_rpc(
client: &mut Client,
method: &'static str,
params: Params,
) -> Result<u64, Error> {
async fn call_rpc_u64(mut client: Client, method: &'static str, params: Params) -> (Client, Result<u64, Error>) {
async fn do_call_rpc(client: &mut Client, method: &'static str, params: Params) -> Result<u64, Error> {
let request_id = client
.rpc_client
.start_request(method, params)
@@ -290,20 +259,18 @@ fn create_submit_transaction(
index: node_primitives::Index,
genesis_hash: H256,
) -> bridge_node_runtime::UncheckedExtrinsic {
let function = bridge_node_runtime::Call::BridgeEthPoA(
bridge_node_runtime::BridgeEthPoACall::import_headers(
headers
.into_iter()
.map(|header| {
let (header, receipts) = header.extract();
(
into_substrate_ethereum_header(&header),
into_substrate_ethereum_receipts(&receipts),
)
})
.collect(),
),
);
let function = bridge_node_runtime::Call::BridgeEthPoA(bridge_node_runtime::BridgeEthPoACall::import_headers(
headers
.into_iter()
.map(|header| {
let (header, receipts) = header.extract();
(
into_substrate_ethereum_header(&header),
into_substrate_ethereum_receipts(&receipts),
)
})
.collect(),
));
let extra = |i: node_primitives::Index, f: node_primitives::Balance| {
(
@@ -331,10 +298,5 @@ fn create_submit_transaction(
let signer: sp_runtime::MultiSigner = signer.public().into();
let (function, extra, _) = raw_payload.deconstruct();
bridge_node_runtime::UncheckedExtrinsic::new_signed(
function,
signer.into_account().into(),
signature.into(),
extra,
)
bridge_node_runtime::UncheckedExtrinsic::new_signed(function, signer.into_account().into(), signature.into(), extra)
}