X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fchain%2Ftransaction.rs;h=227afa0de68e35bf8a104ea913f6ce7e2c6b0db0;hb=7f6c31ea15ca0042da0dd50f9e0819065eb00757;hp=615c970f018953c954dcf19d0229ddc86c1630b4;hpb=ca6b44b8cce864bac61a38a967284e8128836cbd;p=rust-lightning diff --git a/src/chain/transaction.rs b/src/chain/transaction.rs index 615c970f..227afa0d 100644 --- a/src/chain/transaction.rs +++ b/src/chain/transaction.rs @@ -1,7 +1,8 @@ use bitcoin::util::hash::Sha256dHash; +use bitcoin::blockdata::transaction::OutPoint as BitcoinOutPoint; /// A reference to a transaction output. -/// Differs from bitcoin::blockdata::transaction::TxOutRef as the index is a u16 instead of usize +/// Differs from bitcoin::blockdata::transaction::OutPoint as the index is a u16 instead of u32 /// due to LN's restrictions on index values. Should reduce (possibly) unsafe conversions this way. #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] pub struct OutPoint { @@ -12,7 +13,7 @@ pub struct OutPoint { } impl OutPoint { - /// Creates a new `OutPoint` from the txid an the index. + /// Creates a new `OutPoint` from the txid and the index. pub fn new(txid: Sha256dHash, index: u16) -> OutPoint { OutPoint { txid, index } } @@ -25,6 +26,13 @@ impl OutPoint { res[31] ^= ((self.index >> 0) & 0xff) as u8; res } + + pub fn into_bitcoin_outpoint(self) -> BitcoinOutPoint { + BitcoinOutPoint { + txid: self.txid, + vout: self.index as u32, + } + } } #[cfg(test)]