diff --git a/payjoin-ffi/csharp/UnitTests.cs b/payjoin-ffi/csharp/UnitTests.cs index 655286fa5..01592395f 100644 --- a/payjoin-ffi/csharp/UnitTests.cs +++ b/payjoin-ffi/csharp/UnitTests.cs @@ -305,6 +305,30 @@ public void InputPairRejectsInvalidOutpoint() }); } + [Fact] + public void InputPairExposesOutpoint() + { + const string txid = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + const uint vout = 7; + var txin = new TxIn( + new OutPoint(txid, vout), + new byte[] {}, + uint.MaxValue, + new byte[][] {} + ); + var psbtIn = new PsbtInput( + new TxOut(12345, Convert.FromHexString("00140000000000000000000000000000000000000000")), + null, + null + ); + using var inputPair = new InputPair(txin, psbtIn, null); + + var outpoint = inputPair.Outpoint(); + + Assert.Equal(txid, outpoint.txid); + Assert.Equal(vout, outpoint.vout); + } + [Fact] public void SenderBuilderRejectsBadPsbt() { diff --git a/payjoin-ffi/src/receive/mod.rs b/payjoin-ffi/src/receive/mod.rs index e560c1806..3295c7779 100644 --- a/payjoin-ffi/src/receive/mod.rs +++ b/payjoin-ffi/src/receive/mod.rs @@ -1114,6 +1114,9 @@ impl InputPair { .map(Self) .map_err(|err| InputPairError::InvalidPsbtInput(Arc::new(err.into()))) } + + /// Returns the outpoint spent by this input pair. + pub fn outpoint(&self) -> OutPoint { self.0.outpoint().into() } } impl From for payjoin::receive::InputPair { diff --git a/payjoin/src/core/receive/mod.rs b/payjoin/src/core/receive/mod.rs index 259e91422..b665856b7 100644 --- a/payjoin/src/core/receive/mod.rs +++ b/payjoin/src/core/receive/mod.rs @@ -216,6 +216,9 @@ impl InputPair { Self::new_segwit_input_pair(txout, outpoint, Some(expected_weight)) } + /// Returns the outpoint spent by this input pair. + pub fn outpoint(&self) -> OutPoint { self.txin.previous_output } + pub(crate) fn previous_txout(&self) -> TxOut { InternalInputPair::from(self) .previous_txout() @@ -541,6 +544,18 @@ pub(crate) mod tests { assert_eq!(input_pair.expected_weight, expected_satifiability_weight); } + #[test] + fn input_pair_outpoint_returns_previous_output() { + let txout = TxOut { + value: Amount::from_sat(123), + script_pubkey: ScriptBuf::new_p2wpkh(&WPubkeyHash::from_byte_array(DUMMY20)), + }; + let outpoint = OutPoint { txid: Txid::from_byte_array(DUMMY32), vout: 31 }; + let input_pair = InputPair::new_p2wpkh(txout, outpoint).unwrap(); + + assert_eq!(input_pair.outpoint(), outpoint); + } + #[test] fn create_p2pkh_input_pair() { let p2sh_txout = TxOut {