liqwid-plutarch-extra-3.21.1: A collection of Plutarch extras from Liqwid Labs
Safe HaskellSafe-Inferred
LanguageHaskell2010

Plutarch.Extra.IsData

Synopsis

PlutusTx ToData/FromData derive-wrappers

newtype ProductIsData (a :: Type) Source #

Wrapper for deriving ToData, FromData using the List constructor of Data to represent a Product type.

It is recommended to use PlutusTypeDataList when deriving PlutusType as it provides some basic safety by ensuring Plutarch types have an Inner type of PDataRecord.

Uses gProductToBuiltinData, gproductFromBuiltinData.

Example

import qualified Generics.SOP as SOP

data Foo =
  Foo Integer [Integer]
  deriving stock (Generic)
  deriving anyclass (SOP.Generic)
  deriving (FromData, ToData) via (ProductIsData Foo)
  deriving (PConstantDecl) via (DerivePConstantViaDataList Foo PFoo)

instance PUnsafeLiftDecl PFoo where type PLifted PFoo = Foo

newtype PFoo s
    = PFoo
      ( Term s
          ( PDataRecord
              '[ "abc" ':= PInteger
               , "def" ':= PBuiltinList (PAsData PInteger)
               ]
          )
      )
  deriving stock (Generic)
  deriving anyclass (SOP.Generic)
  deriving anyclass (PlutusType, PIsData)

instance DerivePlutusType PFoo where
   type DPTStrat _ = PlutusTypeDataList

Since: 3.8.0

Constructors

ProductIsData a 

Instances

Instances details
(IsProductType a repr, All FromData repr) => FromData (ProductIsData a) Source #

Since: 1.1.0

Instance details

Defined in Plutarch.Extra.IsData

(IsProductType a repr, All ToData repr) => ToData (ProductIsData a) Source #

Since: 1.1.0

Instance details

Defined in Plutarch.Extra.IsData

(IsProductType a repr, All UnsafeFromData repr) => UnsafeFromData (ProductIsData a) Source #

Since: 1.1.0

Instance details

Defined in Plutarch.Extra.IsData

newtype EnumIsData (a :: Type) Source #

Wrapper for deriving ToData, FromData using an Integer representation via Enum.

Since: 1.1.0

Constructors

EnumIsData a 

Instances

Instances details
Enum a => FromData (EnumIsData a) Source #

Since: 1.1.0

Instance details

Defined in Plutarch.Extra.IsData

Enum a => ToData (EnumIsData a) Source #

Since: 1.1.0

Instance details

Defined in Plutarch.Extra.IsData

Enum a => UnsafeFromData (EnumIsData a) Source #

Since: 1.1.0

Instance details

Defined in Plutarch.Extra.IsData

unProductIsData :: forall (a :: Type). ProductIsData a -> a Source #

Since: 3.8.0

Plutarch PIsData/PlutusType derive-wrappers

newtype DerivePConstantViaEnum (h :: Type) (p :: S -> Type) Source #

Wrapper for deriving PConstantDecl using an Integer representation via Enum.

Since: 1.1.0

Constructors

DerivePConstantEnum h 

Plutarch deriving strategy

Functions for PEnumData types

pmatchEnum :: forall (a :: Type) (b :: S -> Type) (s :: S). (Bounded a, Enum a) => Term s PInteger -> (a -> Term s b) -> Term s b Source #

Pattern match over the integer-repr of a Bounded Enum type.

Since: 1.1.0

pmatchEnumFromData :: forall (a :: Type) (b :: S -> Type) (s :: S). (Bounded a, Enum a) => Term s PData -> (Maybe a -> Term s b) -> Term s b Source #

Pattern match PData as a Bounded Enum. Useful for Redeemers.

Since: 1.1.0