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

darkfid: Compile and include rpc_xmr

parazyd 1 год назад
Родитель
Сommit
20fb68303e
4 измененных файлов с 7 добавлено и 35 удалено
  1. 1 0
      bin/darkfid/src/lib.rs
  2. 4 6
      bin/darkfid/src/rpc.rs
  3. 1 28
      bin/darkfid/src/rpc_blockchain.rs
  4. 1 1
      bin/darkfid/src/rpc_xmr.rs

+ 1 - 0
bin/darkfid/src/lib.rs

@@ -47,6 +47,7 @@ mod rpc;
 use rpc::{DefaultRpcHandler, MinerRpcClient, MmRpcHandler};
 mod rpc_blockchain;
 mod rpc_tx;
+mod rpc_xmr;
 
 /// Validator async tasks
 pub mod task;

+ 4 - 6
bin/darkfid/src/rpc.rs

@@ -97,7 +97,6 @@ impl RequestHandler<DefaultRpcHandler> for DarkfiNode {
             "blockchain.subscribe_blocks" => self.blockchain_subscribe_blocks(req.id, req.params).await,
             "blockchain.subscribe_txs" =>  self.blockchain_subscribe_txs(req.id, req.params).await,
             "blockchain.subscribe_proposals" => self.blockchain_subscribe_proposals(req.id, req.params).await,
-            "merge_mining_get_chain_id" => self.merge_mining_get_chain_id(req.id, req.params).await,
 
             // ===================
             // Transaction methods
@@ -127,11 +126,10 @@ impl RequestHandler<MmRpcHandler> for DarkfiNode {
         debug!(target: "darkfid::mm_rpc", "--> {}", req.stringify().unwrap());
 
         match req.method.as_str() {
-            // =====================
-            // Miscellaneous methods
-            // =====================
-            "ping" => <DarkfiNode as RequestHandler<MmRpcHandler>>::pong(self, req.id, req.params).await,
-            "clock" => self.clock(req.id, req.params).await,
+            // ================================================
+            // P2Pool methods requested for Monero Merge Mining
+            // ================================================
+            "merge_mining_get_chain_id" => self.xmr_merge_mining_get_chain_id(req.id, req.params).await,
 
             // ==============
             // Invalid method

+ 1 - 28
bin/darkfid/src/rpc_blockchain.rs

@@ -16,7 +16,7 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use std::{collections::HashMap, str::FromStr};
+use std::str::FromStr;
 
 use darkfi_sdk::{crypto::ContractId, tx::TransactionHash};
 use darkfi_serial::{deserialize_async, serialize_async};
@@ -313,31 +313,4 @@ impl DarkfiNode {
 
         JsonResponse::new(JsonValue::Array(ret), id).into()
     }
-
-    // RPCAPI:
-    // Returns the `chain_id` used for merge mining. A 32-byte hash of the genesis block.
-    //
-    // --> {"jsonrpc": "2.0", "method": "merge_mining_get_chain_id", "params": [], "id": 0}
-    // <-- {"jsonrpc": "2.0", "result": {"chain_id": 02f8...7863"}, "id": 0}
-    pub async fn merge_mining_get_chain_id(&self, id: u16, _params: JsonValue) -> JsonResult {
-        let chain_id = match self.validator.blockchain.genesis() {
-            Ok((_, v)) => v,
-            Err(e) => {
-                error!(
-                    target: "darkfid::rpc::merge_mining_get_chain_id",
-                    "[RPC] Error looking up genesis block: {}", e,
-                );
-                return JsonError::new(InternalError, None, id).into()
-            }
-        };
-
-        JsonResponse::new(
-            JsonValue::Object(HashMap::from([(
-                "chain_id".to_string(),
-                chain_id.as_string().into(),
-            )])),
-            id,
-        )
-        .into()
-    }
 }

+ 1 - 1
bin/darkfid/src/rpc_xmr.rs

@@ -34,7 +34,7 @@ impl DarkfiNode {
     //
     // --> {"jsonrpc":"2.0", "method": "merge_mining_get_chain_id", "id": 1}
     // <-- {"jsonrpc":"2.0", "result": {"chain_id": "0f28c...7863"}, "id": 1}
-    pub async fn xmr_merge_mining_get_chain_id(self, id: u16, _params: JsonValue) -> JsonResult {
+    pub async fn xmr_merge_mining_get_chain_id(&self, id: u16, _params: JsonValue) -> JsonResult {
         let (_, genesis_hash) = match self.validator.blockchain.genesis() {
             Ok(v) => v,
             Err(e) => {