Skip to content

Commit 0f89f16

Browse files
committed
add rustfmt rules
1 parent 3b0d405 commit 0f89f16

File tree

16 files changed

+327
-109
lines changed

16 files changed

+327
-109
lines changed

archive/src/lib.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,21 @@ impl<
3232
})
3333
}
3434

35-
pub fn get_header(&self, txn: &RoTxn, height: u32) -> Result<Option<Header>, Error> {
35+
pub fn get_header(
36+
&self,
37+
txn: &RoTxn,
38+
height: u32,
39+
) -> Result<Option<Header>, Error> {
3640
let height = height.to_be_bytes();
3741
let header = self.headers.get(txn, &height)?;
3842
Ok(header)
3943
}
4044

41-
pub fn get_body(&self, txn: &RoTxn, height: u32) -> Result<Option<Body<A, C>>, Error> {
45+
pub fn get_body(
46+
&self,
47+
txn: &RoTxn,
48+
height: u32,
49+
) -> Result<Option<Body<A, C>>, Error> {
4250
let height = height.to_be_bytes();
4351
let header = self.bodies.get(txn, &height)?;
4452
Ok(header)
@@ -78,7 +86,11 @@ impl<
7886
Ok(())
7987
}
8088

81-
pub fn append_header(&self, txn: &mut RwTxn, header: &Header) -> Result<(), Error> {
89+
pub fn append_header(
90+
&self,
91+
txn: &mut RwTxn,
92+
header: &Header,
93+
) -> Result<(), Error> {
8294
let height = self.get_height(txn)?;
8395
let best_hash = self.get_best_hash(txn)?;
8496
if header.prev_side_hash != best_hash {

authorization/src/lib.rs

+33-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
pub use ed25519_dalek::{Keypair, PublicKey, Signature, SignatureError, Signer, Verifier};
1+
pub use ed25519_dalek::{
2+
Keypair, PublicKey, Signature, SignatureError, Signer, Verifier,
3+
};
24
use plain_types::blake3;
3-
use plain_types::{Address, AuthorizedTransaction, Body, GetAddress, Transaction, Verify};
5+
use plain_types::{
6+
Address, AuthorizedTransaction, Body, GetAddress, Transaction, Verify,
7+
};
48
use rayon::prelude::*;
59
use serde::{Deserialize, Serialize};
610

@@ -16,9 +20,13 @@ impl GetAddress for Authorization {
1620
}
1721
}
1822

19-
impl<C: Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync> Verify<C> for Authorization {
23+
impl<C: Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync> Verify<C>
24+
for Authorization
25+
{
2026
type Error = Error;
21-
fn verify_transaction(transaction: &AuthorizedTransaction<Self, C>) -> Result<(), Self::Error>
27+
fn verify_transaction(
28+
transaction: &AuthorizedTransaction<Self, C>,
29+
) -> Result<(), Self::Error>
2230
where
2331
Self: Sized,
2432
{
@@ -56,16 +64,17 @@ pub fn verify_authorized_transaction<C: Clone + Serialize + Sync>(
5664
let messages: Vec<_> = std::iter::repeat(serialized_transaction.as_slice())
5765
.take(transaction.authorizations.len())
5866
.collect();
59-
let (public_keys, signatures): (Vec<PublicKey>, Vec<Signature>) = transaction
60-
.authorizations
61-
.iter()
62-
.map(
63-
|Authorization {
64-
public_key,
65-
signature,
66-
}| (public_key, signature),
67-
)
68-
.unzip();
67+
let (public_keys, signatures): (Vec<PublicKey>, Vec<Signature>) =
68+
transaction
69+
.authorizations
70+
.iter()
71+
.map(
72+
|Authorization {
73+
public_key,
74+
signature,
75+
}| (public_key, signature),
76+
)
77+
.unzip();
6978
ed25519_dalek::verify_batch(&messages, &signatures, &public_keys)?;
7079
Ok(())
7180
}
@@ -82,7 +91,8 @@ pub fn verify_authorizations<C: Clone + Serialize + Sync>(
8291
.par_iter()
8392
.map(bincode::serialize)
8493
.collect::<Result<_, _>>()?;
85-
let serialized_transactions = serialized_transactions.iter().map(Vec::as_slice);
94+
let serialized_transactions =
95+
serialized_transactions.iter().map(Vec::as_slice);
8696
let messages = input_numbers.zip(serialized_transactions).flat_map(
8797
|(input_number, serialized_transaction)| {
8898
std::iter::repeat(serialized_transaction).take(input_number)
@@ -101,7 +111,9 @@ pub fn verify_authorizations<C: Clone + Serialize + Sync>(
101111
signatures: Vec::with_capacity(package_size),
102112
public_keys: Vec::with_capacity(package_size),
103113
};
104-
for (authorization, message) in &pairs[i * package_size..(i + 1) * package_size] {
114+
for (authorization, message) in
115+
&pairs[i * package_size..(i + 1) * package_size]
116+
{
105117
package.messages.push(*message);
106118
package.signatures.push(authorization.signature);
107119
package.public_keys.push(authorization.public_key);
@@ -128,7 +140,9 @@ pub fn verify_authorizations<C: Clone + Serialize + Sync>(
128140
messages,
129141
signatures,
130142
public_keys,
131-
}| ed25519_dalek::verify_batch(messages, signatures, public_keys),
143+
}| {
144+
ed25519_dalek::verify_batch(messages, signatures, public_keys)
145+
},
132146
)
133147
.collect::<Result<(), SignatureError>>()?;
134148
Ok(())
@@ -146,7 +160,8 @@ pub fn authorize<C: Clone + Serialize>(
146160
addresses_keypairs: &[(Address, &Keypair)],
147161
transaction: Transaction<C>,
148162
) -> Result<AuthorizedTransaction<Authorization, C>, Error> {
149-
let mut authorizations: Vec<Authorization> = Vec::with_capacity(addresses_keypairs.len());
163+
let mut authorizations: Vec<Authorization> =
164+
Vec::with_capacity(addresses_keypairs.len());
150165
let message = bincode::serialize(&transaction)?;
151166
for (address, keypair) in addresses_keypairs {
152167
let hash_public_key = get_address(&keypair.public);

drivechain/src/client.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,19 @@ pub trait Main {
7575
nsidechain: u32,
7676
) -> Result<Vec<WithdrawalStatus>, jsonrpsee::core::Error>;
7777
#[method(name = "listspentwithdrawals")]
78-
async fn listspentwithdrawals(&self) -> Result<Vec<SpentWithdrawal>, jsonrpsee::core::Error>;
78+
async fn listspentwithdrawals(
79+
&self,
80+
) -> Result<Vec<SpentWithdrawal>, jsonrpsee::core::Error>;
7981
#[method(name = "listfailedwithdrawals")]
80-
async fn listfailedwithdrawals(&self) -> Result<Vec<FailedWithdrawal>, jsonrpsee::core::Error>;
82+
async fn listfailedwithdrawals(
83+
&self,
84+
) -> Result<Vec<FailedWithdrawal>, jsonrpsee::core::Error>;
8185
#[method(name = "getblockcount")]
8286
async fn getblockcount(&self) -> Result<usize, jsonrpsee::core::Error>;
8387
#[method(name = "getbestblockhash")]
84-
async fn getbestblockhash(&self) -> Result<bitcoin::BlockHash, jsonrpsee::core::Error>;
88+
async fn getbestblockhash(
89+
&self,
90+
) -> Result<bitcoin::BlockHash, jsonrpsee::core::Error>;
8591
#[method(name = "getblock")]
8692
async fn getblock(
8793
&self,
@@ -122,14 +128,20 @@ pub trait Main {
122128
) -> Result<serde_json::Value, jsonrpsee::core::Error>;
123129

124130
#[method(name = "generate")]
125-
async fn generate(&self, num: u32) -> Result<serde_json::Value, jsonrpsee::core::Error>;
131+
async fn generate(
132+
&self,
133+
num: u32,
134+
) -> Result<serde_json::Value, jsonrpsee::core::Error>;
126135

127136
#[method(name = "getnewaddress")]
128137
async fn getnewaddress(
129138
&self,
130139
account: &str,
131140
address_type: &str,
132-
) -> Result<bitcoin::Address<bitcoin::address::NetworkUnchecked>, jsonrpsee::core::Error>;
141+
) -> Result<
142+
bitcoin::Address<bitcoin::address::NetworkUnchecked>,
143+
jsonrpsee::core::Error,
144+
>;
133145

134146
#[method(name = "createsidechaindeposit")]
135147
async fn createsidechaindeposit(

drivechain/src/lib.rs

+22-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ impl<C> Drivechain<C> {
2323
.nextblockhash
2424
.ok_or(Error::NoNextBlock { prev_main_hash })?;
2525
self.client
26-
.verifybmm(&block_hash, &header.hash().into(), self.sidechain_number)
26+
.verifybmm(
27+
&block_hash,
28+
&header.hash().into(),
29+
self.sidechain_number,
30+
)
2731
.await?;
2832
Ok(())
2933
}
@@ -37,7 +41,8 @@ impl<C> Drivechain<C> {
3741
end: bitcoin::BlockHash,
3842
start: Option<bitcoin::BlockHash>,
3943
) -> Result<TwoWayPegData<C>, Error> {
40-
let (deposits, deposit_block_hash) = self.get_deposit_outputs(end, start).await?;
44+
let (deposits, deposit_block_hash) =
45+
self.get_deposit_outputs(end, start).await?;
4146
let bundle_statuses = self.get_withdrawal_bundle_statuses().await?;
4247
let two_way_peg_data = TwoWayPegData {
4348
deposits,
@@ -64,19 +69,25 @@ impl<C> Drivechain<C> {
6469
&self,
6570
end: bitcoin::BlockHash,
6671
start: Option<bitcoin::BlockHash>,
67-
) -> Result<(HashMap<OutPoint, Output<C>>, Option<bitcoin::BlockHash>), Error> {
72+
) -> Result<(HashMap<OutPoint, Output<C>>, Option<bitcoin::BlockHash>), Error>
73+
{
6874
let deposits = self
6975
.client
70-
.listsidechaindepositsbyblock(self.sidechain_number, Some(end), start)
76+
.listsidechaindepositsbyblock(
77+
self.sidechain_number,
78+
Some(end),
79+
start,
80+
)
7181
.await?;
7282
let mut last_block_hash = None;
7383
let mut last_total = 0;
7484
let mut outputs = HashMap::new();
7585
dbg!(last_total);
7686
for deposit in &deposits {
7787
let transaction = hex::decode(&deposit.txhex)?;
78-
let transaction =
79-
bitcoin::Transaction::consensus_decode(&mut std::io::Cursor::new(transaction))?;
88+
let transaction = bitcoin::Transaction::consensus_decode(
89+
&mut std::io::Cursor::new(transaction),
90+
)?;
8091
if let Some(start) = start {
8192
if deposit.hashblock == start {
8293
last_total = transaction.output[deposit.nburnindex].value;
@@ -126,7 +137,11 @@ impl<C> Drivechain<C> {
126137
Ok(statuses)
127138
}
128139

129-
pub fn new(sidechain_number: u32, host: &str, port: u32) -> Result<Self, Error> {
140+
pub fn new(
141+
sidechain_number: u32,
142+
host: &str,
143+
port: u32,
144+
) -> Result<Self, Error> {
130145
let mut headers = HeaderMap::new();
131146
let auth = format!("{}:{}", "user", "password");
132147
let header_value = format!(

mempool/src/lib.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ use serde::{Deserialize, Serialize};
55

66
#[derive(Clone)]
77
pub struct MemPool<A, C> {
8-
pub transactions: Database<OwnedType<[u8; 32]>, SerdeBincode<AuthorizedTransaction<A, C>>>,
8+
pub transactions: Database<
9+
OwnedType<[u8; 32]>,
10+
SerdeBincode<AuthorizedTransaction<A, C>>,
11+
>,
912
pub spent_utxos: Database<SerdeBincode<OutPoint>, Unit>,
1013
}
1114

@@ -40,8 +43,11 @@ impl<
4043
}
4144
self.spent_utxos.put(txn, input, &())?;
4245
}
43-
self.transactions
44-
.put(txn, &transaction.transaction.txid().into(), &transaction)?;
46+
self.transactions.put(
47+
txn,
48+
&transaction.transaction.txid().into(),
49+
&transaction,
50+
)?;
4551
Ok(())
4652
}
4753

miner/src/lib.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ pub struct Miner<A, C> {
1414
}
1515

1616
impl<A: Clone, C: Clone + GetValue + Serialize> Miner<A, C> {
17-
pub fn new(sidechain_number: u32, host: &str, port: u32) -> Result<Self, Error> {
17+
pub fn new(
18+
sidechain_number: u32,
19+
host: &str,
20+
port: u32,
21+
) -> Result<Self, Error> {
1822
let drivechain = Drivechain::new(sidechain_number, host, port)?;
1923
Ok(Self {
2024
drivechain,
@@ -54,14 +58,18 @@ impl<A: Clone, C: Clone + GetValue + Serialize> Miner<A, C> {
5458
)
5559
.await
5660
.map_err(plain_drivechain::Error::from)?;
57-
bitcoin::Txid::from_str(value["txid"]["txid"].as_str().ok_or(Error::InvalidJson)?)
58-
.map_err(plain_drivechain::Error::from)?;
61+
bitcoin::Txid::from_str(
62+
value["txid"]["txid"].as_str().ok_or(Error::InvalidJson)?,
63+
)
64+
.map_err(plain_drivechain::Error::from)?;
5965
assert_eq!(header.merkle_root, body.compute_merkle_root());
6066
self.block = Some((header, body));
6167
Ok(())
6268
}
6369

64-
pub async fn confirm_bmm(&mut self) -> Result<Option<(Header, Body<A, C>)>, Error> {
70+
pub async fn confirm_bmm(
71+
&mut self,
72+
) -> Result<Option<(Header, Body<A, C>)>, Error> {
6573
if let Some((header, body)) = self.block.clone() {
6674
self.drivechain.verify_bmm(&header).await?;
6775
self.block = None;

net/src/lib.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ impl Net {
118118
Ok(peer)
119119
}
120120

121-
pub async fn disconnect(&self, stable_id: usize) -> Result<Option<Peer>, Error> {
121+
pub async fn disconnect(
122+
&self,
123+
stable_id: usize,
124+
) -> Result<Option<Peer>, Error> {
122125
let peer = self.peers.write().await.remove(&stable_id);
123126
Ok(peer)
124127
}
@@ -140,7 +143,9 @@ pub fn make_client_endpoint(bind_addr: SocketAddr) -> Result<Endpoint, Error> {
140143
/// - a stream of incoming QUIC connections
141144
/// - server certificate serialized into DER format
142145
#[allow(unused)]
143-
pub fn make_server_endpoint(bind_addr: SocketAddr) -> Result<(Endpoint, Vec<u8>), Error> {
146+
pub fn make_server_endpoint(
147+
bind_addr: SocketAddr,
148+
) -> Result<(Endpoint, Vec<u8>), Error> {
144149
let (server_config, server_cert) = configure_server()?;
145150
let endpoint = Endpoint::server(server_config, bind_addr)?;
146151
Ok((endpoint, server_cert))
@@ -154,7 +159,8 @@ fn configure_server() -> Result<(ServerConfig, Vec<u8>), Error> {
154159
let priv_key = rustls::PrivateKey(priv_key);
155160
let cert_chain = vec![rustls::Certificate(cert_der.clone())];
156161

157-
let mut server_config = ServerConfig::with_single_cert(cert_chain, priv_key)?;
162+
let mut server_config =
163+
ServerConfig::with_single_cert(cert_chain, priv_key)?;
158164
let transport_config = Arc::get_mut(&mut server_config.transport).unwrap();
159165
transport_config.max_concurrent_uni_streams(1_u8.into());
160166

0 commit comments

Comments
 (0)