use bellscoin as btc_like;
use crate::common::{
hash::Hash256,
inscriptions::{Genesis, Outpoint},
};
use btc_like::{hashes::Hash, Txid};
impl From<Outpoint> for btc_like::OutPoint {
fn from(v: Outpoint) -> Self {
let txid = Txid::from_slice(&v.txid).unwrap();
Self { txid, vout: v.vout }
}
}
impl From<btc_like::OutPoint> for Outpoint {
fn from(v: btc_like::OutPoint) -> Self {
Self {
txid: v.txid.to_byte_array(),
vout: v.vout,
}
}
}
impl From<Genesis> for btc_like::OutPoint {
fn from(v: Genesis) -> Self {
v.0.into()
}
}
impl From<btc_like::OutPoint> for Genesis {
fn from(v: btc_like::OutPoint) -> Self {
Genesis(v.into())
}
}
impl From<btc_like::BlockHash> for Hash256 {
fn from(value: btc_like::BlockHash) -> Self {
Hash256(*value.to_raw_hash().as_byte_array())
}
}
impl From<Hash256> for btc_like::BlockHash {
fn from(value: Hash256) -> Self {
btc_like::BlockHash::from_byte_array(value.0)
}
}
impl From<Txid> for Hash256 {
fn from(v: Txid) -> Self {
Hash256(v.to_byte_array())
}
}
impl TryFrom<Hash256> for Txid {
type Error = bitcoin_hashes::Error;
fn try_from(v: Hash256) -> Result<Self, Self::Error> {
Txid::from_slice(&v.0)
}
}