Skip to content

Commit

Permalink
Merge branch 'master' into SCP-1751-keep-simulation-state
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoerdvisscher committed Oct 14, 2021
2 parents d17083a + 5197c90 commit a9ce8e3
Show file tree
Hide file tree
Showing 195 changed files with 2,592 additions and 1,650 deletions.
10 changes: 9 additions & 1 deletion doc/plutus/troubleshooting.rst
Expand Up @@ -26,7 +26,15 @@ Some things you can do to fix it:
Some more details are in `the plutus-tx readme <https://github.com/input-output-hk/plutus/tree/master/plutus-tx#building-projects-with-plutus-tx>`_.

If you don't need the plugin to succeed, f.e. when Haddock is building documentation,
you can pass the GHC option ``-fplugin-opt Plutus.Tx.Plugin:defer-errors``.
you can pass the GHC option ``-fplugin-opt Plutus.Tx.Plugin:defer-errors`` as a cli parameter::

cabal repl --ghc-options -fplugin-opt PlutusTx.Plugin:defer-errors plutus-contract

or add the following lines for your ``package-name`` to ``cabal.project``::

package your-package
haddock-options: "--optghc=-fplugin-opt PlutusTx.Plugin:defer-errors"


.. note::
The recommended way to build documentation is with ``nix-build default.nix -A docs.site``
Expand Down
7 changes: 2 additions & 5 deletions doc/plutus/tutorials/BasicApps.hs
Expand Up @@ -93,12 +93,9 @@ unlock = endpoint @"unlock" (unlockFunds . mkSplitData)

mkSplitData :: LockArgs -> SplitData
mkSplitData LockArgs{recipient1Wallet, recipient2Wallet, totalAda} =
let convert :: Wallet -> PubKeyHash
convert = pubKeyHash . walletPubKey
in
SplitData
{ recipient1 = convert recipient1Wallet
, recipient2 = convert recipient2Wallet
{ recipient1 = walletPubKeyHash recipient1Wallet
, recipient2 = walletPubKeyHash recipient2Wallet
, amount = totalAda
}

Expand Down
2 changes: 1 addition & 1 deletion doc/plutus/tutorials/basic-apps.rst
Expand Up @@ -114,7 +114,7 @@ Next you need to turn the two ``Wallet`` values into their public key hashes so
:start-after: BLOCK6
:end-before: BLOCK7

Note that the :hsobj:`Wallet.Emulator.Wallet.walletPubKey` function and the :hsobj:`Wallet.Emulator.Wallet.Wallet` type are only available in the simulated environment used by the Plutus playground and by Plutus tests.
Note that the :hsobj:`Wallet.Emulator.Wallet.walletPubKeyHash` function and the :hsobj:`Wallet.Emulator.Wallet.Wallet` type are only available in the simulated environment used by the Plutus playground and by Plutus tests.
A real Plutus app would use the metadata server or a custom lookup function for such conversions.

Locking the funds
Expand Down
12 changes: 12 additions & 0 deletions marlowe-dashboard-client/spago-packages.nix
Expand Up @@ -977,6 +977,18 @@ let
installPhase = "ln -s $src $out";
};

"rationals" = pkgs.stdenv.mkDerivation {
name = "rationals";
version = "v5.0.0";
src = pkgs.fetchgit {
url = "https://github.com/anttih/purescript-rationals.git";
rev = "8c52d8cc891d1223150a31416220aa9b99404442";
sha256 = "1idvjvvx5kwmi8kj2ps95bcvlsgij1xgin4jfw3rmcqd930wqq6q";
};
phases = "installPhase";
installPhase = "ln -s $src $out";
};

"record" = pkgs.stdenv.mkDerivation {
name = "record";
version = "v2.0.2";
Expand Down
1 change: 1 addition & 0 deletions marlowe-dashboard-client/spago.dhall
Expand Up @@ -15,6 +15,7 @@ You can edit this file as you like.
, "halogen"
, "markdown"
, "node-fs"
, "numerics"
, "now"
, "prelude"
, "psci-support"
Expand Down
2 changes: 1 addition & 1 deletion marlowe-dashboard-client/src/API/Url.purs
Expand Up @@ -22,4 +22,4 @@ instance contractInstanceIdToUrlPiece :: ToUrlPiece ContractInstanceId where
toUrlPiece (ContractInstanceId { unContractInstanceId: JsonUUID uuid }) = UUID.toString uuid

instance walletToUrlPiece :: ToUrlPiece Wallet where
toUrlPiece (Wallet { getWalletId }) = show getWalletId
toUrlPiece (Wallet { getWalletId }) = getWalletId
21 changes: 14 additions & 7 deletions marlowe-dashboard-client/src/Bridge.purs
Expand Up @@ -12,10 +12,12 @@ import Data.BigInteger (BigInteger)
import Data.Json.JsonUUID (JsonUUID(..))
import Data.Lens (Iso', iso)
import Data.Map (Map, fromFoldable, toUnfoldable) as Front
import Data.Maybe (Maybe)
import Data.Tuple (Tuple)
import Data.Tuple.Nested ((/\))
import Data.Json.JsonNTuple (JsonNTuple(..))
import Marlowe.PAB (PlutusAppId(..)) as Front
import Marlowe.Semantics (Assets(..), Slot(..)) as Front
import Marlowe.Semantics (Assets(..), Slot(..), PubKeyHash) as Front
import Network.RemoteData (RemoteData)
import Plutus.V1.Ledger.Crypto (PubKey(..), PubKeyHash(..)) as Back
import Plutus.V1.Ledger.Slot (Slot(..)) as Back
Expand All @@ -24,7 +26,7 @@ import PlutusTx.AssocMap (Map, fromTuples, toTuples) as Back
import Servant.PureScript.Ajax (AjaxError)
import Wallet.Emulator.Wallet (Wallet(..)) as Back
import Wallet.Types (ContractInstanceId(..)) as Back
import Contacts.Types (PubKeyHash(..), Wallet(..), WalletInfo(..)) as Front
import Contacts.Types (Wallet(..), WalletInfo(..)) as Front

{-
Note [JSON communication]: To ensure the client and the PAB server understand each other, they have
Expand Down Expand Up @@ -79,6 +81,10 @@ instance eitherBridge :: (Bridge a c, Bridge b d) => Bridge (Either a b) (Either
toFront = bimap toFront toFront
toBack = bimap toBack toBack

instance maybeBridge :: (Bridge a b) => Bridge (Maybe a) (Maybe b) where
toFront = map toFront
toBack = map toBack

instance mapBridge :: (Ord a, Ord c, Bridge a c, Bridge b d) => Bridge (Back.Map a b) (Front.Map c d) where
toFront map = Front.fromFoldable $ toFront <$> Back.toTuples map
toBack map = Back.fromTuples $ toBack <$> Front.toUnfoldable map
Expand Down Expand Up @@ -112,16 +118,17 @@ instance currencySymbolBridge :: Bridge Back.CurrencySymbol String where
toBack unCurrencySymbol = Back.CurrencySymbol { unCurrencySymbol }

instance walletInfoBridge :: Bridge Back.WalletInfo Front.WalletInfo where
toFront (Back.WalletInfo { wiWallet, wiPubKey, wiPubKeyHash }) = Front.WalletInfo { wallet: toFront wiWallet, pubKey: toFront wiPubKey, pubKeyHash: toFront wiPubKeyHash }
toBack (Front.WalletInfo { wallet, pubKey, pubKeyHash }) = Back.WalletInfo { wiWallet: toBack wallet, wiPubKey: toBack pubKey, wiPubKeyHash: toBack pubKeyHash }
toFront (Back.WalletInfo { wiWallet, wiPubKeyHash }) = Front.WalletInfo { wallet: toFront wiWallet, pubKeyHash: toFront wiPubKeyHash }
toBack (Front.WalletInfo { wallet, pubKeyHash }) = Back.WalletInfo { wiWallet: toBack wallet, wiPubKeyHash: toBack pubKeyHash }

instance walletBridge :: Bridge Back.Wallet Front.Wallet where
toFront (Back.Wallet { getWalletId }) = Front.Wallet getWalletId
toBack (Front.Wallet getWalletId) = Back.Wallet { getWalletId }

instance pubKeyHashBridge :: Bridge Back.PubKeyHash Front.PubKeyHash where
toFront (Back.PubKeyHash { getPubKeyHash }) = Front.PubKeyHash getPubKeyHash
toBack (Front.PubKeyHash getPubKeyHash) = Back.PubKeyHash { getPubKeyHash }
-- TODO: Marlowe.Semantics.PubKeyHash is currently just an alias for String
instance pubKeyHashBridge :: Bridge Back.PubKeyHash String where
toFront (Back.PubKeyHash { getPubKeyHash }) = getPubKeyHash
toBack getPubKeyHash = Back.PubKeyHash { getPubKeyHash }

instance contractInstanceIdBridge :: Bridge Back.ContractInstanceId Front.PlutusAppId where
toFront (Back.ContractInstanceId { unContractInstanceId: JsonUUID uuid }) = Front.PlutusAppId uuid
Expand Down
19 changes: 10 additions & 9 deletions marlowe-dashboard-client/src/Capability/Marlowe.purs
Expand Up @@ -28,8 +28,8 @@ import Capability.MarloweStorage (class ManageMarloweStorage, addAssets, getCont
import Capability.PlutusApps.MarloweApp as MarloweApp
import Capability.Wallet (class ManageWallet)
import Capability.Wallet (createWallet, getWalletInfo, getWalletTotalFunds) as Wallet
import Contacts.Lenses (_companionAppId, _marloweAppId, _pubKey, _pubKeyHash, _wallet, _walletInfo)
import Contacts.Types (PubKeyHash(..), Wallet(..), WalletDetails, WalletInfo(..))
import Contacts.Lenses (_companionAppId, _marloweAppId, _pubKeyHash, _wallet, _walletInfo)
import Contacts.Types (Wallet(..), WalletDetails, WalletInfo(..))
import Control.Monad.Except (ExceptT(..), except, lift, mapExceptT, runExcept, runExceptT, withExceptT)
import Control.Monad.Reader (asks)
import Control.Monad.Reader.Class (ask)
Expand All @@ -55,11 +55,13 @@ import Foreign.Generic (decodeJSON)
import Halogen (HalogenM, liftAff)
import Marlowe.Client (ContractHistory(..))
import Marlowe.PAB (PlutusAppId(..))
import Marlowe.Semantics (Assets(..), Contract, MarloweData(..), MarloweParams(..), TokenName, TransactionInput, _rolePayoutValidatorHash, asset, emptyState)
import Marlowe.Semantics (Assets(..), Contract, MarloweData(..), MarloweParams(..), TokenName, TransactionInput, _rolePayoutValidatorHash, asset, emptyState, PubKeyHash(..))
import MarloweContract (MarloweContract(..))
import Plutus.PAB.Webserver.Types (ContractInstanceClientState)
import Servant.PureScript.Ajax (AjaxError(..), ErrorDescription(..))
import Types (AjaxResponse, CombinedWSStreamToServer(..), DecodedAjaxResponse)
import Contacts.Lenses (_companionAppId, _marloweAppId, _pubKeyHash, _wallet, _walletInfo)
import Contacts.Types (Wallet(..), WalletDetails, WalletInfo(..))
import WebSocket.Support as WS

-- The `ManageMarlowe` class provides a window on the `ManageContract` and `ManageWallet`
Expand Down Expand Up @@ -126,8 +128,7 @@ instance manageMarloweAppM :: ManageMarlowe AppM where
walletInfo =
WalletInfo
{ wallet: Wallet uuidString
, pubKey: uuidString
, pubKeyHash: PubKeyHash uuidString
, pubKeyHash: uuidString
}

assets = Assets $ singleton "" $ singleton "" (fromInt 1000000 * fromInt 10000)
Expand Down Expand Up @@ -248,14 +249,14 @@ instance manageMarloweAppM :: ManageMarlowe AppM where
, marloweState: emptyState zero
}
void $ insertContract marloweParams (marloweData /\ mempty)
void $ insertWalletRoleContracts (view (_walletInfo <<< _pubKey) walletDetails) marloweParams marloweData
void $ insertWalletRoleContracts (view (_walletInfo <<< _pubKeyHash) walletDetails) marloweParams marloweData
let
unfoldableRoles :: Array (Tuple TokenName PubKeyHash)
unfoldableRoles = toUnfoldable roles
void
$ for unfoldableRoles \(tokenName /\ pubKeyHash) -> do
void $ addAssets pubKeyHash $ asset (toString uuid) tokenName (fromInt 1)
void $ insertWalletRoleContracts (unwrap pubKeyHash) marloweParams marloweData
void $ insertWalletRoleContracts pubKeyHash marloweParams marloweData
pure $ Right unit
-- "apply-inputs" to a Marlowe contract on the blockchain
applyTransactionInput walletDetails marloweParams transactionInput = do
Expand Down Expand Up @@ -351,7 +352,7 @@ instance manageMarloweAppM :: ManageMarlowe AppM where
observableStateJson <- withExceptT Left $ ExceptT $ Contract.getContractInstanceObservableState companionAppId
mapExceptT (pure <<< lmap Right <<< unwrap) $ decodeJSON $ unwrap observableStateJson
LocalStorage -> do
roleContracts <- getWalletRoleContracts $ view (_walletInfo <<< _pubKey) walletDetails
roleContracts <- getWalletRoleContracts $ view (_walletInfo <<< _pubKeyHash) walletDetails
pure $ Right roleContracts
-- get all MarloweFollower apps for a given wallet
getFollowerApps walletDetails = do
Expand Down Expand Up @@ -379,7 +380,7 @@ instance manageMarloweAppM :: ManageMarlowe AppM where
Left decodingErrors -> Left decodingErrors
Right observableState -> Right (plutusAppId /\ observableState)
LocalStorage -> do
roleContracts <- getWalletRoleContracts $ view (_walletInfo <<< _pubKey) walletDetails
roleContracts <- getWalletRoleContracts $ view (_walletInfo <<< _pubKeyHash) walletDetails
allContracts <- getContracts
let
roleContractsToHistory :: MarloweParams -> MarloweData -> Maybe (Tuple PlutusAppId ContractHistory)
Expand Down
4 changes: 2 additions & 2 deletions marlowe-dashboard-client/src/Capability/MarloweStorage.purs
Expand Up @@ -27,9 +27,9 @@ import Foreign.Generic (decodeJSON, encodeJSON)
import Halogen (HalogenM)
import LocalStorage (Key(..), getItem, removeItem, setItem)
import Marlowe.PAB (PlutusAppId)
import Marlowe.Semantics (Assets, MarloweData, MarloweParams, TransactionInput)
import Marlowe.Semantics (Assets, MarloweData, MarloweParams, TransactionInput, PubKeyHash)
import Contacts.Lenses (_assets, _pubKeyHash, _walletInfo, _walletNickname)
import Contacts.Types (PubKeyHash, WalletDetails, WalletLibrary)
import Contacts.Types (WalletDetails, WalletLibrary)

walletLibraryLocalStorageKey :: Key
walletLibraryLocalStorageKey = Key "walletLibrary"
Expand Down
Expand Up @@ -20,7 +20,6 @@ import Capability.Contract (class ManageContract)
import Capability.Contract (invokeEndpoint) as Contract
import Capability.PlutusApps.MarloweApp.Lenses (_applyInputs, _create, _marloweAppEndpointMutex, _redeem, _requests)
import Capability.PlutusApps.MarloweApp.Types (EndpointMutex, LastResult(..), MarloweAppEndpointMutexEnv)
import Contacts.Types (PubKeyHash)
import Control.Monad.Reader (class MonadAsk, asks)
import Data.Array (findMap, take, (:))
import Data.Foldable (elem)
Expand All @@ -40,7 +39,7 @@ import Effect.Aff.Class (class MonadAff, liftAff)
import Effect.Class (liftEffect)
import Foreign.Generic (class Encode)
import Marlowe.PAB (PlutusAppId)
import Marlowe.Semantics (Contract, MarloweParams, SlotInterval(..), TokenName, TransactionInput(..))
import Marlowe.Semantics (Contract, MarloweParams, SlotInterval(..), TokenName, TransactionInput(..), PubKeyHash)
import Plutus.Contract.Effects (ActiveEndpoint, _ActiveEndpoint)
import Plutus.V1.Ledger.Crypto (PubKeyHash) as Back
import Plutus.V1.Ledger.Slot (Slot) as Back
Expand Down
8 changes: 2 additions & 6 deletions marlowe-dashboard-client/src/Contacts/Lenses.purs
Expand Up @@ -11,7 +11,6 @@ module Contacts.Lenses
, _assets
, _previousCompanionAppState
, _wallet
, _pubKey
, _pubKeyHash
) where

Expand All @@ -23,9 +22,9 @@ import Data.Map (Map)
import Data.Symbol (SProxy(..))
import InputField.Types (State) as InputField
import Marlowe.PAB (PlutusAppId)
import Marlowe.Semantics (Assets, MarloweData, MarloweParams, PubKey)
import Marlowe.Semantics (Assets, MarloweData, MarloweParams, PubKey, PubKeyHash)
import Types (WebData)
import Contacts.Types (CardSection, PubKeyHash, State, Wallet, WalletIdError, WalletInfo, WalletLibrary, WalletNickname, WalletNicknameError, WalletDetails)
import Contacts.Types (CardSection, State, Wallet, WalletIdError, WalletInfo, WalletLibrary, WalletNickname, WalletNicknameError, WalletDetails)

_walletLibrary :: Lens' State WalletLibrary
_walletLibrary = prop (SProxy :: SProxy "walletLibrary")
Expand Down Expand Up @@ -65,8 +64,5 @@ _previousCompanionAppState = prop (SProxy :: SProxy "previousCompanionAppState")
_wallet :: Lens' WalletInfo Wallet
_wallet = _Newtype <<< prop (SProxy :: SProxy "wallet")

_pubKey :: Lens' WalletInfo PubKey
_pubKey = _Newtype <<< prop (SProxy :: SProxy "pubKey")

_pubKeyHash :: Lens' WalletInfo PubKeyHash
_pubKeyHash = _Newtype <<< prop (SProxy :: SProxy "pubKeyHash")
7 changes: 3 additions & 4 deletions marlowe-dashboard-client/src/Contacts/State.purs
Expand Up @@ -39,12 +39,12 @@ import InputField.Types (Action(..), State) as InputField
import MainFrame.Types (Action(..)) as MainFrame
import MainFrame.Types (ChildSlots, Msg)
import Marlowe.PAB (PlutusAppId(..))
import Marlowe.Semantics (Assets, Token(..))
import Marlowe.Semantics (Assets, Token(..), PubKeyHash(..))
import Network.RemoteData (RemoteData(..), fromEither)
import Toast.Types (errorToast, successToast)
import Types (WebData)
import Contacts.Lenses (_cardSection, _remoteWalletInfo, _walletIdInput, _walletLibrary, _walletNickname, _walletNicknameInput)
import Contacts.Types (Action(..), CardSection(..), PubKeyHash(..), State, Wallet(..), WalletDetails, WalletIdError(..), WalletInfo(..), WalletLibrary, WalletNickname, WalletNicknameError(..))
import Contacts.Types (Action(..), CardSection(..), State, Wallet(..), WalletDetails, WalletIdError(..), WalletInfo(..), WalletLibrary, WalletNickname, WalletNicknameError(..))

mkInitialState :: WalletLibrary -> State
mkInitialState walletLibrary =
Expand All @@ -69,8 +69,7 @@ defaultWalletInfo :: WalletInfo
defaultWalletInfo =
WalletInfo
{ wallet: Wallet ""
, pubKey: ""
, pubKeyHash: PubKeyHash ""
, pubKeyHash: ""
}

handleAction ::
Expand Down
20 changes: 1 addition & 19 deletions marlowe-dashboard-client/src/Contacts/Types.purs
Expand Up @@ -5,7 +5,6 @@ module Contacts.Types
, WalletDetails
, WalletInfo(..)
, Wallet(..)
, PubKeyHash(..)
, CardSection(..)
, WalletNicknameError(..)
, WalletIdError(..)
Expand All @@ -24,7 +23,7 @@ import Foreign.Generic (defaultOptions, genericDecode, genericEncode)
import InputField.Types (Action, State) as InputField
import InputField.Types (class InputFieldError)
import Marlowe.PAB (PlutusAppId)
import Marlowe.Semantics (Assets, MarloweData, MarloweParams, PubKey)
import Marlowe.Semantics (Assets, MarloweData, MarloweParams, PubKey, PubKeyHash)
import Types (WebData)

type State
Expand Down Expand Up @@ -58,7 +57,6 @@ type WalletDetails
newtype WalletInfo
= WalletInfo
{ wallet :: Wallet
, pubKey :: PubKey
, pubKeyHash :: PubKeyHash
}

Expand Down Expand Up @@ -89,22 +87,6 @@ instance encodeWallet :: Encode Wallet where
instance decodeWallet :: Decode Wallet where
decode value = genericDecode defaultOptions value

-- TODO: move this into Marlowe.Semantics
newtype PubKeyHash
= PubKeyHash String

derive instance newtypePubKeyHash :: Newtype PubKeyHash _

derive instance eqPubKeyHash :: Eq PubKeyHash

derive instance genericPubKeyHash :: Generic PubKeyHash _

instance encodePubKeyHash :: Encode PubKeyHash where
encode value = genericEncode defaultOptions value

instance decodePubKeyHash :: Decode PubKeyHash where
decode value = genericDecode defaultOptions value

data CardSection
= Home
| ViewWallet WalletDetails
Expand Down
2 changes: 1 addition & 1 deletion marlowe-dashboard-client/src/Contract/State.purs
Expand Up @@ -219,7 +219,7 @@ getUserParties walletDetails marloweParams =

roleTokens = foldMap (Set.map Role <<< Map.keys <<< Map.filter ((/=) zero)) mCurrencyTokens
in
Set.insert (PK $ unwrap pubKeyHash) roleTokens
Set.insert (PK pubKeyHash) roleTokens

withStarted ::
forall action slots msg m.
Expand Down
12 changes: 12 additions & 0 deletions marlowe-playground-client/spago-packages.nix
Expand Up @@ -1013,6 +1013,18 @@ let
installPhase = "ln -s $src $out";
};

"rationals" = pkgs.stdenv.mkDerivation {
name = "rationals";
version = "v5.0.0";
src = pkgs.fetchgit {
url = "https://github.com/anttih/purescript-rationals.git";
rev = "8c52d8cc891d1223150a31416220aa9b99404442";
sha256 = "1idvjvvx5kwmi8kj2ps95bcvlsgij1xgin4jfw3rmcqd930wqq6q";
};
phases = "installPhase";
installPhase = "ln -s $src $out";
};

"record" = pkgs.stdenv.mkDerivation {
name = "record";
version = "v2.0.2";
Expand Down
1 change: 1 addition & 0 deletions marlowe-playground-client/spago.dhall
Expand Up @@ -20,6 +20,7 @@ You can edit this file as you like.
, "halogen"
, "matryoshka"
, "node-fs"
, "numerics"
, "markdown"
, "prelude"
, "psci-support"
Expand Down
1 change: 1 addition & 0 deletions marlowe/marlowe.cabal
Expand Up @@ -125,6 +125,7 @@ test-suite marlowe-test-long-running
websockets -any,
network -any,
openapi3 -any,
uuid -any,

test-suite marlowe-test
import: lang
Expand Down

0 comments on commit a9ce8e3

Please sign in to comment.