use strict_types::{CompileError, LibBuilder, TypeLib};
use crate::timelocks::TimeLockInterval;
use crate::{
Bip340Sig, BlockHeader, ByteStr, CompressedPk, ControlBlock, FutureLeafVer, InternalPk,
LeafScript, LegacyPk, LegacySig, LockHeight, LockTimestamp, OpCode, OutputPk, PubkeyHash,
RedeemScript, ScriptHash, TapCode, TapLeafHash, TapNodeHash, TapScript, Tx, UncompressedPk,
VBytes, VarInt, WPubkeyHash, WScriptHash, WeightUnits, WitnessProgram, WitnessScript,
WitnessVer, Wtxid, LIB_NAME_BITCOIN,
};
pub const LIB_ID_BP_TX: &str =
"stl:9WwTYiP2-OadKCZP-cR0bJ_Y-qruINYX-bXZFj8Y-fsQoGgo#signal-color-cipher";
pub const LIB_ID_BP_CONSENSUS: &str =
"stl:wUfEZiWN-tvMpLYq-~h1iQC3-bHNSjiW-h9d7O0t-i154uQ0#quiz-patent-exit";
#[deprecated(since = "0.10.8", note = "use _bp_tx_stl instead")]
fn _bitcoin_stl() -> Result<TypeLib, CompileError> { _bp_tx_stl() }
fn _bp_tx_stl() -> Result<TypeLib, CompileError> {
LibBuilder::new(libname!(LIB_NAME_BITCOIN), None).transpile::<Tx>().compile()
}
fn _bp_consensus_stl() -> Result<TypeLib, CompileError> {
LibBuilder::new(libname!(LIB_NAME_BITCOIN), tiny_bset! {
strict_types::stl::std_stl().to_dependency(),
})
.transpile::<LegacySig>()
.transpile::<Bip340Sig>()
.transpile::<OpCode>()
.transpile::<PubkeyHash>()
.transpile::<WPubkeyHash>()
.transpile::<ScriptHash>()
.transpile::<WScriptHash>()
.transpile::<WitnessScript>()
.transpile::<RedeemScript>()
.transpile::<Wtxid>()
.transpile::<WitnessProgram>()
.transpile::<WitnessVer>()
.transpile::<CompressedPk>()
.transpile::<UncompressedPk>()
.transpile::<LegacyPk>()
.transpile::<InternalPk>()
.transpile::<OutputPk>()
.transpile::<TapNodeHash>()
.transpile::<TapLeafHash>()
.transpile::<FutureLeafVer>()
.transpile::<LeafScript>()
.transpile::<TapCode>()
.transpile::<TapScript>()
.transpile::<ControlBlock>()
.transpile::<BlockHeader>()
.transpile::<TimeLockInterval>()
.transpile::<LockTimestamp>()
.transpile::<LockHeight>()
.transpile::<Tx>()
.transpile::<VarInt>()
.transpile::<ByteStr>()
.transpile::<WeightUnits>()
.transpile::<VBytes>()
.compile()
}
#[deprecated(since = "0.10.8", note = "use bp_tx_stl instead")]
pub fn bitcoin_stl() -> TypeLib { bp_tx_stl() }
pub fn bp_tx_stl() -> TypeLib {
_bp_tx_stl().expect("invalid strict type Bitcoin transaction library")
}
pub fn bp_consensus_stl() -> TypeLib {
_bp_consensus_stl().expect("invalid strict type Bitcoin consensus library")
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn lib_id_tx() {
let lib = bp_tx_stl();
assert_eq!(lib.id().to_string(), LIB_ID_BP_TX);
}
#[test]
fn lib_id_consensus() {
let lib = bp_consensus_stl();
assert_eq!(lib.id().to_string(), LIB_ID_BP_CONSENSUS);
}
}