Skip to content

Commit

Permalink
Merge pull request #1538 from Plutonomicon/koz/1491
Browse files Browse the repository at this point in the history
scriptCurrencySymbol no longer returns Maybe
  • Loading branch information
klntsky authored Sep 27, 2023
2 parents 1f8b11e + 08baebd commit c37ffea
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### Changed

- `scriptCurrencySymbol` no longer returns `Maybe`
([#1538](https://github.com/Plutonomicon/cardano-transaction-lib/pull/1538)
- **[IMPORTANT]** It is no more recommended to use `utxosAt` to get UTxOs at light wallet addresses. It may be a source of application bugs in some cases due to how wallets operate. Please see *Synchronization and wallet UTxO locking* section [here](./doc/query-layers.md) ([#1440](https://github.com/Plutonomicon/cardano-transaction-lib/pull/1440))
- Slot to/from POSIXTime conversion functions now live outside of `Effect` ([#1490](https://github.com/Plutonomicon/cardano-transaction-lib/pull/1490))
- All uses of `utxosAt` call have been replaced with `getWalletUtxos` in the balancer ([#1440](https://github.com/Plutonomicon/cardano-transaction-lib/pull/1440))
Expand Down
2 changes: 1 addition & 1 deletion examples/Helpers.purs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mkCurrencySymbol
-> Contract (MintingPolicy /\ CurrencySymbol)
mkCurrencySymbol mintingPolicy = do
mp <- mintingPolicy
cs <- liftContractM "Cannot get cs" $ Value.scriptCurrencySymbol mp
let cs = Value.scriptCurrencySymbol mp
pure (mp /\ cs)

mkTokenName :: String -> Contract TokenName
Expand Down
2 changes: 1 addition & 1 deletion examples/PlutusV2/ReferenceInputsAndScripts.purs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ mintAlwaysMintsV2ToTheScript
:: TokenName -> Validator -> Int -> Contract Unit
mintAlwaysMintsV2ToTheScript tokenName validator sum = do
mp <- alwaysMintsPolicyV2
cs <- liftContractM "Cannot get cs" $ Value.scriptCurrencySymbol mp
let cs = Value.scriptCurrencySymbol mp

let
vhash = validatorHash validator
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Plutus/Types/CurrencySymbol.purs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Ctl.Internal.Plutus.Types.CurrencySymbol
( CurrencySymbol
( CurrencySymbol(CurrencySymbol)
, adaSymbol
, currencyMPSHash
, getCurrencySymbol
Expand Down
15 changes: 11 additions & 4 deletions src/Internal/Scripts.purs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import Prelude

import Ctl.Internal.Hashing (plutusScriptHash)
import Ctl.Internal.NativeScripts (NativeScriptHash, nativeScriptHash)
import Ctl.Internal.Plutus.Types.CurrencySymbol (CurrencySymbol, mpsSymbol)
import Ctl.Internal.Plutus.Types.CurrencySymbol
( CurrencySymbol(CurrencySymbol)
)
import Ctl.Internal.Serialization.Address
( Address
, NetworkId
Expand All @@ -23,6 +25,7 @@ import Ctl.Internal.Serialization.Address
, scriptAddress
, scriptHashCredential
)
import Ctl.Internal.Serialization.Hash (scriptHashToBytes)
import Ctl.Internal.Types.Scripts
( MintingPolicy(NativeMintingPolicy, PlutusMintingPolicy)
, MintingPolicyHash
Expand All @@ -32,7 +35,6 @@ import Ctl.Internal.Types.Scripts
, Validator
, ValidatorHash
)
import Data.Maybe (Maybe)
import Data.Newtype (unwrap, wrap)

-- | Helpers for `PlutusScript` and `ScriptHash` newtype wrappers, separate from
Expand Down Expand Up @@ -81,5 +83,10 @@ nativeScriptStakeValidatorHash
nativeScriptStakeValidatorHash = unwrap >>> nativeScriptHash >>> unwrap >>> wrap

-- | Converts a `MintingPolicy` to a `CurrencySymbol`.
scriptCurrencySymbol :: MintingPolicy -> Maybe CurrencySymbol
scriptCurrencySymbol = mpsSymbol <<< mintingPolicyHash
scriptCurrencySymbol :: MintingPolicy -> CurrencySymbol
scriptCurrencySymbol = CurrencySymbol
<<< unwrap
<<< scriptHashToBytes
<<< unwrap
<<<
mintingPolicyHash
6 changes: 3 additions & 3 deletions test/Plutip/Contract.purs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ suite = do
withWallets distribution \alice -> do
withKeyWallet alice do
mp <- alwaysMintsPolicy
cs <- liftContractM "Cannot get cs" $ Value.scriptCurrencySymbol mp
let cs = Value.scriptCurrencySymbol mp
tn <- liftContractM "Cannot make token name"
$ Value.mkTokenName
=<< byteArrayFromAscii "TheToken"
Expand Down Expand Up @@ -1374,7 +1374,7 @@ suite = do
pure $ pkh /\ stakePkh

mp <- alwaysMintsPolicy
cs <- liftContractM "Cannot get cs" $ Value.scriptCurrencySymbol mp
let cs = Value.scriptCurrencySymbol mp
tn <- liftContractM "Cannot make token name"
$ byteArrayFromAscii "TheToken" >>= Value.mkTokenName
let asset = Value.singleton cs tn $ BigInt.fromInt 50
Expand Down Expand Up @@ -1650,7 +1650,7 @@ suite = do
logInfo' $ "wUtxos0 " <> show wUtxos0

mp <- alwaysMintsPolicyV2
cs <- liftContractM "Cannot get cs" $ Value.scriptCurrencySymbol mp
let cs = Value.scriptCurrencySymbol mp
tn <- liftContractM "Cannot make token name"
$ byteArrayFromAscii "TheToken" >>= Value.mkTokenName

Expand Down

0 comments on commit c37ffea

Please sign in to comment.