use bp::dbc::Anchor;
use commit_verify::lnpbp4;
use crate::{reveal, ContractId, MergeReveal};
pub trait ConcealAnchors {
fn conceal_anchors_except(
&mut self,
contracts: impl AsRef<[ContractId]>,
) -> Result<usize, lnpbp4::LeafNotKnown>;
}
impl ConcealAnchors for Anchor<lnpbp4::MerkleBlock> {
fn conceal_anchors_except(
&mut self,
contracts: impl AsRef<[ContractId]>,
) -> Result<usize, lnpbp4::LeafNotKnown> {
let protocols = contracts
.as_ref()
.iter()
.copied()
.map(lnpbp4::ProtocolId::from)
.collect::<Vec<_>>();
self.conceal_except(protocols)
}
}
impl MergeReveal for Anchor<lnpbp4::MerkleBlock> {
fn merge_reveal(self, other: Self) -> Result<Self, reveal::Error> {
self.merge_reveal(other).map_err(reveal::Error::from)
}
}
#[cfg(test)]
mod test {
use std::collections::BTreeMap;
use bitcoin::consensus::deserialize;
use bitcoin::util::psbt::PartiallySignedTransaction;
use strict_encoding::StrictDecode;
use super::*;
use crate::contract::{Genesis, Node};
use crate::NodeId;
static GENESIS: [u8; 2447] = include!("../../test/genesis.in");
static PSBT: [u8; 462] = include!("../../test/test_transaction.psbt");
#[test]
#[ignore]
fn test_psbt() {
let genesis = Genesis::strict_decode(&GENESIS[..]).unwrap();
let contract_id = genesis.contract_id();
let node_id = genesis.node_id();
let source_psbt: PartiallySignedTransaction = deserialize(&PSBT[..]).unwrap();
let witness_psbt = source_psbt.clone();
let mut map: BTreeMap<ContractId, NodeId> = BTreeMap::new();
map.insert(contract_id, node_id);
assert_eq!(
source_psbt.unsigned_tx.output.len(),
witness_psbt.unsigned_tx.output.len()
);
assert_eq!(
source_psbt.unsigned_tx.output[0].value,
witness_psbt.unsigned_tx.output[0].value
);
assert_eq!(
source_psbt.unsigned_tx.output[1].value,
witness_psbt.unsigned_tx.output[1].value
);
}
}