1#![cfg_attr(bench, feature(test))]
55#![allow(
56 clippy::bool_assert_comparison,
58 clippy::let_unit_value,
60 clippy::map_clone
62)]
63
64#[cfg(feature = "bitcoin")]
65pub extern crate bitcoin;
66#[cfg(feature = "elements")]
67pub extern crate elements;
68#[cfg(feature = "serde")]
69pub extern crate serde;
70
71#[cfg(feature = "base64")]
73pub use bitcoin::base64;
74pub extern crate byteorder;
76pub extern crate ghost_cell;
78pub extern crate hashes;
80pub extern crate hex;
82
83#[cfg(bench)]
84extern crate test;
85
86#[macro_use]
87mod macros;
88
89mod analysis;
90mod bit_encoding;
91pub mod bit_machine;
92pub mod dag;
93#[cfg(feature = "human_encoding")]
94pub mod human_encoding;
95pub mod jet;
96mod merkle;
97pub mod node;
98#[cfg(feature = "elements")]
99pub mod policy;
100#[cfg(feature = "serde")]
101pub mod serializers;
102pub mod types;
103mod value;
104
105pub use bit_encoding::decode;
106pub use bit_encoding::encode;
107pub use bit_encoding::{
108 u2, BitCollector, BitIter, CloseError as BitIterCloseError, EarlyEndOfStreamError,
109};
110pub use bit_encoding::{write_to_vec, BitWriter};
111
112#[cfg(feature = "elements")]
113pub use crate::policy::{
114 sighash, Policy, Preimage32, Satisfier, SimplicityKey, ToXOnlyPubkey, Translator,
115};
116
117pub use crate::analysis::{Cost, NodeBounds};
118pub use crate::bit_machine::BitMachine;
119pub use crate::encode::{encode_natural, encode_value, encode_witness};
120pub use crate::merkle::{
121 amr::Amr,
122 cmr::Cmr,
123 ihr::{Ihr, Imr},
124 tmr::Tmr,
125 FailEntropy, HasCmr,
126};
127pub use crate::node::{CommitNode, ConstructNode, Hiding, RedeemNode};
128pub use crate::value::{Value, ValueRef, Word};
129pub use simplicity_sys as ffi;
130use std::fmt;
131
132#[cfg(feature = "elements")]
134pub fn leaf_version() -> elements::taproot::LeafVersion {
135 elements::taproot::LeafVersion::from_u8(0xbe).expect("constant leaf version")
136}
137
138#[non_exhaustive]
140#[derive(Debug)]
141pub enum DecodeError {
142 Decode(decode::Error),
144 DisconnectRedeemTime,
146 Type(types::Error),
148}
149
150impl fmt::Display for DecodeError {
151 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
152 match self {
153 Self::Decode(ref e) => fmt::Display::fmt(e, f),
154 Self::DisconnectRedeemTime => {
155 f.write_str("disconnect node had one child (redeem time); must have two")
156 }
157 Self::Type(ref e) => fmt::Display::fmt(e, f),
158 }
159 }
160}
161
162impl std::error::Error for DecodeError {
163 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
164 match self {
165 Self::Decode(ref e) => Some(e),
166 Self::DisconnectRedeemTime => None,
167 Self::Type(ref e) => Some(e),
168 }
169 }
170}
171
172#[non_exhaustive]
174#[derive(Debug)]
175pub enum ParseError {
176 Decode(DecodeError),
178 #[cfg(feature = "base64")]
180 Base64(base64::DecodeError),
181 Hex(hex::error::HexToBytesError),
183}
184
185impl fmt::Display for ParseError {
186 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
187 match self {
188 Self::Decode(ref e) => e.fmt(f),
189 #[cfg(feature = "base64")]
190 Self::Base64(ref e) => e.fmt(f),
191 Self::Hex(ref e) => e.fmt(f),
192 }
193 }
194}
195
196impl std::error::Error for ParseError {
197 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
198 match self {
199 Self::Decode(ref e) => Some(e),
200 #[cfg(feature = "base64")]
201 Self::Base64(ref e) => Some(e),
202 Self::Hex(ref e) => Some(e),
203 }
204 }
205}
206
207#[non_exhaustive]
209#[derive(Debug)]
210pub enum FinalizeError {
211 DisconnectRedeemTime,
213 Execution(bit_machine::ExecutionError),
215 Type(types::Error),
217}
218
219impl fmt::Display for FinalizeError {
220 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
221 match self {
222 Self::DisconnectRedeemTime => {
223 f.write_str("disconnect node had one child (redeem time); must have two")
224 }
225 Self::Execution(ref e) => fmt::Display::fmt(e, f),
226 Self::Type(ref e) => fmt::Display::fmt(e, f),
227 }
228 }
229}
230
231impl std::error::Error for FinalizeError {
232 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
233 match self {
234 Self::DisconnectRedeemTime => None,
235 Self::Execution(ref e) => Some(e),
236 Self::Type(ref e) => Some(e),
237 }
238 }
239}
240
241#[non_exhaustive]
245#[derive(Debug)]
246pub enum Error {
247 InvalidJetName(String),
249}
250
251impl fmt::Display for Error {
252 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
253 match self {
254 Error::InvalidJetName(s) => write!(f, "unknown jet `{}`", s),
255 }
256 }
257}
258
259impl std::error::Error for Error {
260 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
261 match *self {
262 Error::InvalidJetName(..) => None,
263 }
264 }
265}