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

Add simple script mint/spend #202

Merged
merged 1 commit into from
Sep 5, 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
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
14 changes: 14 additions & 0 deletions src/base/lib/Convex/BuildTx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module Convex.BuildTx(
spendPlutusV2RefWithoutInRef,
spendPlutusV2RefWithoutInRefInlineDatum,
spendPlutusV2InlineDatum,
spendSimpleScript,

-- ** Adding outputs
payToAddress,
Expand All @@ -81,6 +82,7 @@ module Convex.BuildTx(
mintPlutusV1,
mintPlutusV2,
mintPlutusV2Ref,
mintSimpleScriptAssets,

-- ** Constructing script witness
buildV1ScriptWitness,
Expand Down Expand Up @@ -124,6 +126,7 @@ import Convex.Class (MonadBlockchain (..),
import Convex.MonadLog (MonadLog (..), MonadLogIgnoreT,
MonadLogKatipT)
import Convex.Scripts (toHashableScriptData)
import Data.Foldable (traverse_)
import Data.Functor.Identity (Identity (..))
import Data.List (nub)
import qualified Data.Map as Map
Expand Down Expand Up @@ -475,6 +478,17 @@ mintPlutusV2Ref refTxIn sh red assetName quantity =
>> addBtx (over (L.txMintValue . L._TxMintValue) (over _1 (<> v) . over _2 (Map.insert policyId wit)))
>> addReference refTxIn

mintSimpleScriptAssets :: MonadBuildTx m => C.SimpleScript -> [(C.AssetName, C.Quantity)] -> m ()
mintSimpleScriptAssets sscript assets =
let wit = C.SimpleScriptWitness C.SimpleScriptInBabbage (C.SScript sscript)
policyId = C.scriptPolicyId . C.SimpleScript $ sscript
in traverse_ (\(an,q) -> addMintWithTxBody policyId an q (const wit)) assets

spendSimpleScript :: MonadBuildTx m => C.TxIn -> C.SimpleScript -> m ()
spendSimpleScript txIn sscript =
let wit = C.SimpleScriptWitness C.SimpleScriptInBabbage (C.SScript sscript)
in addBtx (over L.txIns ((txIn, C.BuildTxWith $ C.ScriptWitness C.ScriptWitnessForSpending wit) :))

addCollateral :: MonadBuildTx m => C.TxIn -> m ()
addCollateral i = addBtx $ over (L.txInsCollateral . L._TxInsCollateralIso) ((:) i)

Expand Down
10 changes: 6 additions & 4 deletions src/base/lib/Convex/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ import Cardano.Ledger.Shelley.API (ApplyTxError
MempoolEnv,
MempoolState,
UTxO (..),
Validated, extractTx)
Validated,
extractTx)
import Cardano.Ledger.Shelley.LedgerState (certDStateL,
dsUnifiedL,
lsCertStateL,
Expand All @@ -98,7 +99,8 @@ import Cardano.Ledger.UMap (RDPair (..),
compactCoinOrError)
import Cardano.Slotting.Time (SlotLength,
SystemStart)
import Control.Lens (_1, set, view, (^.), to)
import Control.Lens (_1, set, to,
view, (^.))
import Control.Lens.TH (makeLensesFor,
makePrisms)
import Control.Monad.Except (MonadError,
Expand Down Expand Up @@ -355,8 +357,8 @@ setUtxo :: MonadMockchain m => UTxO ERA -> m ()
setUtxo u = modifyUtxo (const (u, ()))

{-| Return all Tx's from the ledger state -}
getTxs :: MonadMockchain m => m [Core.Tx ERA]
getTxs = getMockChainState <&> view (transactions . traverse . _1 . to ((: []) . extractTx))
getTxs :: MonadMockchain m => m [C.Tx C.BabbageEra] -- [Core.Tx ERA]
getTxs = getMockChainState <&> view (transactions . traverse . _1 . to ((: []) . C.ShelleyTx C.ShelleyBasedEraBabbage . extractTx))

{-| Return all Tx's from the ledger state -}

Expand Down
Loading