ghassmo 5 tahun lalu
induk
melakukan
8286356da2
6 mengubah file dengan 14 tambahan dan 24 penghapusan
  1. 1 3
      src/bin/demowallet.rs
  2. 1 1
      src/lib.rs
  3. 0 4
      src/rpc/adapter.rs
  4. 6 3
      src/service/gateway.rs
  5. 5 11
      src/slab.rs
  6. 1 2
      src/slabstore.rs

+ 1 - 3
src/bin/demowallet.rs

@@ -20,10 +20,8 @@ async fn start(executor: Arc<Executor<'_>>) -> Result<()> {
     // TODO sync new slab with slabstore
     let fetch_loop_task = executor.spawn(fetch_slabs_loop(subscriber.clone(), slabs.clone()));
 
-
-
     println!("send put slab");
-    let slab = Slab::new("testcoin".to_string(), vec![0,0,0,0]);
+    let slab = Slab::new("testcoin".to_string(), vec![0, 0, 0, 0]);
     client.put_slab(slab).await?;
 
     // println!("send get slab");

+ 1 - 1
src/lib.rs

@@ -16,8 +16,8 @@ pub mod net;
 pub mod rpc;
 pub mod serial;
 pub mod service;
-pub mod slabstore;
 pub mod slab;
+pub mod slabstore;
 pub mod state;
 pub mod system;
 pub mod tx;

+ 0 - 4
src/rpc/adapter.rs

@@ -1,13 +1,9 @@
 use crate::serial;
-use crate::serial;
-use crate::Result;
 use crate::Result;
 use ff::Field;
 use log::*;
 use rand::rngs::OsRng;
 use rusqlite::Connection;
-use rusqlite::Connection;
-use smol::Async;
 use std::fs::File;
 use std::io::prelude::*;
 use std::sync::Arc;

+ 6 - 3
src/service/gateway.rs

@@ -4,7 +4,9 @@ use std::net::SocketAddr;
 use std::path::Path;
 
 use super::reqrep::{Publisher, RepProtocol, Reply, ReqProtocol, Request, Subscriber};
-use crate::{serial::deserialize, serial::serialize, slabstore::SlabStore, Error, Result, slab::Slab};
+use crate::{
+    serial::deserialize, serial::serialize, slab::Slab, slabstore::SlabStore, Error, Result,
+};
 
 use async_executor::Executor;
 use log::*;
@@ -141,7 +143,7 @@ impl GatewayClient {
         let last_index = self.get_last_index().await?;
 
         if last_index > 0 {
-            for index in (local_last_index + 1)..(last_index + 1){
+            for index in (local_last_index + 1)..(last_index + 1) {
                 self.get_slab(index).await?;
             }
         }
@@ -156,7 +158,8 @@ impl GatewayClient {
     }
 
     pub async fn get_slab(&mut self, index: u64) -> Result<Vec<u8>> {
-        let slab = self.protocol
+        let slab = self
+            .protocol
             .request(GatewayCommand::GetSlab as u8, serialize(&index))
             .await?;
         self.slabstore.put(slab.clone())?;

+ 5 - 11
src/slab.rs

@@ -1,19 +1,16 @@
-
-use crate::Result;
 use crate::serial::{Decodable, Encodable};
+use crate::Result;
 
-pub struct Slab{
+pub struct Slab {
     asset_type: String,
     index: u64,
     payload: Vec<u8>,
 }
 
-
 impl Slab {
-
-    pub fn new(asset_type: String,  payload: Vec<u8>) -> Self{
+    pub fn new(asset_type: String, payload: Vec<u8>) -> Self {
         let index = 0;
-        Slab{
+        Slab {
             asset_type,
             index,
             payload,
@@ -24,7 +21,7 @@ impl Slab {
         self.index = index;
     }
 
-    pub fn get_index(&self) -> u64{
+    pub fn get_index(&self) -> u64 {
         self.index
     }
 
@@ -33,7 +30,6 @@ impl Slab {
     }
 }
 
-
 impl Encodable for Slab {
     fn encode<S: std::io::Write>(&self, mut s: S) -> Result<usize> {
         let mut len = 0;
@@ -53,5 +49,3 @@ impl Decodable for Slab {
         })
     }
 }
-
-

+ 1 - 2
src/slabstore.rs

@@ -14,7 +14,6 @@ pub struct SlabStore {
 
 impl SlabStore {
     pub fn new(path: &Path) -> Result<Self> {
-
         let mut opt = Options::default();
         opt.create_if_missing(true);
 
@@ -37,7 +36,7 @@ impl SlabStore {
         if slab.get_index() == key {
             let key = serialize(&key);
             self.db.put(key, value)?;
-        } 
+        }
         Ok(())
     }