cargo fmt

This commit is contained in:
rachel-rose
2021-06-02 10:30:49 +02:00
parent 40a342696a
commit 020ced3c5c
6 changed files with 42 additions and 38 deletions

View File

@@ -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<std::thread::JoinHandle<()>> = 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);

View File

@@ -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};

View File

@@ -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(())
}

View File

@@ -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(),
))

View File

@@ -13,7 +13,6 @@ use log::*;
pub type Slabs = Vec<Vec<u8>>;
#[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<Arc<GatewayService>> {
pub fn new(
addr: SocketAddr,
pub_addr: SocketAddr,
slabstore_path: &Path,
) -> Result<Arc<GatewayService>> {
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::<Vec<u8>>();
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<Option<Vec<u8>>> {
@@ -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;
}
}

View File

@@ -14,7 +14,7 @@ use rand::Rng;
use signal_hook::{consts::SIGINT, iterator::Signals};
use zeromq::*;
pub type PeerId = Vec<u8>;
pub type PeerId = Vec<u8>;
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(),
)),
}
}