Просмотр исходного кода

rpc: Have JSON notifications take JsonValue as params.

This outsources encoding/serialization to the caller.
parazyd 3 лет назад
Родитель
Сommit
d3f3ac8737
1 измененных файлов с 2 добавлено и 12 удалено
  1. 2 12
      src/rpc/jsonrpc.rs

+ 2 - 12
src/rpc/jsonrpc.rs

@@ -19,14 +19,12 @@
 //! JSON-RPC 2.0 object definitions
 //! JSON-RPC 2.0 object definitions
 use std::collections::HashMap;
 use std::collections::HashMap;
 
 
-use darkfi_serial::{serialize, Encodable};
 use rand::{rngs::OsRng, Rng};
 use rand::{rngs::OsRng, Rng};
 use tinyjson::JsonValue;
 use tinyjson::JsonValue;
 
 
 use crate::{
 use crate::{
     error::RpcError,
     error::RpcError,
     system::{Subscriber, SubscriberPtr},
     system::{Subscriber, SubscriberPtr},
-    util::encoding::base64,
     Result,
     Result,
 };
 };
 
 
@@ -488,16 +486,8 @@ impl JsonSubscriber {
         Self { method, sub }
         Self { method, sub }
     }
     }
 
 
-    /// Send a notification to the subscriber with the given params.
-    /// All the params will be serialized and then encoded with base64 encoding.
-    pub async fn notify<T: Encodable>(&self, raw_params: &[T]) {
-        let mut params = vec![];
-
-        // Serialize and encode all params
-        for raw_param in raw_params {
-            params.push(JsonValue::String(base64::encode(&serialize(raw_param))));
-        }
-
+    /// Send a notification to the subscriber with the given JSON object
+    pub async fn notify(&self, params: Vec<JsonValue>) {
         let notification = JsonNotification::new(self.method, JsonValue::Array(params));
         let notification = JsonNotification::new(self.method, JsonValue::Array(params));
         self.sub.notify(notification).await;
         self.sub.notify(notification).await;
     }
     }