Skip to content

Commit

Permalink
Keep abortTx valid by distinguishing initial redeemer as Commit | Abort
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo committed Jan 26, 2022
1 parent 4a35e66 commit 2c7422e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions hydra-node/src/Hydra/Chain/Direct/Tx.hs
Expand Up @@ -196,7 +196,7 @@ commitTx networkId party utxo (initialInput, vkh) =
initialDatum =
Api.mkDatumForTxIn $ Initial.datum vkh
initialRedeemer =
Api.mkRedeemerForTxIn $ Initial.redeemer ()
Api.mkRedeemerForTxIn $ Initial.redeemer Initial.Commit

commitOutput =
Api.TxOut commitAddress commitValue commitDatum
Expand Down Expand Up @@ -398,7 +398,7 @@ abortTx networkId (Api.fromLedgerTxIn -> headInput, Api.fromLedgerData -> headDa
initialScript =
Api.fromPlutusScript Initial.validatorScript
initialRedeemer =
Api.mkRedeemerForTxIn $ Initial.redeemer ()
Api.mkRedeemerForTxIn $ Initial.redeemer Initial.Abort

-- * Observe Hydra Head transactions

Expand Down
14 changes: 11 additions & 3 deletions hydra-plutus/src/Hydra/Contract/Initial.hs
Expand Up @@ -18,9 +18,15 @@ import PlutusTx.IsData.Class (ToData (..))

data Initial

data InitialRedeemer
= Abort
| Commit

PlutusTx.unstableMakeIsData ''InitialRedeemer

instance Scripts.ValidatorTypes Initial where
type DatumType Initial = PubKeyHash
type RedeemerType Initial = ()
type RedeemerType Initial = InitialRedeemer

validator ::
-- | Commit validator
Expand All @@ -29,8 +35,10 @@ validator ::
RedeemerType Initial ->
ScriptContext ->
Bool
validator commitValidator _datum _redeemer context@ScriptContext{scriptContextTxInfo = txInfo} =
checkOutputValue
validator commitValidator _datum red context@ScriptContext{scriptContextTxInfo = txInfo} =
case red of
Abort -> True
Commit -> checkOutputValue
where
checkOutputValue =
traceIfFalse "commitLockedValue does not match" $
Expand Down

0 comments on commit 2c7422e

Please sign in to comment.