mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-09 06:38:12 -05:00
[WIP] darkfid: moved rpc into its own module
This commit is contained in:
@@ -45,12 +45,7 @@ use error::{server_error, RpcError};
|
||||
|
||||
/// JSON-RPC requests handler and methods
|
||||
mod rpc;
|
||||
use rpc::{DefaultRpcHandler, MmRpcHandler, StratumRpcHandler};
|
||||
mod rpc_blockchain;
|
||||
mod rpc_miner;
|
||||
mod rpc_stratum;
|
||||
mod rpc_tx;
|
||||
mod rpc_xmr;
|
||||
use rpc::DefaultRpcHandler;
|
||||
|
||||
/// Validator async tasks
|
||||
pub mod task;
|
||||
|
||||
@@ -34,7 +34,10 @@ use darkfi::{
|
||||
Error, Result,
|
||||
};
|
||||
|
||||
use crate::{DarkfiNode, DarkfiNodePtr, MmRpcHandler, StratumRpcHandler};
|
||||
use crate::{
|
||||
rpc::{rpc_stratum::StratumRpcHandler, rpc_xmr::MmRpcHandler},
|
||||
DarkfiNode, DarkfiNodePtr,
|
||||
};
|
||||
|
||||
/// Block related structures
|
||||
pub mod model;
|
||||
|
||||
@@ -36,12 +36,24 @@ use darkfi::{
|
||||
|
||||
use crate::DarkfiNode;
|
||||
|
||||
/// Blockchain related methods
|
||||
mod rpc_blockchain;
|
||||
|
||||
/// Transactions related methods
|
||||
mod rpc_tx;
|
||||
|
||||
// TODO: drop
|
||||
/// minerd related methods
|
||||
mod rpc_miner;
|
||||
|
||||
/// Stratum JSON-RPC related methods for native mining
|
||||
pub mod rpc_stratum;
|
||||
|
||||
/// HTTP JSON-RPC related methods for merge mining
|
||||
pub mod rpc_xmr;
|
||||
|
||||
/// Default JSON-RPC `RequestHandler`
|
||||
pub struct DefaultRpcHandler;
|
||||
/// JSON-RPC `RequestHandler` for Stratum
|
||||
pub struct StratumRpcHandler;
|
||||
/// HTTP JSON-RPC `RequestHandler` for p2pool/merge mining
|
||||
pub struct MmRpcHandler;
|
||||
|
||||
#[async_trait]
|
||||
#[rustfmt::skip]
|
||||
@@ -83,6 +95,7 @@ impl RequestHandler<DefaultRpcHandler> for DarkfiNode {
|
||||
"tx.clean_pending" => self.tx_clean_pending(req.id, req.params).await,
|
||||
"tx.calculate_fee" => self.tx_calculate_fee(req.id, req.params).await,
|
||||
|
||||
// TODO: drop
|
||||
// =============
|
||||
// Miner methods
|
||||
// =============
|
||||
@@ -104,54 +117,6 @@ impl RequestHandler<DefaultRpcHandler> for DarkfiNode {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
#[rustfmt::skip]
|
||||
impl RequestHandler<StratumRpcHandler> for DarkfiNode {
|
||||
async fn handle_request(&self, req: JsonRequest) -> JsonResult {
|
||||
debug!(target: "darkfid::stratum_rpc", "--> {}", req.stringify().unwrap());
|
||||
|
||||
match req.method.as_str() {
|
||||
// ======================
|
||||
// Stratum mining methods
|
||||
// ======================
|
||||
"login" => self.stratum_login(req.id, req.params).await,
|
||||
"submit" => self.stratum_submit(req.id, req.params).await,
|
||||
"keepalived" => self.stratum_keepalived(req.id, req.params).await,
|
||||
_ => JsonError::new(ErrorCode::MethodNotFound, None, req.id).into(),
|
||||
}
|
||||
}
|
||||
|
||||
async fn connections_mut(&self) -> MutexGuard<'life0, HashSet<StoppableTaskPtr>> {
|
||||
self.registry.stratum_rpc_connections.lock().await
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
#[rustfmt::skip]
|
||||
impl RequestHandler<MmRpcHandler> for DarkfiNode {
|
||||
async fn handle_request(&self, req: JsonRequest) -> JsonResult {
|
||||
debug!(target: "darkfid::mm_rpc", "--> {}", req.stringify().unwrap());
|
||||
|
||||
match req.method.as_str() {
|
||||
// ================================================
|
||||
// P2Pool methods requested for Monero Merge Mining
|
||||
// ================================================
|
||||
"merge_mining_get_chain_id" => self.xmr_merge_mining_get_chain_id(req.id, req.params).await,
|
||||
"merge_mining_get_aux_block" => self.xmr_merge_mining_get_aux_block(req.id, req.params).await,
|
||||
"merge_mining_submit_solution" => self.xmr_merge_mining_submit_solution(req.id, req.params).await,
|
||||
|
||||
// ==============
|
||||
// Invalid method
|
||||
// ==============
|
||||
_ => JsonError::new(ErrorCode::MethodNotFound, None, req.id).into(),
|
||||
}
|
||||
}
|
||||
|
||||
async fn connections_mut(&self) -> MutexGuard<'life0, HashSet<StoppableTaskPtr>> {
|
||||
self.registry.mm_rpc_connections.lock().await
|
||||
}
|
||||
}
|
||||
|
||||
impl DarkfiNode {
|
||||
// RPCAPI:
|
||||
// Returns current system clock as `u64` (String) timestamp.
|
||||
@@ -16,17 +16,29 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use std::{collections::HashMap, str::FromStr};
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use smol::lock::MutexGuard;
|
||||
use tinyjson::JsonValue;
|
||||
use tracing::{debug, error, info};
|
||||
|
||||
use darkfi::{
|
||||
rpc::jsonrpc::{ErrorCode, ErrorCode::InvalidParams, JsonError, JsonResponse, JsonResult},
|
||||
rpc::{
|
||||
jsonrpc::{
|
||||
ErrorCode, ErrorCode::InvalidParams, JsonError, JsonRequest, JsonResponse, JsonResult,
|
||||
},
|
||||
server::RequestHandler,
|
||||
},
|
||||
system::StoppableTaskPtr,
|
||||
util::{encoding::base64, time::Timestamp},
|
||||
validator::consensus::Proposal,
|
||||
};
|
||||
use darkfi_sdk::crypto::keypair::Address;
|
||||
use darkfi_serial::serialize_async;
|
||||
use tinyjson::JsonValue;
|
||||
use tracing::{error, info};
|
||||
|
||||
use crate::{
|
||||
proto::ProposalMessage,
|
||||
@@ -37,6 +49,31 @@ use crate::{
|
||||
// https://github.com/xmrig/xmrig-proxy/blob/master/doc/STRATUM.md
|
||||
// https://github.com/xmrig/xmrig-proxy/blob/master/doc/STRATUM_EXT.md
|
||||
|
||||
/// JSON-RPC `RequestHandler` for Stratum
|
||||
pub struct StratumRpcHandler;
|
||||
|
||||
#[async_trait]
|
||||
#[rustfmt::skip]
|
||||
impl RequestHandler<StratumRpcHandler> for DarkfiNode {
|
||||
async fn handle_request(&self, req: JsonRequest) -> JsonResult {
|
||||
debug!(target: "darkfid::stratum_rpc", "--> {}", req.stringify().unwrap());
|
||||
|
||||
match req.method.as_str() {
|
||||
// ======================
|
||||
// Stratum mining methods
|
||||
// ======================
|
||||
"login" => self.stratum_login(req.id, req.params).await,
|
||||
"submit" => self.stratum_submit(req.id, req.params).await,
|
||||
"keepalived" => self.stratum_keepalived(req.id, req.params).await,
|
||||
_ => JsonError::new(ErrorCode::MethodNotFound, None, req.id).into(),
|
||||
}
|
||||
}
|
||||
|
||||
async fn connections_mut(&self) -> MutexGuard<'life0, HashSet<StoppableTaskPtr>> {
|
||||
self.registry.stratum_rpc_connections.lock().await
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: We often just return InvalidParams. These should be cleaned up
|
||||
// and more verbose.
|
||||
// TODO: The jobs storing method is not the most ideal. Think of a better one.
|
||||
@@ -16,7 +16,16 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use std::{collections::HashMap, str::FromStr};
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use hex::FromHex;
|
||||
use smol::lock::MutexGuard;
|
||||
use tinyjson::JsonValue;
|
||||
use tracing::{debug, error, info};
|
||||
|
||||
use darkfi::{
|
||||
blockchain::{
|
||||
@@ -27,7 +36,13 @@ use darkfi::{
|
||||
},
|
||||
HeaderHash,
|
||||
},
|
||||
rpc::jsonrpc::{ErrorCode, ErrorCode::InvalidParams, JsonError, JsonResponse, JsonResult},
|
||||
rpc::{
|
||||
jsonrpc::{
|
||||
ErrorCode, ErrorCode::InvalidParams, JsonError, JsonRequest, JsonResponse, JsonResult,
|
||||
},
|
||||
server::RequestHandler,
|
||||
},
|
||||
system::StoppableTaskPtr,
|
||||
util::encoding::base64,
|
||||
validator::consensus::Proposal,
|
||||
};
|
||||
@@ -36,9 +51,6 @@ use darkfi_sdk::{
|
||||
pasta::pallas,
|
||||
};
|
||||
use darkfi_serial::{deserialize_async, serialize_async};
|
||||
use hex::FromHex;
|
||||
use tinyjson::JsonValue;
|
||||
use tracing::{error, info};
|
||||
|
||||
use crate::{
|
||||
proto::ProposalMessage,
|
||||
@@ -48,6 +60,35 @@ use crate::{
|
||||
|
||||
// https://github.com/SChernykh/p2pool/blob/master/docs/MERGE_MINING.MD
|
||||
|
||||
/// HTTP JSON-RPC `RequestHandler` for p2pool/merge mining
|
||||
pub struct MmRpcHandler;
|
||||
|
||||
#[async_trait]
|
||||
#[rustfmt::skip]
|
||||
impl RequestHandler<MmRpcHandler> for DarkfiNode {
|
||||
async fn handle_request(&self, req: JsonRequest) -> JsonResult {
|
||||
debug!(target: "darkfid::mm_rpc", "--> {}", req.stringify().unwrap());
|
||||
|
||||
match req.method.as_str() {
|
||||
// ================================================
|
||||
// P2Pool methods requested for Monero Merge Mining
|
||||
// ================================================
|
||||
"merge_mining_get_chain_id" => self.xmr_merge_mining_get_chain_id(req.id, req.params).await,
|
||||
"merge_mining_get_aux_block" => self.xmr_merge_mining_get_aux_block(req.id, req.params).await,
|
||||
"merge_mining_submit_solution" => self.xmr_merge_mining_submit_solution(req.id, req.params).await,
|
||||
|
||||
// ==============
|
||||
// Invalid method
|
||||
// ==============
|
||||
_ => JsonError::new(ErrorCode::MethodNotFound, None, req.id).into(),
|
||||
}
|
||||
}
|
||||
|
||||
async fn connections_mut(&self) -> MutexGuard<'life0, HashSet<StoppableTaskPtr>> {
|
||||
self.registry.mm_rpc_connections.lock().await
|
||||
}
|
||||
}
|
||||
|
||||
impl DarkfiNode {
|
||||
// RPCAPI:
|
||||
// Gets a unique ID that identifies this merge mined chain and
|
||||
Reference in New Issue
Block a user