|
@@ -20,18 +20,16 @@ use std::collections::HashSet;
|
|
|
|
|
|
|
|
use async_trait::async_trait;
|
|
use async_trait::async_trait;
|
|
|
use smol::lock::MutexGuard;
|
|
use smol::lock::MutexGuard;
|
|
|
-use tinyjson::JsonValue;
|
|
|
|
|
use tracing::debug;
|
|
use tracing::debug;
|
|
|
|
|
|
|
|
use darkfi::{
|
|
use darkfi::{
|
|
|
net::P2pPtr,
|
|
net::P2pPtr,
|
|
|
rpc::{
|
|
rpc::{
|
|
|
- jsonrpc::{ErrorCode, JsonError, JsonRequest, JsonResponse, JsonResult},
|
|
|
|
|
|
|
+ jsonrpc::{ErrorCode, JsonError, JsonRequest, JsonResult},
|
|
|
p2p_method::HandlerP2p,
|
|
p2p_method::HandlerP2p,
|
|
|
server::RequestHandler,
|
|
server::RequestHandler,
|
|
|
},
|
|
},
|
|
|
system::StoppableTaskPtr,
|
|
system::StoppableTaskPtr,
|
|
|
- util::time::Timestamp,
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
use crate::DarkfiNode;
|
|
use crate::DarkfiNode;
|
|
@@ -48,6 +46,9 @@ pub mod stratum;
|
|
|
/// HTTP JSON-RPC related methods for merge mining
|
|
/// HTTP JSON-RPC related methods for merge mining
|
|
|
pub mod xmr;
|
|
pub mod xmr;
|
|
|
|
|
|
|
|
|
|
+/// Misc JSON-RPC methods
|
|
|
|
|
+pub mod misc;
|
|
|
|
|
+
|
|
|
/// Default JSON-RPC `RequestHandler`
|
|
/// Default JSON-RPC `RequestHandler`
|
|
|
pub struct DefaultRpcHandler;
|
|
pub struct DefaultRpcHandler;
|
|
|
|
|
|
|
@@ -104,78 +105,6 @@ impl RequestHandler<DefaultRpcHandler> for DarkfiNode {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-impl DarkfiNode {
|
|
|
|
|
- // RPCAPI:
|
|
|
|
|
- // Returns current system clock as a UNIX timestamp.
|
|
|
|
|
- //
|
|
|
|
|
- // --> {"jsonrpc": "2.0", "method": "clock", "params": [], "id": 1}
|
|
|
|
|
- // <-- {"jsonrpc": "2.0", "result": 1767015913, "id": 1}
|
|
|
|
|
- async fn clock(&self, id: u16, _params: JsonValue) -> JsonResult {
|
|
|
|
|
- JsonResponse::new((Timestamp::current_time().inner() as f64).into(), id).into()
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // RPCAPI:
|
|
|
|
|
- // Activate or deactivate dnet in the P2P stack.
|
|
|
|
|
- // By sending `true`, dnet will be activated, and by sending `false` dnet
|
|
|
|
|
- // will be deactivated.
|
|
|
|
|
- //
|
|
|
|
|
- // Returns `true` on success.
|
|
|
|
|
- //
|
|
|
|
|
- // --> {"jsonrpc": "2.0", "method": "dnet.switch", "params": [true], "id": 1}
|
|
|
|
|
- // <-- {"jsonrpc": "2.0", "result": true, "id": 1}
|
|
|
|
|
- async fn dnet_switch(&self, id: u16, params: JsonValue) -> JsonResult {
|
|
|
|
|
- let Some(params) = params.get::<Vec<JsonValue>>() else {
|
|
|
|
|
- return JsonError::new(ErrorCode::InvalidParams, None, id).into()
|
|
|
|
|
- };
|
|
|
|
|
- if params.len() != 1 || !params[0].is_bool() {
|
|
|
|
|
- return JsonError::new(ErrorCode::InvalidParams, None, id).into()
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- let switch = params[0].get::<bool>().unwrap();
|
|
|
|
|
-
|
|
|
|
|
- if *switch {
|
|
|
|
|
- self.p2p_handler.p2p.dnet_enable();
|
|
|
|
|
- } else {
|
|
|
|
|
- self.p2p_handler.p2p.dnet_disable();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- JsonResponse::new(JsonValue::Boolean(true), id).into()
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // RPCAPI:
|
|
|
|
|
- // Initializes a subscription to P2P dnet events.
|
|
|
|
|
- // Once a subscription is established, `darkfid` will send JSON-RPC
|
|
|
|
|
- // notifications of new network events to the subscriber.
|
|
|
|
|
- //
|
|
|
|
|
- // --> {
|
|
|
|
|
- // "jsonrpc": "2.0",
|
|
|
|
|
- // "method": "dnet.subscribe_events",
|
|
|
|
|
- // "params": [],
|
|
|
|
|
- // "id": 1
|
|
|
|
|
- // }
|
|
|
|
|
- // <-- {
|
|
|
|
|
- // "jsonrpc": "2.0",
|
|
|
|
|
- // "method": "dnet.subscribe_events",
|
|
|
|
|
- // "params": [
|
|
|
|
|
- // {
|
|
|
|
|
- // "chan": {"Channel": "Info"},
|
|
|
|
|
- // "cmd": "command",
|
|
|
|
|
- // "time": 1767016282
|
|
|
|
|
- // }
|
|
|
|
|
- // ]
|
|
|
|
|
- // }
|
|
|
|
|
- pub async fn dnet_subscribe_events(&self, id: u16, params: JsonValue) -> JsonResult {
|
|
|
|
|
- let Some(params) = params.get::<Vec<JsonValue>>() else {
|
|
|
|
|
- return JsonError::new(ErrorCode::InvalidParams, None, id).into()
|
|
|
|
|
- };
|
|
|
|
|
- if !params.is_empty() {
|
|
|
|
|
- return JsonError::new(ErrorCode::InvalidParams, None, id).into()
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- self.subscribers.get("dnet").unwrap().clone().into()
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
impl HandlerP2p for DarkfiNode {
|
|
impl HandlerP2p for DarkfiNode {
|
|
|
fn p2p(&self) -> P2pPtr {
|
|
fn p2p(&self) -> P2pPtr {
|
|
|
self.p2p_handler.p2p.clone()
|
|
self.p2p_handler.p2p.clone()
|