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;
93pub mod human_encoding;
94pub mod jet;
95mod merkle;
96pub mod node;
97#[cfg(feature = "elements")]
98pub mod policy;
99pub mod types;
100mod value;
101
102pub use bit_encoding::decode;
103pub use bit_encoding::encode;
104pub use bit_encoding::{
105 u2, BitCollector, BitIter, CloseError as BitIterCloseError, EarlyEndOfStreamError,
106};
107pub use bit_encoding::{write_to_vec, BitWriter};
108
109#[cfg(feature = "elements")]
110pub use crate::policy::{
111 sighash, Policy, Preimage32, Satisfier, SimplicityKey, ToXOnlyPubkey, Translator,
112};
113
114pub use crate::analysis::{Cost, NodeBounds};
115pub use crate::bit_machine::BitMachine;
116pub use crate::encode::{encode_natural, encode_value, encode_witness};
117pub use crate::merkle::{
118 amr::Amr,
119 cmr::Cmr,
120 ihr::{Ihr, Imr},
121 tmr::Tmr,
122 FailEntropy, HasCmr,
123};
124pub use crate::node::{CommitNode, ConstructNode, Hiding, RedeemNode};
125pub use crate::value::{Value, ValueRef, Word};
126pub use simplicity_sys as ffi;
127use std::fmt;
128
129#[cfg(feature = "elements")]
131pub fn leaf_version() -> elements::taproot::LeafVersion {
132 elements::taproot::LeafVersion::from_u8(0xbe).expect("constant leaf version")
133}
134
135#[non_exhaustive]
137#[derive(Debug)]
138pub enum DecodeError {
139 Decode(decode::Error),
141 DisconnectRedeemTime,
143 Type(types::Error),
145}
146
147impl fmt::Display for DecodeError {
148 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
149 match self {
150 Self::Decode(ref e) => fmt::Display::fmt(e, f),
151 Self::DisconnectRedeemTime => {
152 f.write_str("disconnect node had one child (redeem time); must have two")
153 }
154 Self::Type(ref e) => fmt::Display::fmt(e, f),
155 }
156 }
157}
158
159impl std::error::Error for DecodeError {
160 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
161 match self {
162 Self::Decode(ref e) => Some(e),
163 Self::DisconnectRedeemTime => None,
164 Self::Type(ref e) => Some(e),
165 }
166 }
167}
168
169#[non_exhaustive]
171#[derive(Debug)]
172pub enum ParseError {
173 Decode(DecodeError),
175 #[cfg(feature = "base64")]
177 Base64(base64::DecodeError),
178 Hex(hex::error::HexToBytesError),
180}
181
182impl fmt::Display for ParseError {
183 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
184 match self {
185 Self::Decode(ref e) => e.fmt(f),
186 #[cfg(feature = "base64")]
187 Self::Base64(ref e) => e.fmt(f),
188 Self::Hex(ref e) => e.fmt(f),
189 }
190 }
191}
192
193impl std::error::Error for ParseError {
194 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
195 match self {
196 Self::Decode(ref e) => Some(e),
197 #[cfg(feature = "base64")]
198 Self::Base64(ref e) => Some(e),
199 Self::Hex(ref e) => Some(e),
200 }
201 }
202}
203
204#[non_exhaustive]
206#[derive(Debug)]
207pub enum FinalizeError {
208 DisconnectRedeemTime,
210 Execution(bit_machine::ExecutionError),
212 Type(types::Error),
214}
215
216impl fmt::Display for FinalizeError {
217 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
218 match self {
219 Self::DisconnectRedeemTime => {
220 f.write_str("disconnect node had one child (redeem time); must have two")
221 }
222 Self::Execution(ref e) => fmt::Display::fmt(e, f),
223 Self::Type(ref e) => fmt::Display::fmt(e, f),
224 }
225 }
226}
227
228impl std::error::Error for FinalizeError {
229 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
230 match self {
231 Self::DisconnectRedeemTime => None,
232 Self::Execution(ref e) => Some(e),
233 Self::Type(ref e) => Some(e),
234 }
235 }
236}
237
238#[non_exhaustive]
242#[derive(Debug)]
243pub enum Error {
244 InvalidJetName(String),
246}
247
248impl fmt::Display for Error {
249 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
250 match self {
251 Error::InvalidJetName(s) => write!(f, "unknown jet `{}`", s),
252 }
253 }
254}
255
256impl std::error::Error for Error {
257 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
258 match *self {
259 Error::InvalidJetName(..) => None,
260 }
261 }
262}