Merge pull request #33 from jeandudey/funding_txo
[rust-lightning] / src / chain / transaction.rs
1 use bitcoin::util::hash::Sha256dHash;
2 use bitcoin::util::uint::Uint256;
3
4 /// A reference to a transaction output.
5 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
6 pub struct OutPoint {
7         /// The referenced transaction's txid.
8         pub txid: Sha256dHash,
9         /// The index of the referenced output in its transaction's vout.
10         pub index: u16,
11 }
12
13 impl OutPoint {
14         /// Creates a new `OutPoint` from the txid an the index.
15         pub fn new(txid: Sha256dHash, index: u16) -> OutPoint {
16                 OutPoint { txid, index }
17         }
18
19     /// Convert an `OutPoint` to a lightning channel id.
20     pub fn to_channel_id(&self) -> Uint256 {
21         // TODO: or le?
22         self.txid.into_be() ^ Uint256::from_u64(self.index as u64).unwrap()
23     }
24 }