Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
1,350 additions
and
372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{-# LANGUAGE ViewPatterns #-} | ||
module Language.Marlowe.CLI.Cardano.Api.Value | ||
where | ||
|
||
import qualified Cardano.Api as C | ||
import Language.Marlowe.CLI.Orphans () | ||
import qualified Ledger.Tx.CardanoAPI as L | ||
import qualified Plutus.V1.Ledger.Value as P | ||
import qualified PlutusTx.Prelude as PlutusTx | ||
|
||
txOutValue :: C.TxOut ctx era -> C.TxOutValue era | ||
txOutValue (C.TxOut _ v _ _) = v | ||
|
||
|
||
txOutValueValue :: C.TxOut ctx era -> C.Value | ||
txOutValueValue (C.TxOut _ v _ _) = C.txOutValueToValue v | ||
|
||
|
||
toPlutusValue :: C.Value -> P.Value | ||
toPlutusValue (C.valueToList -> assets) = foldMap (uncurry assetToValue) assets | ||
|
||
|
||
lovelaceToPlutusValue :: C.Lovelace -> P.Value | ||
lovelaceToPlutusValue (C.Lovelace v) = P.singleton P.adaSymbol P.adaToken v | ||
|
||
|
||
assetToValue :: C.AssetId -> C.Quantity -> P.Value | ||
assetToValue (C.AssetId policyId assetName) (C.Quantity quantity) = | ||
P.singleton (toCurrencySymbol policyId) (toTokenName assetName) quantity | ||
assetToValue C.AdaAssetId (C.Quantity quantity) = | ||
P.singleton P.adaSymbol P.adaToken quantity | ||
|
||
|
||
toCurrencySymbol :: C.PolicyId -> P.CurrencySymbol | ||
toCurrencySymbol = P.mpsSymbol . L.fromCardanoPolicyId | ||
|
||
|
||
toTokenName :: C.AssetName -> P.TokenName | ||
toTokenName (C.AssetName bs) = P.TokenName $ PlutusTx.toBuiltin bs | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.