@@ -12,6 +12,7 @@ module BotPlutusInterface.CardanoCLI (
1212 validatorScriptFilePath ,
1313 unsafeSerialiseAddress ,
1414 policyScriptFilePath ,
15+ validateRange ,
1516 utxosAt ,
1617 queryTip ,
1718) where
@@ -49,10 +50,17 @@ import Data.Set qualified as Set
4950import Data.Text (Text )
5051import Data.Text qualified as Text
5152import Data.Text.Encoding (decodeUtf8 )
53+ import Ledger (Slot (Slot ), SlotRange )
5254import Ledger qualified
5355import Ledger.Ada qualified as Ada
5456import Ledger.Address (Address (.. ))
5557import Ledger.Crypto (PubKey , PubKeyHash )
58+ import Ledger.Interval (
59+ Extended (Finite , NegInf , PosInf ),
60+ Interval (Interval ),
61+ LowerBound (LowerBound ),
62+ UpperBound (UpperBound ),
63+ )
5664import Ledger.Scripts (Datum , DatumHash (.. ))
5765import Ledger.Scripts qualified as Scripts
5866import Ledger.Tx (
@@ -185,9 +193,7 @@ isRawBuildMode :: BuildMode -> Bool
185193isRawBuildMode (BuildRaw _) = True
186194isRawBuildMode _ = False
187195
188- {- | Build a tx body and write it to disk
189- If a fee if specified, it uses the build-raw command
190- -}
196+ -- | Build a tx body and write it to disk
191197buildTx ::
192198 forall (w :: Type ) (effs :: [Type -> Type ]).
193199 Member (PABEffect w ) effs =>
@@ -211,6 +217,7 @@ buildTx pabConf ownPkh buildMode tx =
211217 , txInCollateralOpts (txCollateral tx)
212218 , txOutOpts pabConf (txData tx) (txOutputs tx)
213219 , mintOpts pabConf buildMode (txMintScripts tx) (txRedeemers tx) (txMint tx)
220+ , validRangeOpts (txValidRange tx)
214221 , requiredSigners
215222 , case buildMode of
216223 BuildRaw fee -> [" --fee" , showText fee]
@@ -350,6 +357,20 @@ mintOpts pabConf buildMode mintingPolicies redeemers mintValue =
350357 else []
351358 ]
352359
360+ -- | This function does not check if the range is valid, that
361+ validRangeOpts :: SlotRange -> [Text ]
362+ validRangeOpts (Interval lowerBound upperBound) =
363+ mconcat
364+ [ case lowerBound of
365+ LowerBound (Finite (Slot x)) True -> [" --invalid-hereafter" , showText x]
366+ LowerBound (Finite (Slot x)) False -> [" --invalid-hereafter" , showText (x + 1 )]
367+ _ -> []
368+ , case upperBound of
369+ UpperBound (Finite (Slot x)) True -> [" --invalid-before" , showText (x + 1 )]
370+ UpperBound (Finite (Slot x)) False -> [" --invalid-before" , showText x]
371+ _ -> []
372+ ]
373+
353374txOutOpts :: PABConfig -> Map DatumHash Datum -> [TxOut ] -> [Text ]
354375txOutOpts pabConf datums =
355376 concatMap
@@ -417,6 +438,14 @@ exBudgetToCliArg (ExBudget (ExCPU steps) (ExMemory memory)) =
417438showText :: forall (a :: Type ). Show a => a -> Text
418439showText = Text. pack . show
419440
441+ validateRange :: SlotRange -> Bool
442+ validateRange (Interval (LowerBound PosInf _) _) = False
443+ validateRange (Interval _ (UpperBound NegInf _)) = False
444+ validateRange (Interval (LowerBound (Finite lowerBound) _) (UpperBound (Finite upperBound) _))
445+ | lowerBound >= upperBound = False
446+ | otherwise = True
447+ validateRange _ = True
448+
420449-- -- TODO: There is some issue with this function, the generated wallet key is incorrect
421450-- toWalletKey :: Wallet -> Text
422451-- toWalletKey =
0 commit comments