瀏覽代碼

lilith: remobed dummy subscriber

aggstam 3 年之前
父節點
當前提交
d10437425a
共有 1 個文件被更改,包括 2 次插入39 次删除
  1. 2 39
      bin/lilith/src/main.rs

+ 2 - 39
bin/lilith/src/main.rs

@@ -34,13 +34,11 @@ use darkfi::{
     rpc::{
         jsonrpc::{
             ErrorCode::{InvalidParams, MethodNotFound},
-            JsonError, JsonNotification, JsonRequest, JsonResponse, JsonResult, JsonSubscriber,
+            JsonError, JsonRequest, JsonResponse, JsonResult,
         },
         server::{listen_and_serve, RequestHandler},
     },
-    system::{Subscriber, SubscriberPtr},
     util::{
-        async_util::sleep,
         file::{load_file, save_file},
         path::{expand_path, get_config_path},
     },
@@ -85,8 +83,6 @@ struct Lilith {
     urls: Vec<Url>,
     /// Spawned networks
     spawns: Vec<Spawn>,
-    // TODO: Subscriber should come from ValidatorState or something
-    subscriber: SubscriberPtr<JsonNotification>,
 }
 
 impl Lilith {
@@ -132,30 +128,6 @@ impl Lilith {
     async fn pong(&self, id: Value, _params: &[Value]) -> JsonResult {
         JsonResponse::new(json!("pong"), id).into()
     }
-
-    // RPCAPI:
-    // Create a new subscriber for new blocks to notify connected peer.
-    //
-    // --> {"jsonrpc": "2.0", "method": "blockchain.notify_blocks", "params": [], "id": 1}
-    // <-- {"jsonrpc": "2.0", "result": {...}, "id": 1}
-    pub async fn blockchain_notify_blocks(&self, id: Value, params: &[Value]) -> JsonResult {
-        if !params.is_empty() {
-            return JsonError::new(InvalidParams, None, id).into()
-        }
-
-        JsonSubscriber::new(self.subscriber.clone()).into()
-    }
-}
-
-// TODO: remove this
-async fn simulate_blocks(subscriber: SubscriberPtr<JsonNotification>) {
-    // Notifications simulation
-    let message =
-        JsonNotification::new("blockchain.notify_blocks", Value::from("New Block created!"));
-    loop {
-        subscriber.notify(message.clone()).await;
-        sleep(10).await;
-    }
 }
 
 #[async_trait]
@@ -170,9 +142,6 @@ impl RequestHandler for Lilith {
         match req.method.as_str() {
             Some("spawns") => return self.spawns(req.id, params).await,
             Some("ping") => return self.pong(req.id, params).await,
-            Some("blockchain.notify_blocks") => {
-                return self.blockchain_notify_blocks(req.id, params).await
-            }
             Some(_) | None => return JsonError::new(MethodNotFound, None, req.id).into(),
         }
     }
@@ -336,10 +305,7 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'_>>) -> Result<()> {
         }
     }
 
-    // TODO: Subscriber should come from ValidatorState or something
-    let subscriber: SubscriberPtr<JsonNotification> = Subscriber::new();
-
-    let lilith = Lilith { urls, spawns, subscriber: subscriber.clone() };
+    let lilith = Lilith { urls, spawns };
     let lilith = Arc::new(lilith);
 
     // JSON-RPC server
@@ -347,9 +313,6 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'_>>) -> Result<()> {
     let _ex = ex.clone();
     ex.spawn(listen_and_serve(args.rpc_listen, lilith.clone(), _ex)).detach();
 
-    // JSON-RPC notifications simulation
-    ex.spawn(simulate_blocks(subscriber)).detach();
-
     // Wait for SIGINT
     shutdown.recv().await?;
     print!("\r");