Skip to content

Commit

Permalink
Update Prism example contract by removing the RPC mechanism of the cr…
Browse files Browse the repository at this point in the history
…edential manager.

Co-authored-by: Jann Mueller <jann.mueller@iohk.io>
  • Loading branch information
koslambrou and j-mueller committed Jun 4, 2021
1 parent 8868f4f commit 932fcb1
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 344 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 20 additions & 23 deletions playground-common/src/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,29 @@ module Schema
, formArgumentToJson
) where

import Crypto.Hash (Digest, SHA256)
import Data.Aeson (FromJSON, ToJSON, toJSON)
import qualified Data.Aeson as JSON
import Data.Bifunctor (first)
import Data.Eq.Deriving (deriveEq1)
import Data.Functor.Foldable (Fix (Fix), cata)
import qualified Data.HashMap.Strict as HashMap
import Crypto.Hash (Digest, SHA256)
import Data.Aeson (FromJSON, ToJSON, toJSON)
import qualified Data.Aeson as JSON
import Data.Bifunctor (first)
import Data.Eq.Deriving (deriveEq1)
import Data.Functor.Foldable (Fix (Fix), cata)
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Map
import Data.Proxy (Proxy)
import Data.Text (Text)
import qualified Data.Text as Text
import Data.UUID (UUID)
import GHC.Generics (C1, Constructor, D1, Generic, K1 (K1), M1 (M1), Rec0, Rep, S1, Selector,
U1, conIsRecord, conName, from, selName, (:*:) ((:*:)), (:+:) (L1, R1))
import Ledger (Ada, AssetClass, CurrencySymbol, DatumHash, Interval, PubKey, PubKeyHash,
RedeemerHash, Signature, Slot, SlotRange, TokenName, ValidatorHash, Value)
import Ledger.Bytes (LedgerBytes)
import Plutus.Contract.Effects.RPC (RPCParams)
import Data.Proxy (Proxy)
import Data.Text (Text)
import qualified Data.Text as Text
import Data.UUID (UUID)
import GHC.Generics (C1, Constructor, D1, Generic, K1 (K1), M1 (M1), Rec0, Rep, S1, Selector, U1,
conIsRecord, conName, from, selName, (:*:) ((:*:)), (:+:) (L1, R1))
import Ledger (Ada, AssetClass, CurrencySymbol, DatumHash, Interval, PubKey, PubKeyHash,
RedeemerHash, Signature, Slot, SlotRange, TokenName, ValidatorHash, Value)
import Ledger.Bytes (LedgerBytes)
import qualified PlutusTx.AssocMap
import qualified PlutusTx.Prelude as P
import Wallet.Emulator.Wallet (Wallet)
import Wallet.Types (ContractInstanceId)
import qualified PlutusTx.Prelude as P
import Wallet.Emulator.Wallet (Wallet)
import Wallet.Types (ContractInstanceId)

import Text.Show.Deriving (deriveShow1)
import Text.Show.Deriving (deriveShow1)

{-# ANN module ("HLint: ignore Avoid restricted function" :: Text)
#-}
Expand Down Expand Up @@ -397,5 +396,3 @@ deriving anyclass instance ToArgument Wallet
deriving anyclass instance ToArgument Ada

deriving anyclass instance ToSchema ContractInstanceId

deriving anyclass instance ToSchema a => ToSchema (RPCParams a)
1 change: 0 additions & 1 deletion plutus-contract/plutus-contract.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ library
Plutus.Contract.Effects.AwaitSlot
Plutus.Contract.Effects.AwaitTxConfirmed
Plutus.Contract.Effects.Instance
Plutus.Contract.Effects.RPC
Plutus.Contract.Effects.ExposeEndpoint
Plutus.Contract.Effects.Notify
Plutus.Contract.Effects.OwnPubKey
Expand Down
4 changes: 0 additions & 4 deletions plutus-use-cases/plutus-use-cases.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ library
Plutus.Contracts.PingPong
Plutus.Contracts.Prism
Plutus.Contracts.Prism.Credential
Plutus.Contracts.Prism.CredentialManager
Plutus.Contracts.Prism.STO
Plutus.Contracts.Prism.Mirror
Plutus.Contracts.Prism.StateMachine
Plutus.Contracts.Prism.Unlock
Plutus.Contracts.PubKey
Plutus.Contracts.RPC
Plutus.Contracts.Stablecoin
Plutus.Contracts.Swap
Plutus.Contracts.Uniswap
Expand Down Expand Up @@ -115,7 +113,6 @@ test-suite plutus-use-cases-test
Spec.PubKey
Spec.Prism
Spec.Rollup
Spec.RPC
Spec.Stablecoin
Spec.TokenAccount
Spec.Vesting
Expand Down Expand Up @@ -181,7 +178,6 @@ executable plutus-use-cases-scripts
Spec.PubKey
Spec.Prism
Spec.Rollup
Spec.RPC
Spec.Stablecoin
Spec.TokenAccount
Spec.Vesting
Expand Down
16 changes: 4 additions & 12 deletions plutus-use-cases/src/Plutus/Contracts/Prism.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,16 @@ module Plutus.Contracts.Prism(
, Credential(..)
, UserCredential(..)
, CredentialAuthority(..)
, CredentialManagerSchema
, CredentialManagerError(..)
, credentialManager
-- * all-in-one
, Role(..)
, PrismSchema
, PrismError(..)
, contract
) where

import Data.Aeson (FromJSON, ToJSON)
import GHC.Generics (Generic)
import Data.Aeson (FromJSON, ToJSON)
import GHC.Generics (Generic)
import Plutus.Contracts.Prism.Credential
import Plutus.Contracts.Prism.CredentialManager
import Plutus.Contracts.Prism.Mirror
import Plutus.Contracts.Prism.StateMachine
import Plutus.Contracts.Prism.Unlock
Expand All @@ -77,16 +73,14 @@ import Plutus.Contract

-- | The roles that we pass to 'contract'.
data Role
= CredMan -- ^ The 'credentialManager' contract
| Mirror -- ^ The 'mirror' contract
= Mirror -- ^ The 'mirror' contract
| UnlockSTO -- ^ The 'subscribeSTO' contract
| UnlockExchange -- ^ The 'unlockExchange' contract
deriving stock (Eq, Generic, Show)
deriving anyclass (ToJSON, FromJSON)

type PrismSchema =
CredentialManagerSchema
.\/ MirrorSchema
MirrorSchema
.\/ STOSubscriberSchema
.\/ UnlockExchangeSchema
.\/ Endpoint "role" Role
Expand All @@ -97,7 +91,6 @@ type PrismSchema =
data PrismError =
UnlockSTOErr UnlockError
| MirrorErr MirrorError
| CredManErr CredentialManagerError
| EPError ContractError
| UnlockExchangeErr UnlockError
deriving stock (Eq, Generic, Show)
Expand All @@ -111,7 +104,6 @@ contract :: Contract () PrismSchema PrismError ()
contract = do
r <- mapError EPError $ endpoint @"role"
case r of
CredMan -> mapError CredManErr credentialManager
Mirror -> mapError MirrorErr mirror
UnlockSTO -> mapError UnlockSTOErr subscribeSTO
UnlockExchange -> mapError UnlockExchangeErr unlockExchange
2 changes: 1 addition & 1 deletion plutus-use-cases/src/Plutus/Contracts/Prism/Credential.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import qualified Ledger.Typed.Scripts as Scripts
import Ledger.Value (TokenName, Value)
import qualified Ledger.Value as Value
import Plutus.Contracts.TokenAccount (Account (..))
import qualified PlutusTx as PlutusTx
import qualified PlutusTx
import PlutusTx.Prelude
import qualified Prelude as Haskell
import Schema (ToSchema)
Expand Down
85 changes: 0 additions & 85 deletions plutus-use-cases/src/Plutus/Contracts/Prism/CredentialManager.hs

This file was deleted.

6 changes: 4 additions & 2 deletions plutus-use-cases/src/Plutus/Contracts/Prism/Mirror.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
Expand Down Expand Up @@ -60,8 +59,9 @@ mirror ::
)
=> Contract w s MirrorError ()
mirror = do
logInfo @String "mirror started"
authority <- mapError SetupError $ CredentialAuthority . pubKeyHash <$> ownPubKey
forever $ (createTokens authority `select` revokeToken authority)
forever (createTokens authority `select` revokeToken authority)

createTokens ::
( HasEndpoint "issue" CredentialOwnerReference s
Expand All @@ -70,7 +70,9 @@ createTokens ::
=> CredentialAuthority
-> Contract w s MirrorError ()
createTokens authority = do
logInfo @String "waiting for 'issue' call"
CredentialOwnerReference{coTokenName, coOwner} <- mapError IssueEndpointError $ endpoint @"issue"
logInfo @String "Endpoint 'issue' called"
let pk = Credential.unCredentialAuthority authority
lookups = Constraints.monetaryPolicy (Credential.policy authority)
<> Constraints.ownPubKeyHash pk
Expand Down
2 changes: 1 addition & 1 deletion plutus-use-cases/src/Plutus/Contracts/Prism/STO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import Ledger.Scripts (MonetaryPolicy, mkMonetaryPolicyScript, m
import qualified Ledger.Typed.Scripts as Scripts
import Ledger.Value (TokenName, Value)
import qualified Ledger.Value as Value
import qualified PlutusTx as PlutusTx
import qualified PlutusTx
import PlutusTx.Prelude
import qualified Prelude as Haskell

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import Plutus.Contract.StateMachine (State (..), StateMachine (..
import qualified Plutus.Contract.StateMachine as StateMachine
import Plutus.Contracts.Prism.Credential (Credential (..), CredentialAuthority (..))
import qualified Plutus.Contracts.Prism.Credential as Credential
import qualified PlutusTx as PlutusTx
import qualified PlutusTx
import PlutusTx.Prelude
import qualified Prelude as Haskell

Expand Down
Loading

0 comments on commit 932fcb1

Please sign in to comment.