1

I am using the following function from the Plutus pioneer program:

stakeReferenceLedgerToPlutus :: Ledger.StakeReference StandardCrypto -> Maybe Plutus.StakingCredential
stakeReferenceLedgerToPlutus (StakeRefPtr (Ptr (SlotNo x) y z)) = Just $ StakingPtr (fromIntegral x) (fromIntegral y) (fromIntegral z)

But the latest release of Plutus-apps seems to require a change, because fromIntegral y does not work anymore. See error below:

error:
    • No instance for (Integral Cardano.Ledger.BaseTypes.TxIx)
        arising from a use of ‘fromIntegral’
    • In the second argument of ‘StakingPtr’, namely ‘(fromIntegral y)’

The same is true for fromIntegral z but for Cardano.Ledger.BaseTypes.CertIx.

Any help is appreciated.

1 Answer 1

2

The problem is that on the LHS you have:

StakeRefPtr (Ptr (SlotNo x) y z)

but StakeRefPtr is defined (in cardano-ledger repo, file libs/cardano-ledger-core/src/Cardano/Ledger/Credential.hs) as:

   | StakeRefPtr !Ptr

and Ptr is defined as:

data Ptr = Ptr !SlotNo !TxIx !CertIx

and TxIx is defined as:

newtype TxIx = TxIx Word64

That means, to get your code closer to working you should try:

stakeReferenceLedgerToPlutus :: Ledger.StakeReference StandardCrypto -> Maybe Plutus.StakingCredential
stakeReferenceLedgerToPlutus (StakeRefPtr (Ptr (SlotNo x) (TxIx y) z)) = Just $ StakingPtr (fromIntegral x) (fromIntegral y) (fromIntegral z)

You probably also need to do the same for the z which is defined as a:

newtype CertIx = CertIx Word64
1
  • 1
    Thanks! Pattern matching to get the wrapped type makes complete sense.
    – Will
    Sep 24, 2022 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.