lightning/chain/
transaction.rs1use bitcoin::hash_types::Txid;
13use bitcoin::transaction::OutPoint as BitcoinOutPoint;
14use bitcoin::transaction::Transaction;
15
16pub type TransactionData<'a> = [(usize, &'a Transaction)];
45
46#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
51pub struct OutPoint {
52 pub txid: Txid,
54 pub index: u16,
56}
57
58impl OutPoint {
59 pub fn into_bitcoin_outpoint(self) -> BitcoinOutPoint {
64 BitcoinOutPoint {
65 txid: self.txid,
66 vout: self.index as u32,
67 }
68 }
69}
70
71impl core::fmt::Display for OutPoint {
72 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
73 write!(f, "{}:{}", self.txid, self.index)
74 }
75}
76
77impl_writeable!(OutPoint, { txid, index });
78
79#[derive(Debug, Clone)]
80pub(crate) struct MaybeSignedTransaction(pub Transaction);
81
82impl MaybeSignedTransaction {
83 pub fn is_fully_signed(&self) -> bool {
84 !self.0.input.iter().any(|input| input.witness.is_empty())
85 }
86}
87
88#[cfg(test)]
89mod tests {
90 use crate::chain::transaction::OutPoint;
91 use crate::ln::types::ChannelId;
92
93 use bitcoin::transaction::Transaction;
94 use bitcoin::consensus::encode;
95 use bitcoin::hex::FromHex;
96
97 #[test]
98 fn test_channel_id_calculation() {
99 let tx: Transaction = encode::deserialize(&<Vec<u8>>::from_hex("020000000001010e0adef48412e4361325ac1c6e36411299ab09d4f083b9d8ddb55fbc06e1b0c00000000000feffffff0220a1070000000000220020f81d95e040bd0a493e38bae27bff52fe2bb58b93b293eb579c01c31b05c5af1dc072cfee54a3000016001434b1d6211af5551905dc2642d05f5b04d25a8fe80247304402207f570e3f0de50546aad25a872e3df059d277e776dda4269fa0d2cc8c2ee6ec9a022054e7fae5ca94d47534c86705857c24ceea3ad51c69dd6051c5850304880fc43a012103cb11a1bacc223d98d91f1946c6752e358a5eb1a1c983b3e6fb15378f453b76bd00000000").unwrap()[..]).unwrap();
100 assert_eq!(&ChannelId::v1_from_funding_outpoint(OutPoint {
101 txid: tx.compute_txid(),
102 index: 0
103 }).0[..], &<Vec<u8>>::from_hex("3e88dd7165faf7be58b3c5bb2c9c452aebef682807ea57080f62e6f6e113c25e").unwrap()[..]);
104 assert_eq!(&ChannelId::v1_from_funding_outpoint(OutPoint {
105 txid: tx.compute_txid(),
106 index: 1
107 }).0[..], &<Vec<u8>>::from_hex("3e88dd7165faf7be58b3c5bb2c9c452aebef682807ea57080f62e6f6e113c25f").unwrap()[..]);
108 }
109}