ghassmo 5 лет назад
Родитель
Сommit
5e0a92599c
8 измененных файлов с 19 добавлено и 52 удалено
  1. 2 2
      src/bin/dfi.rs
  2. 0 34
      src/bin/services.rs
  3. 8 3
      src/bin/tx.rs
  4. 2 1
      src/lib.rs
  5. 2 3
      src/rpc/jsonserver.rs
  6. 1 2
      src/rpc/mod.rs
  7. 1 3
      src/rpc/test.rs
  8. 3 4
      src/tx.rs

+ 2 - 2
src/bin/dfi.rs

@@ -6,13 +6,13 @@ use async_std::sync::Mutex;
 use easy_parallel::Parallel;
 use http_types::{Request, Response, StatusCode};
 use log::*;
+use sapvi::rpc::jsonserver::RpcInterface;
+use sapvi::{net, Result};
 use serde_json::json;
 use smol::Async;
 use std::net::SocketAddr;
 use std::net::TcpListener;
 use std::sync::Arc;
-use sapvi::rpc::jsonserver::RpcInterface;
-use sapvi::{net, Result};
 
 /// Listens for incoming connections and serves them.
 async fn listen(

+ 0 - 34
src/bin/services.rs

@@ -1,34 +0,0 @@
-use async_executor::Executor;
-use easy_parallel::Parallel;
-use std::sync::Arc;
-
-use sapvi::Result;
-
-use sapvi::service::{gateway, reqrep};
-
-async fn start(executor: Arc<Executor<'_>>) -> Result<()> {
-    executor.clone().spawn(reqrep::ReqRepAPI::start()).detach();
-
-    gateway::GatewayService::start(executor.clone()).await;
-    Ok(())
-}
-
-fn main() -> Result<()> {
-    let ex = Arc::new(Executor::new());
-    let (signal, shutdown) = async_channel::unbounded::<()>();
-    let ex2 = ex.clone();
-
-    let (_, result) = Parallel::new()
-        // Run four executor threads.
-        .each(0..3, |_| smol::future::block_on(ex.run(shutdown.recv())))
-        // Run the main future on the current thread.
-        .finish(|| {
-            smol::future::block_on(async move {
-                start(ex2).await?;
-                drop(signal);
-                Ok::<(), sapvi::Error>(())
-            })
-        });
-
-    result
-}

+ 8 - 3
src/bin/tx.rs

@@ -48,7 +48,10 @@ fn main() {
     // Create the deposit for 110 BTC
     // Clear inputs are visible to everyone on the network
     let builder = tx::TransactionBuilder {
-        clear_inputs: vec![tx::TransactionBuilderClearInputInfo { value: 110, signature_secret: cashier_secret }],
+        clear_inputs: vec![tx::TransactionBuilderClearInputInfo {
+            value: 110,
+            signature_secret: cashier_secret,
+        }],
         inputs: vec![],
         outputs: vec![tx::TransactionBuilderOutputInfo { value: 110, public }],
     };
@@ -158,7 +161,10 @@ fn main() {
         }],
         // We can add more outputs to this list.
         // The only constraint is that sum(value in) == sum(value out)
-        outputs: vec![tx::TransactionBuilderOutputInfo { value: 110, public: public2 }],
+        outputs: vec![tx::TransactionBuilderOutputInfo {
+            value: 110,
+            public: public2,
+        }],
     };
     // Build the tx
     let mut tx_data = vec![];
@@ -172,4 +178,3 @@ fn main() {
         assert!(tx.verify(&mint_pvk, &spend_pvk));
     }
 }
-

+ 2 - 1
src/lib.rs

@@ -1,4 +1,5 @@
-#[macro_use] extern crate clap;
+#[macro_use]
+extern crate clap;
 use bellman::groth16;
 use bls12_381::{Bls12, Scalar};
 use std::collections::{HashMap, HashSet};

+ 2 - 3
src/rpc/jsonserver.rs

@@ -1,3 +1,4 @@
+use crate::{net, serial, Error, Result};
 use async_executor::Executor;
 use async_native_tls::TlsAcceptor;
 use async_std::sync::Mutex;
@@ -6,6 +7,7 @@ use ff::Field;
 use http_types::{Request, Response, StatusCode};
 use log::*;
 use rand::rngs::OsRng;
+use rusqlite::Connection;
 use serde_json::json;
 use smol::Async;
 use std::fs::File;
@@ -14,8 +16,6 @@ use std::io::BufReader;
 use std::net::SocketAddr;
 use std::net::TcpListener;
 use std::sync::Arc;
-use rusqlite::Connection;
-use crate::{net, serial, Result, Error};
 
 // json RPC server goes here
 pub struct RpcInterface {
@@ -113,4 +113,3 @@ impl RpcInterface {
         Ok(self.stop_recv.recv().await?)
     }
 }
-

+ 1 - 2
src/rpc/mod.rs

@@ -1,3 +1,2 @@
-pub mod test;
 pub mod jsonserver;
-
+pub mod test;

+ 1 - 3
src/rpc/test.rs

@@ -1,3 +1 @@
-fn foo() {
-}
-
+fn foo() {}

+ 3 - 4
src/tx.rs

@@ -61,7 +61,7 @@ impl TransactionBuilder {
             let clear_input = PartialTransactionClearInput {
                 value: input.value,
                 valcom_blind,
-                signature_public
+                signature_public,
             };
             clear_inputs.push(clear_input);
         }
@@ -288,8 +288,7 @@ impl Transaction {
 
         // Verify signatures
         let mut unsigned_tx_data = vec![];
-        self
-            .encode_without_signature(&mut unsigned_tx_data)
+        self.encode_without_signature(&mut unsigned_tx_data)
             .expect("TODO handle this");
         for input in &self.clear_inputs {
             let public = schnorr::PublicKey(input.signature_public.clone());
@@ -321,7 +320,7 @@ impl TransactionClearInput {
             value: partial.value,
             valcom_blind: partial.valcom_blind,
             signature_public: partial.signature_public,
-            signature
+            signature,
         }
     }