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

darkfid: Prepend respective sections to all RPC function names.

Luther Blissett 3 лет назад
Родитель
Сommit
c3ba6e6771

+ 44 - 15
bin/darkfid/src/main.rs

@@ -182,23 +182,52 @@ impl RequestHandler for Darkfid {
         let params = req.params.as_array().unwrap();
 
         match req.method.as_str() {
-            Some("ping") => return self.pong(req.id, params).await,
-            Some("clock") => return self.clock(req.id, params).await,
-            Some("blockchain.get_slot") => return self.get_slot(req.id, params).await,
-            Some("blockchain.merkle_roots") => return self.merkle_roots(req.id, params).await,
-            Some("tx.transfer") => return self.transfer(req.id, params).await,
-            Some("tx.broadcast") => return self.broadcast(req.id, params).await,
-            Some("wallet.keygen") => return self.keygen(req.id, params).await,
-            Some("wallet.get_addrs") => return self.get_addrs(req.id, params).await,
-            Some("wallet.export_keypair") => return self.export_keypair(req.id, params).await,
-            Some("wallet.import_keypair") => return self.import_keypair(req.id, params).await,
+            // =====================
+            // Miscellaneous methods
+            // =====================
+            Some("ping") => return self.misc_pong(req.id, params).await,
+            Some("clock") => return self.misc_clock(req.id, params).await,
+
+            // ==================
+            // Blockchain methods
+            // ==================
+            Some("blockchain.get_slot") => return self.blockchain_get_slot(req.id, params).await,
+            Some("blockchain.merkle_roots") => {
+                return self.blockchain_merkle_roots(req.id, params).await
+            }
+
+            // ===================
+            // Transaction methods
+            // ===================
+            Some("tx.transfer") => return self.tx_transfer(req.id, params).await,
+            Some("tx.broadcast") => return self.tx_broadcast(req.id, params).await,
+
+            // ==============
+            // Wallet methods
+            // ==============
+            Some("wallet.keygen") => return self.wallet_keygen(req.id, params).await,
+            Some("wallet.get_addrs") => return self.wallet_get_addrs(req.id, params).await,
+            Some("wallet.export_keypair") => {
+                return self.wallet_export_keypair(req.id, params).await
+            }
+            Some("wallet.import_keypair") => {
+                return self.wallet_import_keypair(req.id, params).await
+            }
             Some("wallet.set_default_address") => {
-                return self.set_default_address(req.id, params).await
+                return self.wallet_set_default_address(req.id, params).await
             }
-            Some("wallet.get_balances") => return self.get_balances(req.id, params).await,
-            Some("wallet.get_coins_valtok") => return self.get_coins_valtok(req.id, params).await,
-            Some("wallet.get_merkle_path") => return self.get_merkle_path(req.id, params).await,
-            Some("wallet.decrypt_note") => return self.decrypt_note(req.id, params).await,
+            Some("wallet.get_balances") => return self.wallet_get_balances(req.id, params).await,
+            Some("wallet.get_coins_valtok") => {
+                return self.wallet_get_coins_valtok(req.id, params).await
+            }
+            Some("wallet.get_merkle_path") => {
+                return self.wallet_get_merkle_path(req.id, params).await
+            }
+            Some("wallet.decrypt_note") => return self.wallet_decrypt_note(req.id, params).await,
+
+            // ==============
+            // Invalid method
+            // ==============
             Some(_) | None => return JsonError::new(MethodNotFound, None, req.id).into(),
         }
     }

+ 2 - 2
bin/darkfid/src/rpc_blockchain.rs

@@ -18,7 +18,7 @@ impl Darkfid {
     // Returns a readable block upon success.
     // --> {"jsonrpc": "2.0", "method": "blockchain.get_slot", "params": [0], "id": 1}
     // <-- {"jsonrpc": "2.0", "result": {...}, "id": 1}
-    pub async fn get_slot(&self, id: Value, params: &[Value]) -> JsonResult {
+    pub async fn blockchain_get_slot(&self, id: Value, params: &[Value]) -> JsonResult {
         if params.len() != 1 || !params[0].is_u64() {
             return JsonError::new(InvalidParams, None, id).into()
         }
@@ -50,7 +50,7 @@ impl Darkfid {
     // Queries the blockchain database for all available merkle roots.
     // --> {"jsonrpc": "2.0", "method": "blockchain.merkle_roots", "params": [], "id": 1}
     // <-- {"jsonrpc": "2.0", "result": [..., ..., ...], "id": 1}
-    pub async fn merkle_roots(&self, id: Value, _params: &[Value]) -> JsonResult {
+    pub async fn blockchain_merkle_roots(&self, id: Value, _params: &[Value]) -> JsonResult {
         let roots: Vec<MerkleNode> =
             match self.validator_state.read().await.blockchain.merkle_roots.get_all() {
                 Ok(v) => v,

+ 2 - 2
bin/darkfid/src/rpc_misc.rs

@@ -12,7 +12,7 @@ impl Darkfid {
     // Returns a `pong` to the `ping` request.
     // --> {"jsonrpc": "2.0", "method": "ping", "params": [], "id": 1}
     // <-- {"jsonrpc": "2.0", "result": "pong", "id": 1}
-    pub async fn pong(&self, id: Value, _params: &[Value]) -> JsonResult {
+    pub async fn misc_pong(&self, id: Value, _params: &[Value]) -> JsonResult {
         JsonResponse::new(json!("pong"), id).into()
     }
 
@@ -20,7 +20,7 @@ impl Darkfid {
     // Returns current system clock in `Timestamp` format.
     // --> {"jsonrpc": "2.0", "method": "clock", "params": [], "id": 1}
     // <-- {"jsonrpc": "2.0", "result": {...}, "id": 1}
-    pub async fn clock(&self, id: Value, _params: &[Value]) -> JsonResult {
+    pub async fn misc_clock(&self, id: Value, _params: &[Value]) -> JsonResult {
         JsonResponse::new(json!(Timestamp::current_time()), id).into()
     }
 }

+ 2 - 2
bin/darkfid/src/rpc_tx.rs

@@ -26,7 +26,7 @@ impl Darkfid {
     //
     // --> {"jsonrpc": "2.0", "method": "tx.transfer", "params": ["dest_addr", "token_id", 12345], "id": 1}
     // <-- {"jsonrpc": "2.0", "result": "txID...", "id": 1}
-    pub async fn transfer(&self, id: Value, params: &[Value]) -> JsonResult {
+    pub async fn tx_transfer(&self, id: Value, params: &[Value]) -> JsonResult {
         if params.len() != 3 ||
             !params[0].is_string() ||
             !params[1].is_string() ||
@@ -108,7 +108,7 @@ impl Darkfid {
     //
     // --> {"jsonrpc": "2.0", "method": "tx.broadcast", "params": ["base58encodedTX"], "id": 1}
     // <-- {"jsonrpc": "2.0", "result": "txID...", "id": 1}
-    pub async fn broadcast(&self, id: Value, params: &[Value]) -> JsonResult {
+    pub async fn tx_broadcast(&self, id: Value, params: &[Value]) -> JsonResult {
         if params.len() != 1 || params[0].is_string() {
             return JsonError::new(InvalidParams, None, id).into()
         }

+ 9 - 9
bin/darkfid/src/rpc_wallet.rs

@@ -26,7 +26,7 @@ impl Darkfid {
     // Attempts to generate a new keypair and returns its address upon success.
     // --> {"jsonrpc": "2.0", "method": "wallet.keygen", "params": [], "id": 1}
     // <-- {"jsonrpc": "2.0", "result": "1DarkFi...", "id": 1}
-    pub async fn keygen(&self, id: Value, _params: &[Value]) -> JsonResult {
+    pub async fn wallet_keygen(&self, id: Value, _params: &[Value]) -> JsonResult {
         match self.client.keygen().await {
             Ok(a) => JsonResponse::new(json!(a.to_string()), id).into(),
             Err(e) => {
@@ -41,7 +41,7 @@ impl Darkfid {
     // encoded format. `-1` is supported to fetch all available keys.
     // --> {"jsonrpc": "2.0", "method": "wallet.get_addrs", "params": [1, 2], "id": 1}
     // <-- {"jsonrpc": "2.0", "result": ["foo", "bar"], "id": 1}
-    pub async fn get_addrs(&self, id: Value, params: &[Value]) -> JsonResult {
+    pub async fn wallet_get_addrs(&self, id: Value, params: &[Value]) -> JsonResult {
         if params.is_empty() {
             return JsonError::new(InvalidParams, None, id).into()
         }
@@ -95,7 +95,7 @@ impl Darkfid {
     // Returns the encoded secret key upon success.
     // --> {"jsonrpc": "2.0", "method": "wallet.export_keypair", "params": [0], "id": 1}
     // <-- {"jsonrpc": "2.0", "result": "foobar", "id": 1}
-    pub async fn export_keypair(&self, id: Value, params: &[Value]) -> JsonResult {
+    pub async fn wallet_export_keypair(&self, id: Value, params: &[Value]) -> JsonResult {
         if params.len() != 1 || !params[0].is_u64() {
             return JsonError::new(InvalidParams, None, id).into()
         }
@@ -120,7 +120,7 @@ impl Darkfid {
     // Returns the public counterpart as the result upon success.
     // --> {"jsonrpc": "2.0", "method": "wallet.import_keypair", "params": ["foobar"], "id": 1}
     // <-- {"jsonrpc": "2.0", "result": "pubfoobar", "id": 1}
-    pub async fn import_keypair(&self, id: Value, params: &[Value]) -> JsonResult {
+    pub async fn wallet_import_keypair(&self, id: Value, params: &[Value]) -> JsonResult {
         if params.len() != 1 || !params[0].is_string() {
             return JsonError::new(InvalidParams, None, id).into()
         }
@@ -161,7 +161,7 @@ impl Darkfid {
     // Returns `true` upon success.
     // --> {"jsonrpc": "2.0", "method": "wallet.set_default_address", "params": [2], "id": 1}
     // <-- {"jsonrpc": "2.0", "result": true, "id": 1}
-    pub async fn set_default_address(&self, id: Value, params: &[Value]) -> JsonResult {
+    pub async fn wallet_set_default_address(&self, id: Value, params: &[Value]) -> JsonResult {
         if params.len() != 1 || !params[0].is_u64() {
             return JsonError::new(InvalidParams, None, id).into()
         }
@@ -197,7 +197,7 @@ impl Darkfid {
     // Returns a map of balances, indexed by the token ID.
     // --> {"jsonrpc": "2.0", "method": "wallet.get_balances", "params": [], "id": 1}
     // <-- {"jsonrpc": "2.0", "result": [{"1Foobar...": 100}, {...}]", "id": 1}
-    pub async fn get_balances(&self, id: Value, _params: &[Value]) -> JsonResult {
+    pub async fn wallet_get_balances(&self, id: Value, _params: &[Value]) -> JsonResult {
         let balances = match self.client.get_balances().await {
             Ok(v) => v,
             Err(e) => {
@@ -229,7 +229,7 @@ impl Darkfid {
     //
     // --> {"jsonrpc": "2.0", "method": "wallet.get_coins_valtok", "params": [1234, "F00b4r...", true], "id": 1}
     // <-- {"jsonrpc": "2.0", "result": ["coin", "data", ...], "id": 1}
-    pub async fn get_coins_valtok(&self, id: Value, params: &[Value]) -> JsonResult {
+    pub async fn wallet_get_coins_valtok(&self, id: Value, params: &[Value]) -> JsonResult {
         if params.len() != 3 ||
             !params[0].is_u64() ||
             !params[1].is_string() ||
@@ -265,7 +265,7 @@ impl Darkfid {
     // Query the state merkle tree for the merkle path of a given leaf position.
     // --> {"jsonrpc": "2.0", "method": "wallet.get_merkle_path", "params": [3], "id": 1}
     // <-- {"jsonrpc": "2.0", "result": ["f091uf1...", "081ff0h10w1h0...", ...], "id": 1}
-    pub async fn get_merkle_path(&self, id: Value, params: &[Value]) -> JsonResult {
+    pub async fn wallet_get_merkle_path(&self, id: Value, params: &[Value]) -> JsonResult {
         if params.len() != 1 || !params[0].is_u64() {
             return JsonError::new(InvalidParams, None, id).into()
         }
@@ -290,7 +290,7 @@ impl Darkfid {
     // found in the wallet.
     // --> {"jsonrpc": "2.0", "method": "wallet.decrypt_note", params": [ciphertext], "id": 1}
     // <-- {"jsonrpc": "2.0", "result": "base58_encoded_plain_note", "id": 1}
-    pub async fn decrypt_note(&self, id: Value, params: &[Value]) -> JsonResult {
+    pub async fn wallet_decrypt_note(&self, id: Value, params: &[Value]) -> JsonResult {
         if params.len() != 1 || !params[0].is_string() {
             return JsonError::new(InvalidParams, None, id).into()
         }