Connor's suggestions
This commit is contained in:
parent
0090299146
commit
744316a5a6
1 changed files with 19 additions and 27 deletions
|
|
@ -33,11 +33,10 @@ module Agora.Utils (
|
||||||
allOutputs,
|
allOutputs,
|
||||||
anyInput,
|
anyInput,
|
||||||
allInputs,
|
allInputs,
|
||||||
pfindEffectInput,
|
findTxOutByTxOutRef,
|
||||||
pfindEffectAddress,
|
scriptHashFromAddress,
|
||||||
pscriptHashFromAddress,
|
findOutputsToAddress,
|
||||||
pfindOutputsToAddress,
|
findTxOutDatum,
|
||||||
pfindTxOutDatum,
|
|
||||||
) where
|
) where
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
@ -154,7 +153,7 @@ pfromMaybe = phoistAcyclic $
|
||||||
PJust a' -> a'
|
PJust a' -> a'
|
||||||
PNothing -> e
|
PNothing -> e
|
||||||
|
|
||||||
-- | Yield True is a given PMaybe is of form PJust _
|
-- | Yield True if a given PMaybe is of form PJust _
|
||||||
pisJust :: forall a s. Term s (PMaybe a :--> PBool)
|
pisJust :: forall a s. Term s (PMaybe a :--> PBool)
|
||||||
pisJust = phoistAcyclic $
|
pisJust = phoistAcyclic $
|
||||||
plam $ \v' -> P.do
|
plam $ \v' -> P.do
|
||||||
|
|
@ -411,24 +410,17 @@ psingletonValue = phoistAcyclic $
|
||||||
res = pcon $ PValue outerTup
|
res = pcon $ PValue outerTup
|
||||||
in res
|
in res
|
||||||
|
|
||||||
-- | Finds the TxInInfo of an effect from TxInfo and TxOutRef
|
-- | Finds the TxOut of an effect from TxInfo and TxOutRef
|
||||||
pfindEffectInput :: Term s (PTxInfo :--> PTxOutRef :--> PTxInInfo)
|
findTxOutByTxOutRef :: Term s (PTxOutRef :--> PTxInfo :--> PMaybe PTxOut)
|
||||||
pfindEffectInput = phoistAcyclic $
|
findTxOutByTxOutRef = phoistAcyclic $
|
||||||
plam $ \txInfo spending' -> P.do
|
plam $ \txOutRef txInfo ->
|
||||||
input <- plet $ pfromData $ pfield @"inputs" # txInfo
|
pmatch (pfindTxInByTxOutRef # txOutRef # txInfo) $ \case
|
||||||
spending <- plet $ pdata spending'
|
PJust ((pfield @"resolved" #) -> txOut) -> pcon $ PJust txOut
|
||||||
PJust result <- pmatch $ pfind # plam (\x -> pfield @"outRef" # x #== spending) # input
|
PNothing -> pcon PNothing
|
||||||
pfromData result
|
|
||||||
|
|
||||||
-- | Finds the address of an effect from TxInfo and TxOutRef
|
|
||||||
pfindEffectAddress :: Term s (PTxInfo :--> PTxOutRef :--> PTxOut)
|
|
||||||
pfindEffectAddress = phoistAcyclic $
|
|
||||||
plam $ \txInfo spending -> P.do
|
|
||||||
pfromData $ pfield @"resolved" #$ pfindEffectInput # txInfo # spending
|
|
||||||
|
|
||||||
-- | Get script hash from an Address.
|
-- | Get script hash from an Address.
|
||||||
pscriptHashFromAddress :: Term s (PAddress :--> PMaybe PValidatorHash)
|
scriptHashFromAddress :: Term s (PAddress :--> PMaybe PValidatorHash)
|
||||||
pscriptHashFromAddress = phoistAcyclic $
|
scriptHashFromAddress = phoistAcyclic $
|
||||||
plam $ \addr -> P.do
|
plam $ \addr -> P.do
|
||||||
cred <- pmatch $ pfromData $ pfield @"credential" # addr
|
cred <- pmatch $ pfromData $ pfield @"credential" # addr
|
||||||
case cred of
|
case cred of
|
||||||
|
|
@ -436,8 +428,8 @@ pscriptHashFromAddress = phoistAcyclic $
|
||||||
_ -> pcon PNothing
|
_ -> pcon PNothing
|
||||||
|
|
||||||
-- | Find all TxOuts sent to an Address
|
-- | Find all TxOuts sent to an Address
|
||||||
pfindOutputsToAddress :: Term s (PTxInfo :--> PAddress :--> PList PTxOut)
|
findOutputsToAddress :: Term s (PTxInfo :--> PAddress :--> PList PTxOut)
|
||||||
pfindOutputsToAddress = phoistAcyclic $
|
findOutputsToAddress = phoistAcyclic $
|
||||||
plam $ \info address' -> P.do
|
plam $ \info address' -> P.do
|
||||||
address <- plet $ pdata address'
|
address <- plet $ pdata address'
|
||||||
let outputs = pfromData $ pfield @"outputs" # info
|
let outputs = pfromData $ pfield @"outputs" # info
|
||||||
|
|
@ -450,9 +442,9 @@ pfindOutputsToAddress = phoistAcyclic $
|
||||||
# outputs
|
# outputs
|
||||||
pmap @PList # plam pfromData #$ pconvertLists # filteredOutputs
|
pmap @PList # plam pfromData #$ pconvertLists # filteredOutputs
|
||||||
|
|
||||||
-- | Find datum in a TxOut
|
-- | Find the data corresponding to a TxOut, if there is one
|
||||||
pfindTxOutDatum :: Term s (PTxInfo :--> PTxOut :--> PMaybe PDatum)
|
findTxOutDatum :: Term s (PTxInfo :--> PTxOut :--> PMaybe PDatum)
|
||||||
pfindTxOutDatum = phoistAcyclic $
|
findTxOutDatum = phoistAcyclic $
|
||||||
plam $ \info out -> P.do
|
plam $ \info out -> P.do
|
||||||
datumHash' <- pmatch $ pfromData $ pfield @"datumHash" # out
|
datumHash' <- pmatch $ pfromData $ pfield @"datumHash" # out
|
||||||
case datumHash' of
|
case datumHash' of
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue