doc string for util functions

This commit is contained in:
fanghr 2022-04-23 16:21:23 +08:00
parent 9e85a7a004
commit 1cd5a8eb3c
2 changed files with 9 additions and 7 deletions

View file

@ -159,10 +159,7 @@ test-suite agora-test
hs-source-dirs: agora-test hs-source-dirs: agora-test
other-modules: other-modules:
Spec.AuthorityToken Spec.AuthorityToken
<<<<<<< HEAD
Spec.Effect.TreasuryWithdrawal Spec.Effect.TreasuryWithdrawal
=======
>>>>>>> 0f1b4f3 (rewrite the doc for governor components)
Spec.Model.MultiSig Spec.Model.MultiSig
Spec.Proposal Spec.Proposal
Spec.Sample.Effect.TreasuryWithdrawal Spec.Sample.Effect.TreasuryWithdrawal

View file

@ -510,7 +510,6 @@ findTxOutDatum = phoistAcyclic $
PDJust ((pfield @"_0" #) -> datumHash) -> pfindDatum # datumHash # datums PDJust ((pfield @"_0" #) -> datumHash) -> pfindDatum # datumHash # datums
_ -> pcon PNothing _ -> pcon PNothing
<<<<<<< HEAD
{- | Safely convert a 'PValidatorHash' into a 'PTokenName'. This can be useful for tagging {- | Safely convert a 'PValidatorHash' into a 'PTokenName'. This can be useful for tagging
tokens for extra safety. tokens for extra safety.
-} -}
@ -525,8 +524,7 @@ pvalidatorHashToTokenName vh = pcon (PTokenName (pto vh))
getMintingPolicySymbol :: ClosedTerm PMintingPolicy -> CurrencySymbol getMintingPolicySymbol :: ClosedTerm PMintingPolicy -> CurrencySymbol
getMintingPolicySymbol v = mintingPolicySymbol $ mkMintingPolicy v getMintingPolicySymbol v = mintingPolicySymbol $ mkMintingPolicy v
======= -- | The entire value only contains one token of the specific assetclass.
>>>>>>> 93fe9ca (fix compilation erros; format && lint)
hasOnlyOneTokenOfAssetClass' :: AssetClass -> Term s (PValue :--> PBool) hasOnlyOneTokenOfAssetClass' :: AssetClass -> Term s (PValue :--> PBool)
hasOnlyOneTokenOfAssetClass' ac@(AssetClass (as, _)) = phoistAcyclic $ hasOnlyOneTokenOfAssetClass' ac@(AssetClass (as, _)) = phoistAcyclic $
plam $ \vs -> P.do plam $ \vs -> P.do
@ -536,13 +534,14 @@ hasOnlyOneTokenOfAssetClass' ac@(AssetClass (as, _)) = phoistAcyclic $
#&& passetClassValueOf' ac # vs #== 1 #&& passetClassValueOf' ac # vs #== 1
#&& (plength #$ pto $ pto $ pto vs) #== 1 #&& (plength #$ pto $ pto $ pto vs) #== 1
-- | The entire value only contains one token of the specific currency symbol.
hasOnlyOneTokenOfCurrencySymbol :: Term s (PCurrencySymbol :--> PValue :--> PBool) hasOnlyOneTokenOfCurrencySymbol :: Term s (PCurrencySymbol :--> PValue :--> PBool)
hasOnlyOneTokenOfCurrencySymbol = phoistAcyclic $ hasOnlyOneTokenOfCurrencySymbol = phoistAcyclic $
plam $ \cs vs -> P.do plam $ \cs vs -> P.do
psymbolValueOf # cs # vs #== 1 psymbolValueOf # cs # vs #== 1
#&& (plength #$ pto $ pto $ pto vs) #== 1 #&& (plength #$ pto $ pto $ pto vs) #== 1
{- Find datum, in an unsafe manner. {- Find datum given a maybe datum hash, in an unsafe manner.
FIXME: reimplement using 'ptryFrom'. FIXME: reimplement using 'ptryFrom'.
-} -}
@ -556,12 +555,18 @@ mustFindDatum' = phoistAcyclic $
PJust dt <- pmatch $ pfindDatum # dh # info PJust dt <- pmatch $ pfindDatum # dh # info
pfromData $ punsafeCoerce dt pfromData $ punsafeCoerce dt
{- | Extract the value stored in a PMaybe container.
If there's no value, throw an error with the given message.
-}
mustBePJust :: forall a s. Term s (PString :--> PMaybe a :--> a) mustBePJust :: forall a s. Term s (PString :--> PMaybe a :--> a)
mustBePJust = phoistAcyclic $ mustBePJust = phoistAcyclic $
plam $ \emsg mv' -> pmatch mv' $ \case plam $ \emsg mv' -> pmatch mv' $ \case
PJust v -> v PJust v -> v
_ -> ptraceError emsg _ -> ptraceError emsg
{- | Extract the value stored in a PMaybeData container.
If there's no value, throw an error with the given message.
-}
mustBePDJust :: forall a s. (PIsData a) => Term s (PString :--> PMaybeData a :--> a) mustBePDJust :: forall a s. (PIsData a) => Term s (PString :--> PMaybeData a :--> a)
mustBePDJust = phoistAcyclic $ mustBePDJust = phoistAcyclic $
plam $ \emsg mv' -> pmatch mv' $ \case plam $ \emsg mv' -> pmatch mv' $ \case