Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions miner-apps/jd-client/src/lib/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ use stratum_apps::{
};
use tokio::time::error::Elapsed;

use crate::config::ConfigJDCMode;

pub type JDCResult<T, Owner> = Result<T, JDCError<Owner>>;

#[derive(Debug)]
Expand All @@ -58,6 +60,9 @@ pub struct Upstream;
#[derive(Debug)]
pub struct Downstream;

#[derive(Debug)]
pub struct JobDeclaratorClient;

#[derive(Debug)]
pub struct JDCError<Owner> {
pub kind: JDCErrorKind,
Expand All @@ -73,6 +78,12 @@ pub enum Action {
Shutdown,
}

impl Action {
pub fn is_shutdown(self) -> bool {
matches!(self, Self::Shutdown)
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LoopControl {
Continue,
Expand All @@ -85,12 +96,14 @@ impl CanDisconnect for ChannelManager {}
impl CanFallback for Upstream {}
impl CanFallback for JobDeclarator {}
impl CanFallback for ChannelManager {}
impl CanFallback for JobDeclaratorClient {}

impl CanShutdown for ChannelManager {}
impl CanShutdown for TemplateProvider {}
impl CanShutdown for Downstream {}
impl CanShutdown for Upstream {}
impl CanShutdown for JobDeclarator {}
impl CanShutdown for JobDeclaratorClient {}

impl<O> JDCError<O> {
pub fn log<E: Into<JDCErrorKind>>(kind: E) -> Self {
Expand Down Expand Up @@ -259,6 +272,12 @@ pub enum JDCErrorKind {
InvalidKey,
/// Upstream not found
UpstreamNotFound,
/// Cannot determine Bitcoin data directory
InvalidBitcoinDataDir,
/// No upstream specified for pooled mining
NoUpstreamConfig(ConfigJDCMode),
/// Invalid coinbase output in config
InvalidCoinbaseOutput,
}

impl std::error::Error for JDCErrorKind {}
Expand Down Expand Up @@ -402,6 +421,15 @@ impl fmt::Display for JDCErrorKind {
CouldNotInitiateSystem => write!(f, "Could not initiate subsystem"),
InvalidKey => write!(f, "Invalid key used during noise handshake"),
UpstreamNotFound => write!(f, "Upstream not found"),
InvalidBitcoinDataDir => write!(
f,
"Could not determine Bitcoin data directory. Please set data_dir in config."
),
NoUpstreamConfig(mode) => write!(
f,
"No upstreams configured for {mode:?} mode - at least one upstream is required"
),
InvalidCoinbaseOutput => write!(f, "Invalid coinbase output in config"),
}
}
}
Expand Down
Loading
Loading