Context
I was looking for a simple way to get exact TxOut
on on-chain code to validate if funds are to be unlocked to correct wallet address. While looking in plutus haddoc I have found this function:
{-# INLINABLE findOwnInput #-}
-- | Find the input currently being validated.
findOwnInput :: ScriptContext -> Maybe TxInInfo
findOwnInput ScriptContext{scriptContextTxInfo=TxInfo{txInfoInputs}, scriptContextPurpose=Spending txOutRef} =
find (\TxInInfo{txInInfoOutRef} -> txInInfoOutRef == txOutRef) txInfoInputs
findOwnInput _ = Nothing
This function returns:
-- | An input of a pending transaction.
data TxInInfo = TxInInfo
{ txInInfoOutRef :: TxOutRef
, txInInfoResolved :: TxOut
} deriving stock (Generic, Haskell.Show, Haskell.Eq)
And here is where most of my confusion comes from - getOwnInput
returns TxInInfo
which has TxOut
. All I see is TxIn
is TxOut
.
This makes it really unclear to me exactly which part of locking or unlocking transaction UTXO getOwnInput
function returns.
Lets say that I have 10 Ada
in wallet A
and I'm creating locking transaction TX1
of 2 Ada
to SC1
. The way I see it TX1
should look like this:
- UTXO1 of
10 ADA
is created by taking all the funds fromwallet A
. - UTXO2 of
10 ADA - 2 ADA - fees1
is created and is sent back towallet A
. - UTXO3 of
2 ADA
is created and sent toSC1
.
Lets say that now I'm trying to unlock 2 ADA
from SC1
back to wallet A
by creating TX2
:
- UTXO4
10 ADA - 2 ADA - fees1
are taken fromwallet A
to pay forfees2
- UTXO5
2 ADA
is being taken fromSC1
- UTXO6
2 ADA
are sent towallet A
- UTXO7
10 ADA - 2 ADA - fees1 - fees2
are sent back towallet A
Main question
So my main question is. Which of these UTXOs does the function getOwnInput
return as a txInInfoResolved
when TX2
is created?
Bonus question
When TX2
is created, from Plutus validator point of view, which of UTXOs are TxOut
and which are TxIn
?
pubKeyOutput
returnsNothing
. I suppose it is because UTXO3 goes into smartcontract which doesn't havePubKeyHash
but hasValidatorHash
instead.