#![allow(
clippy::bool_assert_comparison,
clippy::let_unit_value
)]
#[cfg(feature = "serde")]
pub extern crate actual_serde as serde;
#[cfg(feature = "bitcoin")]
pub extern crate bitcoin;
#[cfg(feature = "elements")]
pub extern crate elements;
pub extern crate byteorder;
pub extern crate hashes;
pub extern crate hex;
#[macro_use]
mod macros;
mod analysis;
mod bit_encoding;
pub mod bit_machine;
pub mod dag;
pub mod human_encoding;
pub mod jet;
mod merkle;
pub mod node;
#[cfg(feature = "elements")]
pub mod policy;
pub mod types;
mod value;
pub use bit_encoding::decode;
pub use bit_encoding::encode;
pub use bit_encoding::{write_to_vec, BitWriter};
pub use bit_encoding::{BitIter, EarlyEndOfStreamError};
#[cfg(feature = "elements")]
pub use crate::policy::{
sighash, Policy, Preimage32, Satisfier, SimplicityKey, ToXOnlyPubkey, Translator,
};
pub use crate::analysis::{Cost, NodeBounds};
pub use crate::bit_machine::BitMachine;
pub use crate::encode::{encode_natural, encode_value, encode_witness};
pub use crate::merkle::{
amr::Amr,
cmr::Cmr,
imr::{FirstPassImr, Imr},
tmr::Tmr,
FailEntropy,
};
pub use crate::node::{CommitNode, ConstructNode, RedeemNode, WitnessNode};
pub use crate::value::Value;
pub use simplicity_sys as ffi;
use std::fmt;
#[cfg(feature = "elements")]
pub fn leaf_version() -> elements::taproot::LeafVersion {
elements::taproot::LeafVersion::from_u8(0xbe).expect("constant leaf version")
}
#[non_exhaustive]
#[derive(Debug)]
pub enum Error {
Decode(crate::decode::Error),
DisconnectCommitTime,
DisconnectRedeemTime,
Type(crate::types::Error),
NoMoreWitnesses,
IncompleteFinalization,
InconsistentWitnessLength,
InvalidJetName(String),
#[cfg(feature = "elements")]
Policy(policy::Error),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::Decode(ref e) => fmt::Display::fmt(e, f),
Error::DisconnectCommitTime => {
f.write_str("disconnect node had two children (commit time); must have one")
}
Error::DisconnectRedeemTime => {
f.write_str("disconnect node had one child (redeem time); must have two")
}
Error::Type(ref e) => fmt::Display::fmt(e, f),
Error::IncompleteFinalization => f.write_str("unable to satisfy program"),
Error::InconsistentWitnessLength => {
f.write_str("witness has different length than defined in its preamble")
}
Error::InvalidJetName(s) => write!(f, "unknown jet `{}`", s),
Error::NoMoreWitnesses => f.write_str("no more witness data available"),
#[cfg(feature = "elements")]
Error::Policy(ref e) => fmt::Display::fmt(e, f),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Error::Decode(ref e) => Some(e),
Error::DisconnectCommitTime => None,
Error::DisconnectRedeemTime => None,
Error::Type(ref e) => Some(e),
Error::NoMoreWitnesses => None,
Error::IncompleteFinalization => None,
Error::InconsistentWitnessLength => None,
Error::InvalidJetName(..) => None,
#[cfg(feature = "elements")]
Error::Policy(ref e) => Some(e),
}
}
}
impl From<crate::decode::Error> for Error {
fn from(e: crate::decode::Error) -> Error {
Error::Decode(e)
}
}
impl From<EarlyEndOfStreamError> for Error {
fn from(e: EarlyEndOfStreamError) -> Error {
Error::Decode(e.into())
}
}
impl From<crate::types::Error> for Error {
fn from(e: crate::types::Error) -> Error {
Error::Type(e)
}
}
#[cfg(feature = "elements")]
impl From<policy::Error> for Error {
fn from(e: policy::Error) -> Error {
Error::Policy(e)
}
}