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

mmproxy: Add stub RPC methods for Stratum and Monero.

parazyd 2 лет назад
Родитель
Сommit
ab10b5145c
3 измененных файлов с 256 добавлено и 1 удалено
  1. 60 0
      bin/darkfi-mmproxy/src/main.rs
  2. 151 0
      bin/darkfi-mmproxy/src/monero.rs
  3. 45 1
      bin/darkfi-mmproxy/src/stratum.rs

+ 60 - 0
bin/darkfi-mmproxy/src/main.rs

@@ -1,3 +1,21 @@
+/* This file is part of DarkFi (https://dark.fi)
+ *
+ * Copyright (C) 2020-2023 Dyne.org foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
 use std::{collections::HashSet, sync::Arc};
 
 use darkfi::{
@@ -21,6 +39,7 @@ use structopt::StructOpt;
 use structopt_toml::StructOptToml;
 use url::Url;
 
+mod monero;
 mod stratum;
 
 const CONFIG_FILE: &str = "darkfi_mmproxy.toml";
@@ -59,12 +78,53 @@ impl MiningProxy {
 }
 
 #[async_trait]
+#[rustfmt::skip]
 impl RequestHandler for MiningProxy {
     async fn handle_request(&self, req: JsonRequest) -> JsonResult {
         error!(target: "mmproxy::rpc", "--> {}", req.stringify().unwrap());
 
         match req.method.as_str() {
             "ping" => self.pong(req.id, req.params).await,
+
+            // Stratum methods
+            "login" => self.stratum_login(req.id, req.params).await,
+            "job" => self.stratum_job(req.id, req.params).await,
+            "submit" => self.stratum_submit(req.id, req.params).await,
+            "keepalived" => self.stratum_keepalived(req.id, req.params).await,
+
+            // Monero daemon methods
+            "get_block_count" => self.monero_get_block_count(req.id, req.params).await,
+            "on_get_block_hash" => self.monero_on_get_block_hash(req.id, req.params).await,
+            "get_block_template" => self.monero_get_block_template(req.id, req.params).await,
+            "submit_block" => self.monero_submit_block(req.id, req.params).await,
+            "generateblocks" => self.monero_generateblocks(req.id, req.params).await,
+            "get_last_block_header" => self.monero_get_last_block_header(req.id, req.params).await,
+            "get_block_header_by_hash" => self.monero_get_block_header_by_hash(req.id, req.params).await,
+            "get_block_header_by_height" => self.monero_get_block_header_by_height(req.id, req.params).await,
+            "get_block_headers_range" => self.monero_get_block_headers_range(req.id, req.params).await,
+            "get_block" => self.monero_get_block(req.id, req.params).await,
+            "get_connections" => self.monero_get_connections(req.id, req.params).await,
+            "get_info" => self.monero_get_info(req.id, req.params).await,
+            "hard_fork_info" => self.monero_hard_fork_info(req.id, req.params).await,
+            "set_bans" => self.monero_set_bans(req.id, req.params).await,
+            "get_bans" => self.monero_get_bans(req.id, req.params).await,
+            "banned" => self.monero_banned(req.id, req.params).await,
+            "flush_txpool" => self.monero_flush_txpool(req.id, req.params).await,
+            "get_output_histogram" => self.monero_get_output_histogram(req.id, req.params).await,
+            "get_version" => self.monero_get_version(req.id, req.params).await,
+            "get_coinbase_tx_sum" => self.monero_get_coinbase_tx_sum(req.id, req.params).await,
+            "get_fee_estimate" => self.monero_get_fee_estimate(req.id, req.params).await,
+            "get_alternate_chains" => self.monero_get_alternate_chains(req.id, req.params).await,
+            "relay_tx" => self.monero_relay_tx(req.id, req.params).await,
+            "sync_info" => self.monero_sync_info(req.id, req.params).await,
+            "get_txpool_backlog" => self.monero_get_txpool_backlog(req.id, req.params).await,
+            "get_output_distribution" => self.monero_get_output_distribution(req.id, req.params).await,
+            "get_miner_data" => self.monero_get_miner_data(req.id, req.params).await,
+            "prune_blockchain" => self.monero_prune_blockchain(req.id, req.params).await,
+            "calc_pow" => self.monero_calc_pow(req.id, req.params).await,
+            "flush_cache" => self.monero_flush_cache(req.id, req.params).await,
+            "add_aux_pow" => self.monero_add_aux_pow(req.id, req.params).await,
+
             _ => JsonError::new(ErrorCode::MethodNotFound, None, req.id).into(),
         }
     }

+ 151 - 0
bin/darkfi-mmproxy/src/monero.rs

@@ -0,0 +1,151 @@
+/* This file is part of DarkFi (https://dark.fi)
+ *
+ * Copyright (C) 2020-2023 Dyne.org foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+use darkfi::rpc::{jsonrpc::JsonResult, util::JsonValue};
+
+use super::MiningProxy;
+
+impl MiningProxy {
+    pub async fn monero_get_block_count(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_on_get_block_hash(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_get_block_template(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_submit_block(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_generateblocks(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_get_last_block_header(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_get_block_header_by_hash(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_get_block_header_by_height(
+        &self,
+        id: u16,
+        params: JsonValue,
+    ) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_get_block_headers_range(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_get_block(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_get_connections(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_get_info(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_hard_fork_info(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_set_bans(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_get_bans(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_banned(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_flush_txpool(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_get_output_histogram(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_get_version(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_get_coinbase_tx_sum(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_get_fee_estimate(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_get_alternate_chains(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_relay_tx(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_sync_info(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_get_txpool_backlog(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_get_output_distribution(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_get_miner_data(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_prune_blockchain(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_calc_pow(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_flush_cache(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn monero_add_aux_pow(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+}

+ 45 - 1
bin/darkfi-mmproxy/src/stratum.rs

@@ -1,3 +1,47 @@
+/* This file is part of DarkFi (https://dark.fi)
+ *
+ * Copyright (C) 2020-2023 Dyne.org foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+use darkfi::rpc::{
+    jsonrpc::{ErrorCode, JsonError, JsonResult},
+    util::JsonValue,
+};
+
 use super::MiningProxy;
 
-impl MiningProxy {}
+impl MiningProxy {
+    pub async fn stratum_login(&self, id: u16, params: JsonValue) -> JsonResult {
+        let params = params.get::<Vec<JsonValue>>().unwrap();
+        if params.len() != 1 || !params[0].is_object() {
+            return JsonError::new(ErrorCode::InvalidParams, None, id).into()
+        }
+
+        todo!()
+    }
+
+    pub async fn stratum_job(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn stratum_submit(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+
+    pub async fn stratum_keepalived(&self, id: u16, params: JsonValue) -> JsonResult {
+        todo!()
+    }
+}