use alloc::{fmt, vec::Vec};
use binary_sv2::{self, Deserialize, Seq0255, Serialize, Str0255, B0255, B064K, U256};
use core::convert::TryInto;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetCustomMiningJob<'decoder> {
pub channel_id: u32,
pub request_id: u32,
pub token: B0255<'decoder>,
pub version: u32,
pub prev_hash: U256<'decoder>,
pub min_ntime: u32,
pub nbits: u32,
pub coinbase_tx_version: u32,
pub coinbase_prefix: B0255<'decoder>,
pub coinbase_tx_input_n_sequence: u32,
pub coinbase_tx_outputs: B064K<'decoder>,
pub coinbase_tx_locktime: u32,
pub merkle_path: Seq0255<'decoder, U256<'decoder>>,
}
impl fmt::Display for SetCustomMiningJob<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "SetCustomMiningJob(channel_id={}, request_id={}, token={}, version=0x{:08x}, prev_hash={}, min_ntime={}, nbits=0x{:08x}, coinbase_tx_version=0x{:08x}, coinbase_prefix={}, coinbase_tx_input_n_sequence=0x{:08x}, coinbase_tx_outputs={}, coinbase_tx_locktime={}, merkle_path={})",
self.channel_id,
self.request_id,
self.token.as_hex(),
self.version,
self.prev_hash,
self.min_ntime,
self.nbits,
self.coinbase_tx_version,
self.coinbase_prefix.as_hex(),
self.coinbase_tx_input_n_sequence,
self.coinbase_tx_outputs,
self.coinbase_tx_locktime,
self.merkle_path
)
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SetCustomMiningJobSuccess {
pub channel_id: u32,
pub request_id: u32,
pub job_id: u32,
}
impl fmt::Display for SetCustomMiningJobSuccess {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"SetCustomMiningJobSuccess(channel_id={}, request_id={}, job_id={})",
self.channel_id, self.request_id, self.job_id
)
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SetCustomMiningJobError<'decoder> {
pub channel_id: u32,
pub request_id: u32,
pub error_code: Str0255<'decoder>,
}
impl fmt::Display for SetCustomMiningJobError<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"SetCustomMiningJobError(channel_id={}, request_id={}, error_code={})",
self.channel_id,
self.request_id,
self.error_code.as_utf8_or_hex()
)
}
}