plutus icon indicating copy to clipboard operation
plutus copied to clipboard

No instance for ‘PlutusTx.Eq.Eq ScriptPurpose’ arising from a use of ‘lookup’

Open zlonast opened this issue 1 year ago • 1 comments

Summary

Сan you tell me where I'm wrong in my wishes? I want to do lookup (Rewarding sc) (txInfoRedeemers $ scriptContextTxInfo ctx), but in pr 6173 delete instance for PlutusTx.Eq.Eq ScriptPurpose

Steps to reproduce the behavior

add line to plutuscript lookup (Rewarding $ ScriptCredential $ ScriptHash hash) (txInfoRedeemers $ scriptContextTxInfo ctx)

Actual Result

error

Expected Result

no errors

Describe the approach you would take to fix this

Bring back the behavior that was there before?

System info

os: Ubuntu 22.04.3 plutus-core: 1.30

zlonast avatar Jul 01 '24 11:07 zlonast

@ana-pantilie you're probably equipped best to answer this one.

effectfully avatar Jul 01 '24 12:07 effectfully

ScriptPurpose doesn't have an Eq instance anymore because in the case of Proposing scripts we would need to be able to compare Maps, which we decided we cannot do efficiently. @zlonast can you use Foldable.find instead?

ana-pantilie avatar Jul 09 '24 12:07 ana-pantilie

Do I understand correctly that you are suggesting something like that? @ana-pantilie

{-# INLINABLE eqCredential #-}
eqCredential :: Credential -> ScriptPurpose -> Bool
eqCredential a (Rewarding b) = a PlutusTx.== b
eqCredential _ _ = Haskell.False
find (eqCredential sc) (keys $ txInfoRedeemers $ scriptContextTxInfo ctx)

zlonast avatar Jul 09 '24 13:07 zlonast

@zlonast yes that's what I was thinking of.

ana-pantilie avatar Jul 09 '24 13:07 ana-pantilie

Sounds like there's a reasonable workaround and we aren't going to do anything about the issue otherwise, hence I'm closing it. Do feel free to reopen if you feel otherwise.

effectfully avatar Jul 10 '24 10:07 effectfully

instance PlutusTx.Eq.Eq ScriptPurpose where 
  (==) a b = PlutusTx.toBuiltinData a == PlutusTx.toBuiltinData b

colll78 avatar Mar 11 '25 23:03 colll78