-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a wrapper module with conveniency type classes (#411)
This aims at simplifying the Output.hs module and the overall usability of cooked-validators by providing various type classes to summarize existing features of plutus elements. As a side effect, this also: - updates the README - updates our dependency to cardano-node-emulator - adds a few utxoSearches - adds the ExtendedDefaultRules language extension by default
- Loading branch information
Showing
42 changed files
with
538 additions
and
658 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
-- | Re-exports all conversion type classes and instances | ||
module Cooked.Conversion (module X) where | ||
|
||
import Cooked.Conversion.ToAddress as X | ||
import Cooked.Conversion.ToCredential as X | ||
import Cooked.Conversion.ToOutputDatum as X | ||
import Cooked.Conversion.ToPubKeyHash as X | ||
import Cooked.Conversion.ToScript as X | ||
import Cooked.Conversion.ToScriptHash as X | ||
import Cooked.Conversion.ToValue as X |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-- | Objects from which addresses can be extracted | ||
module Cooked.Conversion.ToAddress where | ||
|
||
import Cooked.Wallet | ||
import Plutus.Script.Utils.Typed qualified as Script | ||
import PlutusLedgerApi.V3 qualified as Api | ||
|
||
class ToAddress a where | ||
toAddress :: a -> Api.Address | ||
|
||
instance ToAddress Wallet where | ||
toAddress = walletAddress | ||
|
||
instance ToAddress Api.Address where | ||
toAddress = id | ||
|
||
instance ToAddress (Script.TypedValidator a) where | ||
toAddress = Script.validatorAddress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
-- | Objects from which a credential can be extracted | ||
module Cooked.Conversion.ToCredential where | ||
|
||
import Cooked.Conversion.ToScriptHash | ||
import Plutus.Script.Utils.Scripts qualified as Script | ||
import Plutus.Script.Utils.Typed qualified as Script | ||
import PlutusLedgerApi.V3 qualified as Api | ||
|
||
class ToCredential a where | ||
toCredential :: a -> Api.Credential | ||
|
||
instance ToCredential Api.Credential where | ||
toCredential = id | ||
|
||
instance ToCredential Api.PubKeyHash where | ||
toCredential = Api.PubKeyCredential | ||
|
||
instance ToCredential Api.ScriptHash where | ||
toCredential = Api.ScriptCredential | ||
|
||
instance ToCredential Script.ValidatorHash where | ||
toCredential = toCredential . toScriptHash | ||
|
||
instance ToCredential (Script.Versioned Script.Script) where | ||
toCredential = toCredential . toScriptHash | ||
|
||
instance ToCredential (Script.Versioned Script.Validator) where | ||
toCredential = toCredential . toScriptHash | ||
|
||
instance ToCredential (Script.TypedValidator a) where | ||
toCredential = toCredential . toScriptHash | ||
|
||
instance ToCredential (Script.Versioned Script.MintingPolicy) where | ||
toCredential = toCredential . toScriptHash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
-- | Objects from which an output datum can be extracted | ||
module Cooked.Conversion.ToOutputDatum where | ||
|
||
import PlutusLedgerApi.V3 qualified as Api | ||
|
||
class ToOutputDatum a where | ||
toOutputDatum :: a -> Api.OutputDatum | ||
|
||
instance ToOutputDatum Api.OutputDatum where | ||
toOutputDatum = id | ||
|
||
instance ToOutputDatum Api.Datum where | ||
toOutputDatum = Api.OutputDatum | ||
|
||
instance ToOutputDatum () where | ||
toOutputDatum = const Api.NoOutputDatum | ||
|
||
instance ToOutputDatum Api.DatumHash where | ||
toOutputDatum = Api.OutputDatumHash | ||
|
||
instance ToOutputDatum Api.BuiltinData where | ||
toOutputDatum = toOutputDatum . Api.Datum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- | Objects from which a public key hash can be extracted | ||
module Cooked.Conversion.ToPubKeyHash where | ||
|
||
import Cooked.Wallet | ||
import PlutusLedgerApi.V3 qualified as Api | ||
|
||
class ToPubKeyHash a where | ||
toPubKeyHash :: a -> Api.PubKeyHash | ||
|
||
instance ToPubKeyHash Api.PubKeyHash where | ||
toPubKeyHash = id | ||
|
||
instance ToPubKeyHash Wallet where | ||
toPubKeyHash = walletPKHash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-- | Objects from which a versioned script can be extracted | ||
module Cooked.Conversion.ToScript where | ||
|
||
import Plutus.Script.Utils.Scripts qualified as Script | ||
import Plutus.Script.Utils.Typed qualified as Script | ||
|
||
class ToScript a where | ||
toScript :: a -> Script.Versioned Script.Script | ||
|
||
instance ToScript (Script.Versioned Script.Script) where | ||
toScript = id | ||
|
||
instance ToScript (Script.Versioned Script.Validator) where | ||
toScript (Script.Versioned (Script.Validator script) version) = Script.Versioned script version | ||
|
||
instance ToScript (Script.TypedValidator a) where | ||
toScript = toScript . Script.vValidatorScript | ||
|
||
instance ToScript (Script.Versioned Script.MintingPolicy) where | ||
toScript (Script.Versioned (Script.MintingPolicy script) version) = Script.Versioned script version |
Oops, something went wrong.