Skip to content

Commit

Permalink
Resolve/update TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo committed Jan 26, 2022
1 parent df72d73 commit 6b27b85
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
22 changes: 10 additions & 12 deletions hydra-node/src/Hydra/Chain/Direct/Tx.hs
Expand Up @@ -455,30 +455,28 @@ observeInitTx networkId party (Api.getTxBody . fromLedgerTx -> txBody) = do
convertParty :: OnChain.Party -> Party
convertParty = Party . partyToVerKey

-- | Identify a commit tx by looking for an output which pays to v_commit.
-- | Identify a commit tx by:
--
-- To reconstruct a commit from a commit transaction we need to:
--
-- - Find out which 'initials' is being committed
-- - Find the redeemer corresponding to that 'initial' which contain the
-- output-reference of the commit
-- - Find the outputs which pays to the commit validator
-- - Extract the datum of that output, which contains the output of the commit
-- - Reconstruct the committed UTXO from both values (output ref and output).
-- - Find which 'initial' tx input is being consumed.
-- - Find the redeemer corresponding to that 'initial', which contains the
-- output-reference of the committed utxo.
-- - Find the outputs which pays to the commit validator.
-- - Using the datum of that output, deserialize the comitted output.
-- - Reconstruct the committed Utxo from both values (output ref and output).
observeCommitTx ::
Api.NetworkId ->
-- TODO: This type may be too large for this function, we only probably need
-- just the TxIn.
-- | Known (remaining) initial tx inputs.
[TxIn StandardCrypto] ->
ValidatedTx Era ->
Maybe (OnChainTx CardanoTx, (TxIn StandardCrypto, TxOut Era, Data Era))
observeCommitTx networkId initials (Api.getTxBody . fromLedgerTx -> txBody) = do
observeCommitTx networkId (fmap Api.fromLedgerTxIn -> initials) (Api.getTxBody . fromLedgerTx -> txBody) = do
initialTxIn <- findInitialTxIn
initialRedeemer <- findRedeemerSpending txBody initialTxIn
mCommittedTxIn <- matchCommit initialRedeemer

(commitIn, commitOut) <- Api.findTxOutByAddress commitAddress txBody
dat <- getDatum commitOut
-- TODO: This 'party' would be available from the spent 'initial' utxo (PT eventually)
(party, _, serializedTxOut) <- fromData @(DatumType Commit.Commit) $ toPlutusData dat
let mCommittedTxOut = convertTxOut serializedTxOut

Expand Down
7 changes: 2 additions & 5 deletions hydra-plutus/src/Hydra/Contract/Commit.hs
Expand Up @@ -25,11 +25,8 @@ PlutusTx.unstableMakeIsData ''SerializedTxOut
instance Eq SerializedTxOut where
SerializedTxOut bs == SerializedTxOut bs' = bs == bs'

-- TODO: Having the 'TxOutRef' on-chain is not necessary but it is convenient
-- for the off-chain code to reconstrut the commit UTXO.
--
-- Ideally, since the TxOutRef is already present in the redeemer for the
-- initial validator, the off-chain code could get it from there.
-- TODO: Is the 'Party' here even used? If yes, why is it not a PubKeyHash /
-- cardano-credential?
instance Scripts.ValidatorTypes Commit where
type DatumType Commit = (Party, ValidatorHash, Maybe SerializedTxOut)
type RedeemerType Commit = ()
Expand Down

0 comments on commit 6b27b85

Please sign in to comment.