mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-09 14:48:08 -05:00
mmproxy: monerod HTTP JSON-RPC example
This commit is contained in:
761
Cargo.lock
generated
761
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -15,6 +15,10 @@ darkfi-serial = {path = "../../src/serial", features = ["async"]}
|
||||
# Misc
|
||||
log = "0.4.20"
|
||||
|
||||
# Monero
|
||||
monero = {version = "0.19.0", features = ["full"]}
|
||||
surf = "2.3.2"
|
||||
|
||||
# Encoding
|
||||
url = "2.4.1"
|
||||
uuid = {version = "1.5.0", features = ["v4"]}
|
||||
|
||||
@@ -9,8 +9,8 @@ CARGO = cargo +nightly
|
||||
SRC = \
|
||||
Cargo.toml \
|
||||
../../Cargo.toml \
|
||||
$(shell find src -type f) \
|
||||
$(shell find ../../src -type f) \
|
||||
$(shell find src -type f -name '*.rs') \
|
||||
$(shell find ../../src -type f -name '*.rs') \
|
||||
|
||||
BIN = ../../darkfi-mmproxy
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ struct Args {
|
||||
/// JSON-RPC server listen URL
|
||||
rpc_listen: Url,
|
||||
|
||||
#[structopt(long, default_value = "tcp://127.0.0.1:18081")]
|
||||
#[structopt(long, default_value = "http://127.0.0.1:28081/json_rpc")]
|
||||
/// monerod JSON-RPC server listen URL
|
||||
monerod_rpc: Url,
|
||||
|
||||
@@ -100,6 +100,8 @@ impl Worker {
|
||||
}
|
||||
|
||||
struct MiningProxy {
|
||||
/// monerod RPC endpoint
|
||||
monerod_rpc: Url,
|
||||
/// Worker logins
|
||||
logins: HashMap<String, String>,
|
||||
/// Workers UUIDs
|
||||
@@ -111,8 +113,13 @@ struct MiningProxy {
|
||||
}
|
||||
|
||||
impl MiningProxy {
|
||||
fn new(logins: HashMap<String, String>, executor: Arc<Executor<'static>>) -> Self {
|
||||
fn new(
|
||||
monerod_rpc: Url,
|
||||
logins: HashMap<String, String>,
|
||||
executor: Arc<Executor<'static>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
monerod_rpc,
|
||||
logins,
|
||||
workers: Arc::new(RwLock::new(HashMap::new())),
|
||||
rpc_connections: Mutex::new(HashSet::new()),
|
||||
@@ -137,6 +144,8 @@ impl RequestHandler for MiningProxy {
|
||||
|
||||
// Monero daemon methods
|
||||
"get_block_count" => self.monero_get_block_count(req.id, req.params).await,
|
||||
"getblockcount" => 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,
|
||||
@@ -190,7 +199,7 @@ async fn realmain(args: Args, ex: Arc<Executor<'static>>) -> Result<()> {
|
||||
logins.insert(user, pass);
|
||||
}
|
||||
|
||||
let mmproxy = Arc::new(MiningProxy::new(logins, ex.clone()));
|
||||
let mmproxy = Arc::new(MiningProxy::new(args.monerod_rpc, logins, ex.clone()));
|
||||
let mmproxy_ = Arc::clone(&mmproxy);
|
||||
|
||||
info!("Starting JSON-RPC server");
|
||||
|
||||
@@ -16,12 +16,32 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use darkfi::rpc::{jsonrpc::JsonResult, util::JsonValue};
|
||||
use darkfi::rpc::{
|
||||
jsonrpc::{JsonRequest, JsonResult},
|
||||
util::JsonValue,
|
||||
};
|
||||
use log::{debug, error};
|
||||
use surf::http::mime;
|
||||
|
||||
use super::MiningProxy;
|
||||
|
||||
impl MiningProxy {
|
||||
pub async fn monero_get_block_count(&self, id: u16, params: JsonValue) -> JsonResult {
|
||||
debug!(target: "rpc::monero", "get_block_count()");
|
||||
|
||||
let req_body = JsonRequest::new("get_block_count", vec![]).stringify().unwrap();
|
||||
|
||||
let client = surf::Client::new();
|
||||
let mut response = client
|
||||
.get(&self.monerod_rpc)
|
||||
.header("Content-Type", "application/json")
|
||||
.body(req_body)
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
println!("{:?}", String::from_utf8_lossy(&response.body_bytes().await.unwrap()));
|
||||
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user