From 020ced3c5c5e583ea9505d301cbc04b7beb2ce34 Mon Sep 17 00:00:00 2001 From: rachel-rose Date: Wed, 2 Jun 2021 10:30:49 +0200 Subject: [PATCH] cargo fmt --- src/bin/darkfid.rs | 7 +++---- src/lib.rs | 1 + src/rpc/adapter.rs | 8 ++++---- src/rpc/jsonserver.rs | 8 ++++++-- src/service/gateway.rs | 46 +++++++++++++++++++++--------------------- src/service/reqrep.rs | 10 ++++----- 6 files changed, 42 insertions(+), 38 deletions(-) diff --git a/src/bin/darkfid.rs b/src/bin/darkfid.rs index 44c175160..25967ab8a 100644 --- a/src/bin/darkfid.rs +++ b/src/bin/darkfid.rs @@ -62,7 +62,7 @@ fn main() -> Result<()> { std::fs::File::create(options.log_path.as_path()).unwrap(), ), ]) - .unwrap(); + .unwrap(); let ex2 = ex.clone(); @@ -107,7 +107,7 @@ mod test { std::fs::File::create(Path::new("/tmp/dar.log")).unwrap(), ), ]) - .unwrap(); + .unwrap(); let mut thread_pools: Vec> = vec![]; @@ -122,7 +122,7 @@ mod test { "127.0.0.1:3333".parse().unwrap(), Path::new(&format!("slabstore_{}.db", rnd)), ) - .unwrap(); + .unwrap(); // start client client.start().await.unwrap(); @@ -130,7 +130,6 @@ mod test { // sending slab let _slab = Slab::new("testcoin".to_string(), rnd.to_le_bytes().to_vec()); client.put_slab(_slab).await.unwrap(); - }) }); thread_pools.push(thread); diff --git a/src/lib.rs b/src/lib.rs index 574b2d431..d9dfe7ed8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,6 +23,7 @@ pub mod system; pub mod tx; pub mod vm; pub mod vm_serial; +pub mod wallet; pub use crate::bls_extensions::BlsStringConversion; pub use crate::error::{Error, Result}; diff --git a/src/rpc/adapter.rs b/src/rpc/adapter.rs index 142fb398e..5c7481cd8 100644 --- a/src/rpc/adapter.rs +++ b/src/rpc/adapter.rs @@ -47,10 +47,10 @@ impl RpcAdapter { connect.execute( "INSERT INTO keys(key_id, key_private, key_public) VALUES (:id, :privkey, :pubkey)", - named_params!{":id": id, - ":privkey": privkey, - ":pubkey": pubkey - } + named_params! {":id": id, + ":privkey": privkey, + ":pubkey": pubkey + }, )?; Ok(()) } diff --git a/src/rpc/jsonserver.rs b/src/rpc/jsonserver.rs index f1720da85..f04e653dd 100644 --- a/src/rpc/jsonserver.rs +++ b/src/rpc/jsonserver.rs @@ -156,7 +156,9 @@ impl RpcInterface { }); io.add_method("new_wallet", move |_| async move { println!("New wallet method called..."); - RpcAdapter::new_wallet().await.expect("Failed to create wallet."); + RpcAdapter::new_wallet() + .await + .expect("Failed to create wallet."); Ok(jsonrpc_core::Value::Null) }); io.add_method("key_gen", move |_| async move { @@ -168,7 +170,9 @@ impl RpcInterface { }); io.add_method("new_cashier_wallet", move |_| async move { println!("Key generation method called..."); - RpcAdapter::new_cashier_wallet().await.expect("Failed to generate key"); + RpcAdapter::new_cashier_wallet() + .await + .expect("Failed to generate key"); Ok(jsonrpc_core::Value::String( "Tried to create new cashier wallet".into(), )) diff --git a/src/service/gateway.rs b/src/service/gateway.rs index 36b9b7df2..019487d8f 100644 --- a/src/service/gateway.rs +++ b/src/service/gateway.rs @@ -13,7 +13,6 @@ use log::*; pub type Slabs = Vec>; - #[repr(u8)] enum GatewayError { NoError, @@ -35,7 +34,11 @@ pub struct GatewayService { } impl GatewayService { - pub fn new(addr: SocketAddr, pub_addr: SocketAddr, slabstore_path: &Path) -> Result> { + pub fn new( + addr: SocketAddr, + pub_addr: SocketAddr, + slabstore_path: &Path, + ) -> Result> { let slabstore = SlabStore::new(slabstore_path)?; Ok(Arc::new(GatewayService { @@ -54,16 +57,16 @@ impl GatewayService { let (publish_queue, publish_recv_queue) = async_channel::unbounded::>(); let publisher_task = executor.spawn(Self::start_publisher( - self.pub_addr, - service_name, - publish_recv_queue.clone(), + self.pub_addr, + service_name, + publish_recv_queue.clone(), )); let handle_request_task = executor.spawn(self.handle_request_loop( - send.clone(), - recv.clone(), - publish_queue.clone(), - executor.clone(), + send.clone(), + recv.clone(), + publish_queue.clone(), + executor.clone(), )); protocol.run(executor.clone()).await?; @@ -96,13 +99,13 @@ impl GatewayService { let slabstore = self.slabstore.clone(); let _ = executor .spawn(Self::handle_request( - msg, - slabstore, - send_queue.clone(), - publish_queue.clone(), + msg, + slabstore, + send_queue.clone(), + publish_queue.clone(), )) .detach(); - } + } Err(_) => { break; } @@ -130,7 +133,6 @@ impl GatewayService { let mut reply = Reply::from(&request, GatewayError::NoError as u32, vec![]); - if let None = error { reply.set_error(GatewayError::UpdateIndex as u32); } @@ -209,7 +211,7 @@ impl GatewayClient { assert!(last_index >= local_last_index); - if last_index > 0 { + if last_index > 0 { for index in (local_last_index + 1)..(last_index + 1) { if let None = self.get_slab(index).await? { warn!("Index not exist"); @@ -218,11 +220,8 @@ impl GatewayClient { } } - - info!("End Syncing"); Ok(last_index) - } pub async fn get_slab(&mut self, index: u64) -> Result>> { @@ -231,7 +230,7 @@ impl GatewayClient { .request(GatewayCommand::GetSlab as u8, serialize(&index)) .await?; - if let Some(slab) = rep{ + if let Some(slab) = rep { self.slabstore.put(slab.clone())?; return Ok(Some(slab)); } @@ -239,16 +238,17 @@ impl GatewayClient { } pub async fn put_slab(&mut self, mut slab: Slab) -> Result<()> { - loop{ + loop { let last_index = self.sync().await?; slab.set_index(last_index + 1); let slab = serialize(&slab); - let rep = self.protocol + let rep = self + .protocol .request(GatewayCommand::PutSlab as u8, slab.clone()) .await?; - if let Some(_) = rep{ + if let Some(_) = rep { break; } } diff --git a/src/service/reqrep.rs b/src/service/reqrep.rs index 49287d8aa..a507b21fb 100644 --- a/src/service/reqrep.rs +++ b/src/service/reqrep.rs @@ -14,7 +14,7 @@ use rand::Rng; use signal_hook::{consts::SIGINT, iterator::Signals}; use zeromq::*; -pub type PeerId = Vec; +pub type PeerId = Vec; enum NetEvent { Receive(zeromq::ZmqMessage), @@ -59,8 +59,8 @@ impl RepProtocol { pub async fn start( &mut self, ) -> Result<( - async_channel::Sender<(PeerId, Reply)>, - async_channel::Receiver<(PeerId, Request)>, + async_channel::Sender<(PeerId, Reply)>, + async_channel::Receiver<(PeerId, Request)>, )> { let addr = addr_to_string(self.addr); self.socket.bind(addr.as_str()).await?; @@ -179,7 +179,7 @@ impl ReqProtocol { Ok(Some(reply.get_payload())) } else { Err(crate::Error::ZMQError( - "Couldn't parse ZmqMessage".to_string(), + "Couldn't parse ZmqMessage".to_string(), )) } } @@ -257,7 +257,7 @@ impl Subscriber { Ok(data) } None => Err(crate::Error::ZMQError( - "Couldn't parse ZmqMessage".to_string(), + "Couldn't parse ZmqMessage".to_string(), )), } }