فهرست منبع

Run cargo fmt

Janus 5 سال پیش
والد
کامیت
8da9496f52
6فایلهای تغییر یافته به همراه27 افزوده شده و 34 حذف شده
  1. 1 1
      src/bin/cashierd.rs
  2. 2 5
      src/rpc/adapters/cashier_adapter.rs
  3. 1 2
      src/rpc/adapters/user_adapter.rs
  4. 5 1
      src/rpc/jsonserver.rs
  5. 7 8
      src/service/btc.rs
  6. 11 17
      src/service/cashier.rs

+ 1 - 1
src/bin/cashierd.rs

@@ -7,12 +7,12 @@ use std::{path::Path, path::PathBuf};
 use drk::blockchain::{rocks::columns, Rocks, RocksColumn};
 use drk::blockchain::{rocks::columns, Rocks, RocksColumn};
 use drk::cli::{CashierdCli, CashierdConfig, Config};
 use drk::cli::{CashierdCli, CashierdConfig, Config};
 use drk::rpc::adapters::cashier_adapter::CashierAdapter;
 use drk::rpc::adapters::cashier_adapter::CashierAdapter;
+use drk::rpc::jsonserver;
 use drk::service::CashierService;
 use drk::service::CashierService;
 use drk::service::GatewayClient;
 use drk::service::GatewayClient;
 use drk::util::join_config_path;
 use drk::util::join_config_path;
 use drk::wallet::CashierDb;
 use drk::wallet::CashierDb;
 use drk::{Error, Result};
 use drk::{Error, Result};
-use drk::rpc::jsonserver;
 use log::*;
 use log::*;
 
 
 use async_executor::Executor;
 use async_executor::Executor;

+ 2 - 5
src/rpc/adapters/cashier_adapter.rs

@@ -1,8 +1,7 @@
 use crate::wallet::CashierDb;
 use crate::wallet::CashierDb;
-use crate::{Result};
+use crate::Result;
 use async_std::sync::Arc;
 use async_std::sync::Arc;
 
 
-
 pub struct CashierAdapter {
 pub struct CashierAdapter {
     pub wallet: Arc<CashierDb>,
     pub wallet: Arc<CashierDb>,
 }
 }
@@ -12,9 +11,7 @@ impl CashierAdapter {
         Ok(Self { wallet })
         Ok(Self { wallet })
     }
     }
 
 
-    pub fn handle_input(
-        self: Arc<Self>,
-    ) -> Result<jsonrpc_core::IoHandler> {
+    pub fn handle_input(self: Arc<Self>) -> Result<jsonrpc_core::IoHandler> {
         let mut io = jsonrpc_core::IoHandler::new();
         let mut io = jsonrpc_core::IoHandler::new();
         io.add_sync_method("cashier_hello", |_| {
         io.add_sync_method("cashier_hello", |_| {
             Ok(jsonrpc_core::Value::String("hello world!".into()))
             Ok(jsonrpc_core::Value::String("hello world!".into()))

+ 1 - 2
src/rpc/adapters/user_adapter.rs

@@ -42,8 +42,7 @@ impl UserAdapter {
         })
         })
     }
     }
 
 
-    pub fn handle_input(
-        self: Arc<Self>) -> Result<jsonrpc_core::IoHandler> {
+    pub fn handle_input(self: Arc<Self>) -> Result<jsonrpc_core::IoHandler> {
         let mut io = jsonrpc_core::IoHandler::new();
         let mut io = jsonrpc_core::IoHandler::new();
         io.add_sync_method("say_hello", |_| {
         io.add_sync_method("say_hello", |_| {
             Ok(jsonrpc_core::Value::String("hello world!".into()))
             Ok(jsonrpc_core::Value::String("hello world!".into()))

+ 5 - 1
src/rpc/jsonserver.rs

@@ -115,7 +115,11 @@ impl RpcInterface {
         }))
         }))
     }
     }
 
 
-    pub async fn serve(self: Arc<Self>, mut req: Request, io: Arc<jsonrpc_core::IoHandler>) -> http_types::Result<Response> {
+    pub async fn serve(
+        self: Arc<Self>,
+        mut req: Request,
+        io: Arc<jsonrpc_core::IoHandler>,
+    ) -> http_types::Result<Response> {
         info!("RPC serving {}", req.url());
         info!("RPC serving {}", req.url());
 
 
         let request = req.body_string().await?;
         let request = req.body_string().await?;

+ 7 - 8
src/service/btc.rs

@@ -1,17 +1,17 @@
-use crate::{Result};
+use crate::Result;
 
 
 use rand::distributions::Alphanumeric;
 use rand::distributions::Alphanumeric;
 use rand::{thread_rng, Rng};
 use rand::{thread_rng, Rng};
 
 
-use bitcoin::util::address::Address;
-use bitcoin::util::ecdsa::{PrivateKey, PublicKey};
-use secp256k1::key::SecretKey;
+use async_executor::Executor;
+use async_std::sync::Arc;
 use bitcoin::blockdata::script::Script;
 use bitcoin::blockdata::script::Script;
 use bitcoin::network::constants::Network;
 use bitcoin::network::constants::Network;
-use async_std::sync::Arc;
-use async_executor::Executor;
-use log::*;
+use bitcoin::util::address::Address;
+use bitcoin::util::ecdsa::{PrivateKey, PublicKey};
 use electrum_client::{Client as ElectrumClient, ElectrumApi};
 use electrum_client::{Client as ElectrumClient, ElectrumApi};
+use log::*;
+use secp256k1::key::SecretKey;
 
 
 // Swap out these types for any future non bitcoin-rs types
 // Swap out these types for any future non bitcoin-rs types
 pub type PubAddress = Address;
 pub type PubAddress = Address;
@@ -30,7 +30,6 @@ pub struct BitcoinKeys {
 
 
 impl BitcoinKeys {
 impl BitcoinKeys {
     pub fn new() -> Result<Arc<BitcoinKeys>> {
     pub fn new() -> Result<Arc<BitcoinKeys>> {
-
         // Pull address from config later
         // Pull address from config later
         let client_address = "";
         let client_address = "";
 
 

+ 11 - 17
src/service/cashier.rs

@@ -13,9 +13,9 @@ use bls12_381::Bls12;
 use ff::Field;
 use ff::Field;
 use rand::rngs::OsRng;
 use rand::rngs::OsRng;
 
 
-use electrum_client::{Client as ElectrumClient, ElectrumApi};
-use bitcoin::blockdata::script::Script;
 use async_executor::Executor;
 use async_executor::Executor;
+use bitcoin::blockdata::script::Script;
+use electrum_client::{Client as ElectrumClient, ElectrumApi};
 use log::*;
 use log::*;
 
 
 use async_std::sync::Arc;
 use async_std::sync::Arc;
@@ -82,11 +82,7 @@ impl CashierService {
         let (send, recv) = protocol.start().await?;
         let (send, recv) = protocol.start().await?;
 
 
         let handle_request_task =
         let handle_request_task =
-            executor.spawn(self.handle_request_loop(
-                send.clone(),
-                recv.clone(),
-                executor.clone()
-            ));
+            executor.spawn(self.handle_request_loop(send.clone(), recv.clone(), executor.clone()));
 
 
         protocol.run(executor.clone()).await?;
         protocol.run(executor.clone()).await?;
 
 
@@ -129,15 +125,17 @@ impl CashierService {
 
 
         Ok(())
         Ok(())
     }
     }
-    async fn start_subscribe(self: Arc<Self>, script: Script, executor: Arc<Executor<'_>>) -> Result<()> {
+    async fn start_subscribe(
+        self: Arc<Self>,
+        script: Script,
+        executor: Arc<Executor<'_>>,
+    ) -> Result<()> {
         debug!(target: "BTC", "Subscribe");
         debug!(target: "BTC", "Subscribe");
 
 
         // Check if script is already subscribed
         // Check if script is already subscribed
         let status_start = self.btc_client.script_subscribe(&script).unwrap();
         let status_start = self.btc_client.script_subscribe(&script).unwrap();
         let subscribe_status_task =
         let subscribe_status_task =
-            executor.spawn(
-                self.subscribe_status_loop(status_start, script, executor.clone()),
-            );
+            executor.spawn(self.subscribe_status_loop(status_start, script, executor.clone()));
         debug!(target: "BTC", "Subscribed to scripthash");
         debug!(target: "BTC", "Subscribed to scripthash");
         let _ = subscribe_status_task.cancel().await;
         let _ = subscribe_status_task.cancel().await;
 
 
@@ -154,13 +152,9 @@ impl CashierService {
             let check = self.btc_client.script_pop(&script);
             let check = self.btc_client.script_pop(&script);
             match check {
             match check {
                 // Script has a notification update
                 // Script has a notification update
-                Ok(status) => {
-
-                }
+                Ok(status) => {}
                 // No update, repeat
                 // No update, repeat
-                Err(_) => {
-                    break
-                }
+                Err(_) => break,
             }
             }
         }
         }
         Ok(())
         Ok(())