Skip to content

Commit

Permalink
Draft a new observeAbortTx semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo committed Oct 28, 2021
1 parent e0b381f commit a3ed7a0
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions hydra-node/src/Hydra/Chain/Direct/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -347,21 +347,33 @@ observeCommitTx ValidatedTx{wits, body} = do
convertUtxo :: OnChain.Utxo -> Maybe (Utxo tx)
convertUtxo = Aeson.decodeStrict' . OnChain.toByteString

-- | Identify an abort tx by trying to decode all redeemers to the right type.
-- This is a very weak observation and should be more concretized.
-- | Identify an abort tx by looking up the input spending the Head output and
-- decoding its redeemer.
-- TODO(SN): make sure this is aborting "the right head / your head"
observeAbortTx :: ValidatedTx Era -> Maybe (OnChainTx tx, OnChainHeadState)
observeAbortTx ValidatedTx{wits} =
case extractTransition of
observeAbortTx ::
-- | A Utxo set to lookup tx inputs
Map (TxIn StandardCrypto) (TxOut Era) ->
ValidatedTx Era ->
Maybe (OnChainTx tx, OnChainHeadState)
observeAbortTx utxo ValidatedTx{wits} = do
-- XXX(SN): not hard-code policyId
txOut <- findScriptOutput utxo . plutusScript $ Head.validatorScript policyId
case decodeHeadRedeemer txOut of
Just Head.Abort -> Just (OnAbortTx, Final)
_ -> Nothing
where
extractTransition = foldr decodeData Nothing redeemerData
decodeHeadRedeemer = undefined

decodeData d s = s <|> fromData (getPlutusData d)

redeemerData = fmap fst . Map.elems . unRedeemers $ txrdmrs wits

findScriptOutput ::
Map (TxIn StandardCrypto) (TxOut Era) ->
Script Era ->
Maybe (TxOut StandardCrypto)
findScriptOutput _script = undefined

-- | Provide a UTXO map for some given OnChainHeadState. At least used by the
-- TinyWallet to lookup inputs.
knownUtxo :: OnChainHeadState -> Map (TxIn StandardCrypto) (TxOut Era)
Expand Down

0 comments on commit a3ed7a0

Please sign in to comment.