forked from IntersectMBO/plutus
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* MintValue * Test properties of MintValue
- Loading branch information
Showing
21 changed files
with
292 additions
and
39 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
4 changes: 2 additions & 2 deletions
4
plutus-benchmark/script-contexts/test/9.6/checkScriptContext1-20.budget.golden
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
({cpu: 11100264187581 | ||
| mem: 11100001066437}) | ||
({cpu: 11100263419581 | ||
| mem: 11100001061637}) |
4 changes: 2 additions & 2 deletions
4
plutus-benchmark/script-contexts/test/9.6/checkScriptContext1-4.budget.golden
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
({cpu: 3100079463709 | ||
| mem: 3100000324645}) | ||
({cpu: 3100079207709 | ||
| mem: 3100000323045}) |
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
2 changes: 1 addition & 1 deletion
2
plutus-benchmark/script-contexts/test/9.6/checkScriptContext1.size.golden
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 |
---|---|---|
@@ -1 +1 @@ | ||
3221 | ||
3218 |
4 changes: 2 additions & 2 deletions
4
plutus-benchmark/script-contexts/test/9.6/checkScriptContext2-20.budget.golden
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
({cpu: 11100253887109 | ||
| mem: 11100001016294}) | ||
({cpu: 11100253119109 | ||
| mem: 11100001011494}) |
4 changes: 2 additions & 2 deletions
4
plutus-benchmark/script-contexts/test/9.6/checkScriptContext2-4.budget.golden
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
({cpu: 3100076414565 | ||
| mem: 3100000309734}) | ||
({cpu: 3100076158565 | ||
| mem: 3100000308134}) |
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
2 changes: 1 addition & 1 deletion
2
plutus-benchmark/script-contexts/test/9.6/checkScriptContext2.size.golden
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 |
---|---|---|
@@ -1 +1 @@ | ||
3157 | ||
3154 |
4 changes: 4 additions & 0 deletions
4
plutus-ledger-api/changelog.d/20241031_172446_Yuriy.Lazaryev_mint_value.md
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,4 @@ | ||
### Changed | ||
|
||
- 'txInfoMint' function now returns 'MintValue' instead of 'Value' for minted values. This change | ||
addresses problem described in the issue #5781. |
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
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,126 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE DeriveAnyClass #-} | ||
{-# LANGUAGE DeriveDataTypeable #-} | ||
{-# LANGUAGE DerivingVia #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
{-# OPTIONS_GHC -fexpose-all-unfoldings #-} | ||
{-# OPTIONS_GHC -fno-omit-interface-pragmas #-} | ||
{-# OPTIONS_GHC -fno-spec-constr #-} | ||
{-# OPTIONS_GHC -fno-specialise #-} | ||
|
||
module PlutusLedgerApi.V3.MintValue | ||
( MintValue (..) -- Constructor is exported for testing | ||
, emptyMintValue | ||
, mintValueToMap | ||
, mintValueMinted | ||
, mintValueBurned | ||
) | ||
where | ||
|
||
import PlutusTx.Prelude | ||
|
||
import Control.DeepSeq (NFData) | ||
import Data.Data (Data, Typeable) | ||
import GHC.Generics (Generic) | ||
import PlutusLedgerApi.V1.Value (CurrencySymbol, TokenName, Value (..)) | ||
import PlutusTx (FromData (..), ToData (..), UnsafeFromData (..)) | ||
import PlutusTx.AssocMap (Map) | ||
import PlutusTx.AssocMap qualified as Map | ||
import PlutusTx.Blueprint.Class (HasBlueprintSchema (..)) | ||
import PlutusTx.Blueprint.Definition (HasBlueprintDefinition (..), definitionIdFromType, | ||
definitionRef) | ||
import PlutusTx.Blueprint.Schema (MapSchema (..), Schema (..)) | ||
import PlutusTx.Blueprint.Schema.Annotation (emptySchemaInfo, title) | ||
import PlutusTx.Lift (makeLift) | ||
import Prelude qualified as Haskell | ||
import Prettyprinter (Pretty) | ||
import Prettyprinter.Extras (PrettyShow (PrettyShow)) | ||
|
||
{- Note [MintValue vs Value] | ||
'MintValue' differs conceptually from 'Value' in how negative quantities are interpreted: | ||
In 'MintValue', negative quantities are interpreted as assets being burned. For 'Value', | ||
negative quantities are either don't make sense (e.g. in a transaction output) or interpreted | ||
as a negative balance. | ||
We want to distinguish these at the type level to avoid using 'MintValue' where 'Value' is assumed. | ||
Users should project 'MintValue' into 'Value' using 'mintValueMinted' or 'mintValueBurned'. | ||
-} | ||
|
||
-- | A 'MintValue' represents assets that are minted and burned in a transaction. | ||
newtype MintValue = UnsafeMintValue (Map CurrencySymbol (Map TokenName Integer)) | ||
deriving stock (Generic, Data, Typeable, Haskell.Show) | ||
deriving anyclass (NFData) | ||
deriving newtype (ToData, FromData, UnsafeFromData) | ||
deriving (Pretty) via (PrettyShow MintValue) | ||
|
||
instance Haskell.Eq MintValue where | ||
l == r = mintValueMinted l == mintValueMinted r && mintValueBurned l == mintValueBurned r | ||
|
||
instance HasBlueprintDefinition MintValue where | ||
type Unroll MintValue = '[MintValue, CurrencySymbol, TokenName, Integer] | ||
definitionId = definitionIdFromType @MintValue | ||
|
||
instance HasBlueprintSchema MintValue referencedTypes where | ||
{-# INLINEABLE schema #-} | ||
schema = | ||
SchemaMap | ||
emptySchemaInfo{title = Just "MintValue"} | ||
MkMapSchema | ||
{ keySchema = definitionRef @CurrencySymbol | ||
, valueSchema = | ||
SchemaMap | ||
emptySchemaInfo | ||
MkMapSchema | ||
{ keySchema = definitionRef @TokenName | ||
, valueSchema = definitionRef @Integer | ||
, minItems = Nothing | ||
, maxItems = Nothing | ||
} | ||
, minItems = Nothing | ||
, maxItems = Nothing | ||
} | ||
|
||
{-# INLINEABLE emptyMintValue #-} | ||
emptyMintValue :: MintValue | ||
emptyMintValue = UnsafeMintValue Map.empty | ||
|
||
{-# INLINEABLE mintValueToMap #-} | ||
mintValueToMap :: MintValue -> Map CurrencySymbol (Map TokenName Integer) | ||
mintValueToMap (UnsafeMintValue m) = m | ||
|
||
-- | Get the 'Value' minted by the 'MintValue'. | ||
{-# INLINEABLE mintValueMinted #-} | ||
mintValueMinted :: MintValue -> Value | ||
mintValueMinted (UnsafeMintValue values) = filterQuantities (\x -> [x | x > 0]) values | ||
|
||
{- | Get the 'Value' burned by the 'MintValue'. | ||
All the negative quantities in the 'MintValue' become positive in the resulting 'Value'. | ||
-} | ||
{-# INLINEABLE mintValueBurned #-} | ||
mintValueBurned :: MintValue -> Value | ||
mintValueBurned (UnsafeMintValue values) = filterQuantities (\x -> [abs x | x < 0]) values | ||
|
||
{-# INLINEABLE filterQuantities #-} | ||
filterQuantities :: (Integer -> [Integer]) -> Map CurrencySymbol (Map TokenName Integer) -> Value | ||
filterQuantities mapQuantity values = | ||
Value (Map.unsafeFromList (foldr filterTokenQuantities [] (Map.toList values))) | ||
where | ||
{-# INLINEABLE filterTokenQuantities #-} | ||
filterTokenQuantities | ||
:: (CurrencySymbol, Map TokenName Integer) | ||
-> [(CurrencySymbol, Map TokenName Integer)] | ||
-> [(CurrencySymbol, Map TokenName Integer)] | ||
filterTokenQuantities (currency, tokenQuantities) = | ||
case concatMap (traverse mapQuantity) (Map.toList tokenQuantities) of | ||
[] -> id | ||
quantities -> ((currency, Map.unsafeFromList quantities) :) | ||
|
||
---------------------------------------------------------------------------------------------------- | ||
-- TH Splices -------------------------------------------------------------------------------------- | ||
|
||
$(makeLift ''MintValue) |
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.