Skip to content
This repository was archived by the owner on Aug 11, 2022. It is now read-only.
This repository was archived by the owner on Aug 11, 2022. It is now read-only.

Add AsData x type constructor and functions to work with it #185

@blamario

Description

@blamario

The secret of Plutarch's efficiency comes down to two simple rules:

  • don't generate ridiculous code, and
  • postpone Data decoding as long as possible.

There's not much PlutusTx users can do about the former, though Shrinker can help. The second technique, on the other hand, can be translated to PlutusTx thus:

  1. Introduce AsData type constructor to correspond with Plutarch's PAsData, along with
safeFromData :: UnsafeFromData x => AsData x -> x
safeToData :: ToData x => x -> AsData x
unsafeInjectData :: BuiltinData -> AsData x
forgetData :: AsData x -> BuiltinData
inefficientMapData :: (UnsafeFromData x, ToData y) => (x -> y) -> AsData x -> AsData y
mkTypedValidator :: CompiledCode (AsData (DatumType a) -> AsData (RedeemerType a) -> AsData ScriptContext -> Bool)
                             -> CompiledCode (ValidatorType a -> WrappedValidatorType) -> TypedValidator a
  1. Provide a family of functions that map the AsData ScriptContext to its fields, and same for all the product types it contains. For example
scriptContextTxInfo :: AsData ScriptContext -> AsData TxInfo
txInfoInputs :: AsData TxInfo -> AsData [TxInInfo]

We should be able to generate all of these functions using either Generics.SOP or Template Haskell.

  1. Optionally mirror the collection of other functions that work with ScriptContext, such as
txSignedBy :: AsData TxInfo -> PubKeyHash -> Bool
findDatumHash :: Datum -> AsData TxInfo -> Maybe DatumHash
findOwnInput :: AsData ScriptContext -> Maybe (AsData TxInInfo)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions