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

bin/darkfid2: Add protocol as comments.

parazyd 4 лет назад
Родитель
Сommit
017b5f94df
1 измененных файлов с 18 добавлено и 0 удалено
  1. 18 0
      src/bin/darkfid2.rs

+ 18 - 0
src/bin/darkfid2.rs

@@ -106,10 +106,14 @@ impl Darkfid {
         ));
         ));
     }
     }
 
 
+    // --> {"method": "say_hello", "params": []}
+    // <-- {"result": "hello world"}
     async fn say_hello(self, id: Value, _params: Value) -> JsonResult {
     async fn say_hello(self, id: Value, _params: Value) -> JsonResult {
         JsonResult::Resp(jsonrpc::response(json!("hello world"), id))
         JsonResult::Resp(jsonrpc::response(json!("hello world"), id))
     }
     }
 
 
+    // --> {"method": "create_wallet", "params": []}
+    // <-- {"result": true}
     async fn create_wallet(self, id: Value, _params: Value) -> JsonResult {
     async fn create_wallet(self, id: Value, _params: Value) -> JsonResult {
         match self.wallet.init_db() {
         match self.wallet.init_db() {
             Ok(()) => return JsonResult::Resp(jsonrpc::response(json!(true), id)),
             Ok(()) => return JsonResult::Resp(jsonrpc::response(json!(true), id)),
@@ -117,6 +121,8 @@ impl Darkfid {
         }
         }
     }
     }
 
 
+    // --> {"method": "key_gen", "params": []}
+    // <-- {"result": true}
     async fn key_gen(self, id: Value, _params: Value) -> JsonResult {
     async fn key_gen(self, id: Value, _params: Value) -> JsonResult {
         match self.wallet.key_gen() {
         match self.wallet.key_gen() {
             Ok((_, _)) => return JsonResult::Resp(jsonrpc::response(json!(true), id)),
             Ok((_, _)) => return JsonResult::Resp(jsonrpc::response(json!(true), id)),
@@ -124,6 +130,8 @@ impl Darkfid {
         }
         }
     }
     }
 
 
+    // --> {"method": "get_key", "params": []}
+    // <-- {"result": "vdNS7oBj7KvsMWWmo9r96SV4SqATLrGsH2a3PGpCfJC"}
     async fn get_key(self, id: Value, _params: Value) -> JsonResult {
     async fn get_key(self, id: Value, _params: Value) -> JsonResult {
         match self.wallet.get_keypairs() {
         match self.wallet.get_keypairs() {
             Ok(v) => {
             Ok(v) => {
@@ -140,6 +148,7 @@ impl Darkfid {
     //      "id": 42}
     //      "id": 42}
     // The publickey sent here is used so the cashier can know where to send
     // The publickey sent here is used so the cashier can know where to send
     // assets once the deposit is received.
     // assets once the deposit is received.
+    // <-- {"result": "Ht5G1RhkcKnpLVLMhqJc5aqZ4wYUEbxbtZwGCVbgU7DL"}
     async fn deposit(self, id: Value, params: Value) -> JsonResult {
     async fn deposit(self, id: Value, params: Value) -> JsonResult {
         let args = params.as_array().unwrap();
         let args = params.as_array().unwrap();
         if args.len() != 2 {
         if args.len() != 2 {
@@ -182,6 +191,13 @@ impl Darkfid {
         }
         }
     }
     }
 
 
+    // --> {"method": "withdraw", "params": [network, token, publickey, amount]}
+    // The publickey sent here is the address where the caller wants to receive
+    // the tokens they plan to withdraw.
+    // On request, send request to cashier to get deposit address, and then transfer
+    // dark assets to the cashier's wallet. Following that, the cashier should return
+    // a transaction ID of them sending the funds that are requested for withdrawal.
+    // <-- {"result": "txID"}
     async fn withdraw(self, id: Value, params: Value) -> JsonResult {
     async fn withdraw(self, id: Value, params: Value) -> JsonResult {
         let args = params.as_array().unwrap();
         let args = params.as_array().unwrap();
         if args.len() != 4 {
         if args.len() != 4 {
@@ -201,6 +217,8 @@ impl Darkfid {
         return JsonResult::Err(jsonrpc::error(-69, "failed to withdraw".to_string(), id));
         return JsonResult::Err(jsonrpc::error(-69, "failed to withdraw".to_string(), id));
     }
     }
 
 
+    // --> {"method": "transfer", [dToken, address, amount]}
+    // <-- {"result": "txID"}
     async fn transfer(self, id: Value, _params: Value) -> JsonResult {
     async fn transfer(self, id: Value, _params: Value) -> JsonResult {
         return JsonResult::Err(jsonrpc::error(-69, "failed to transfer".to_string(), id));
         return JsonResult::Err(jsonrpc::error(-69, "failed to transfer".to_string(), id));
     }
     }