Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#365): add valueAlter and some typeclass instances for `GYTxWi… #367

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 0.6.2

* Give `Eq`, `Semigroup`, `Monoid` instance for `GYTxWitness`.
* Adds `valueAlter` utility function inside `GeniusYield.Types.Value` module.
5 changes: 3 additions & 2 deletions atlas-cardano.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.8
name: atlas-cardano
version: 0.6.1
version: 0.6.2
synopsis: Application backend for Plutus smart contracts on Cardano
description:
Atlas is an all-in-one, Haskell-native application backend for writing off-chain code for on-chain Plutus smart contracts.
Expand All @@ -14,7 +14,8 @@ build-type: Simple
category: Blockchain, Cardano, Framework
homepage: https://github.com/geniusyield/atlas#readme
bug-reports: https://github.com/geniusyield/atlas/issues
extra-source-files: README.md
extra-source-files: CHANGELOG.md
README.md
tested-with:
GHC ==9.6.5
|| ==9.6.6
Expand Down
2 changes: 1 addition & 1 deletion src/GeniusYield/Types/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ txIdFromPlutus (PlutusTxIdV3 (PlutusV3.TxId (Plutus.BuiltinByteString bs))) = tx

-- | Wrapper around transaction witness set. Note that Babbage ledger also uses the same @TxWitness@ type defined in Alonzo ledger, which was updated for Plutus-V2 scripts and same is expected for Plutus-V3.
newtype GYTxWitness = GYTxWitness (AlonzoTxWits (Conway.ConwayEra Crypto.StandardCrypto))
deriving newtype Show
deriving newtype (Show, Eq, Semigroup, Monoid)

instance Swagger.ToSchema GYTxWitness where
declareNamedSchema _ =
Expand Down
17 changes: 16 additions & 1 deletion src/GeniusYield/Types/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module GeniusYield.Types.Value (
valueTotalAssets,
valueInsert,
valueAdjust,
valueAlter,
valueFromLovelace,
valueFromApiTxOutValue,
valueToApiTxOutValue,
Expand Down Expand Up @@ -253,10 +254,24 @@ valueInsert :: GYAssetClass -> Integer -> GYValue -> GYValue
valueInsert asc 0 (GYValue m) = GYValue (Map.delete asc m)
valueInsert asc i (GYValue m) = GYValue (Map.insert asc i m)

-- | Adjust the amount of a given 'GYAssetClass' in the given 'GYValue'.
{- | Adjust the amount of a given 'GYAssetClass' in the given 'GYValue'.
If the asset is not present in the value, original value is returned instead.
-}
valueAdjust :: (Integer -> Integer) -> GYAssetClass -> GYValue -> GYValue
valueAdjust f asc (GYValue m) = GYValue (Map.adjust f asc m)

{- | The expression (@'valueAlter' f asc val@) alters the value @x@ at @asc@, or absence thereof.
'valueAlter' can be used to insert, delete, or update a value in a 'GYValue'.

>>> valueAlter (Just . maybe 1 (+ 1)) GYLovelace $ mempty
valueFromList [(GYLovelace,1)]

>>> valueAlter (Just . maybe 1 (+ 1)) GYLovelace $ valueFromList [(GYLovelace, 1)]
valueFromList [(GYLovelace,2)]
-}
valueAlter :: (Maybe Integer -> Maybe Integer) -> GYAssetClass -> GYValue -> GYValue
valueAlter f asc (GYValue m) = GYValue (Map.alter f asc m)

-- | Set of assets within a 'GYValue' in non-zero quantities.
valueAssets :: GYValue -> Set GYAssetClass
valueAssets (GYValue m) = Map.keysSet m
Expand Down
2 changes: 0 additions & 2 deletions tests-privnet/GeniusYield/Test/Privnet/SimpleScripts.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import GeniusYield.Test.Privnet.Ctx
import GeniusYield.Test.Privnet.Setup
import GeniusYield.TxBuilder
import GeniusYield.Types
import GeniusYield.Types.Script (GYAnyScript (GYSimpleScript))
import GeniusYield.Types.UTxO (GYUTxO (utxoRefScript))
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.HUnit (testCaseSteps)

Expand Down
Loading