diff --git a/cooked-validators/src/Cooked/Wallet.hs b/cooked-validators/src/Cooked/Wallet.hs index eab3dc20e..a4b0c4b88 100644 --- a/cooked-validators/src/Cooked/Wallet.hs +++ b/cooked-validators/src/Cooked/Wallet.hs @@ -50,13 +50,15 @@ wallet j | j > 0 && j <= 10 = let i = j - 1 in knownWallets !! i | otherwise = Pl.fromWalletNumber (Pl.WalletNumber $ fromIntegral j) --- | Retrieves the id of the known wallet that corresponds to a public key hash, if any. +-- | Retrieves the id of the known wallet that corresponds to a public key +-- hash, if any. -- -- @walletPKHashToId (walletPKHash (wallet 3)) == Just 3@ walletPKHashToId :: Pl.PubKeyHash -> Maybe Int walletPKHashToId = flip Map.lookup walletPKHashToIdMap where - walletPKHashToIdMap = Map.fromList . flip zip [1 ..] . map walletPKHash $ knownWallets + walletPKHashToIdMap = + Map.fromList . flip zip [1 ..] . map walletPKHash $ knownWallets -- | Retrieves a wallet publik key (PK) walletPK :: Wallet -> Pl.PubKey @@ -85,21 +87,22 @@ walletAddress w = walletSK :: Pl.MockWallet -> PrivateKey walletSK = Pl.unPaymentPrivateKey . Pl.paymentPrivateKey --- FIXME Massive hack to be able to open a MockPrivateKey; this is needed because --- the constructor and accessor to MockPrivateKey are not exported. Hence, --- we make an isomorphic datatype, unsafeCoerce to this datatype then extract --- whatever we need from it. +-- FIXME Massive hack to be able to open a MockPrivateKey; this is needed +-- because the constructor and accessor to MockPrivateKey are not exported. +-- Hence, we make an isomorphic datatype, unsafeCoerce to this datatype then +-- extract whatever we need from it. newtype HACK = HACK Cardano.XPrv -- | Retrieves a wallet's private staking key (secret key SK), if any walletStakingSK :: Wallet -> Maybe PrivateKey walletStakingSK = fmap hackUnMockPrivateKey . Pl.mwStakeKey where - -- Don't use this; its a hack and will be deprecated once we have time - -- to make a PR into plutus exporting the things we need. If you use this anyway, - -- make sure that you only apply it to @MockPrivateKey@; the function is polymorphic - -- because @MockPrivateKey@ is not exported either; having a dedicated function makes - -- it easy to test that this works: check the @Cooked.WalletSpec@ test module. + -- Don't use this; its a hack and will be deprecated once we have time to + -- make a PR into plutus exporting the things we need. If you use this + -- anyway, make sure that you only apply it to @MockPrivateKey@; the + -- function is polymorphic because @MockPrivateKey@ is not exported either; + -- having a dedicated function makes it easy to test that this works: check + -- the @Cooked.WalletSpec@ test module. hackUnMockPrivateKey :: a -> Cardano.XPrv hackUnMockPrivateKey x = let HACK y = unsafeCoerce x in y @@ -115,11 +118,11 @@ txAddSignature w = Pl.addSignature' (walletSK w) -- the underlying plutus definitions to make it easer when we have -- to plug our own, if we ever have the need --- | Describes the initial distribution of /UTxOs/ per wallet. This is important since --- transaction validation must specify a /collateral/, hence, wallets must posses more --- than one UTxO to begin with in order to execute a transaction and have some collateral --- option. The @txCollateral@ is transfered to the node operator in case the transaction --- fails to validate. +-- | Describes the initial distribution of /UTxOs/ per wallet. This is +-- important since transaction validation must specify a /collateral/, hence, +-- wallets must posses more than one UTxO to begin with in order to execute a +-- transaction and have some collateral option. The @txCollateral@ is +-- transfered to the node operator in case the transaction fails to validate. -- -- An initial distribution defined by: -- @@ -131,23 +134,31 @@ txAddSignature w = Pl.addSignature' (walletSK w) -- > , (wallet 3 , [Pl.lovelaceValueOf 10000000 <> permanentValue "XYZ" 10]) -- > ] -- --- Specifies a starting state where @wallet 1@ contains two /UTxOs/, one with 42 Ada --- and one with 2 Ada and one "TOK" token; @wallet 2@ contains a single /UTxO/ with 10 Ada and --- @wallet 3@ has 10 Ada and a permanent value. Check #quickvalues for more on quick --- and permanent values. (Remember: 1 Ada = 1000000 Lovelace) +-- Specifies a starting state where @wallet 1@ contains two /UTxOs/, one with +-- 42 Ada and one with 2 Ada and one "TOK" token; @wallet 2@ contains a single +-- /UTxO/ with 10 Ada and @wallet 3@ has 10 Ada and a permanent value. Check +-- #quickvalues for more on quick and permanent values. (Remember: 1 Ada = +-- 1000000 Lovelace) -- --- Check the corresponding @Default InitialDistribution@ instance for the default value. -newtype InitialDistribution = InitialDistribution {unInitialDistribution :: Map Wallet [Pl.Value]} +-- Check the corresponding @Default InitialDistribution@ instance for the +-- default value. +newtype InitialDistribution = InitialDistribution + { unInitialDistribution :: Map Wallet [Pl.Value] + } deriving (Eq, Show) instance Semigroup InitialDistribution where - (InitialDistribution i) <> (InitialDistribution j) = InitialDistribution $ Map.unionWith (<>) i j + (InitialDistribution i) <> (InitialDistribution j) = + InitialDistribution $ Map.unionWith (<>) i j instance Monoid InitialDistribution where mempty = InitialDistribution Map.empty instance Default InitialDistribution where - def = InitialDistribution $ Map.fromList $ zip knownWallets (repeat $ replicate 10 defLovelace) + def = + InitialDistribution $ + Map.fromList $ + zip knownWallets (repeat $ replicate 10 defLovelace) where defLovelace = Pl.lovelaceValueOf 100_000_000 @@ -177,13 +188,22 @@ initialTxFor initDist = toPlTxOut :: Pl.ToData a => Pl.Address -> Pl.Value -> Maybe a -> Pl.TxOut toPlTxOut addr value datum = toPlTxOut' addr value datum' where - datum' = maybe Pl2.NoOutputDatum (Pl2.OutputDatumHash . Pl.datumHash . Pl.Datum . Pl.toBuiltinData) datum + datum' = + maybe + Pl2.NoOutputDatum + ( Pl2.OutputDatumHash + . Pl.datumHash + . Pl.Datum + . Pl.toBuiltinData + ) + datum toPlTxOut' :: Pl.Address -> Pl.Value -> Pl2.OutputDatum -> Pl.TxOut toPlTxOut' addr value datum = Pl.TxOut $ toCardanoTxOut' addr value datum toCardanoTxOut' :: Pl.Address -> Pl.Value -> Pl2.OutputDatum -> Cardano.TxOut Cardano.CtxTx Cardano.BabbageEra - toCardanoTxOut' addr value datum = Cardano.TxOut cAddr cValue cDatum Cardano.ReferenceScriptNone + toCardanoTxOut' addr value datum = + Cardano.TxOut cAddr cValue cDatum Cardano.ReferenceScriptNone where fromRight' x = case x of Left err -> error $ show err