use chia_protocol::SpendBundle;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PushOutcome {
Accepted,
AlreadyInMempool,
Rejected {
reason: String,
},
}
#[derive(Debug, Clone, thiserror::Error)]
#[error("{0}")]
pub struct ChainUnavailable(String);
impl ChainUnavailable {
pub fn new(cause: impl Into<String>) -> Self {
Self(cause.into())
}
}
pub trait SpendPublisher {
fn push(&self, bundle: &SpendBundle) -> Result<PushOutcome, ChainUnavailable>;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_rejection_carries_the_node_reason_and_is_not_an_error() {
let outcome = PushOutcome::Rejected {
reason: "ASSERT_HEIGHT_ABSOLUTE_FAILED".into(),
};
assert_ne!(outcome, PushOutcome::Accepted);
assert!(matches!(outcome, PushOutcome::Rejected { reason } if reason.contains("ASSERT")));
}
#[test]
fn an_unavailable_chain_displays_its_cause() {
assert_eq!(
ChainUnavailable::new("connection refused").to_string(),
"connection refused"
);
}
}