Skip to content

Commit 27cb805

Browse files
author
gege251
committed
Refactor
1 parent d2ae5aa commit 27cb805

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

examples/plutus-transfer/src/Cardano/PlutusExample/Transfer.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Data.Aeson.TH (defaultOptions, deriveJSON)
1212
import Data.Bifunctor (first)
1313
import Data.Monoid (Last (Last))
1414
import Data.Text (Text)
15+
import Data.Void (Void)
1516
import GHC.Generics (Generic)
1617
import Ledger hiding (singleton)
1718
import Ledger.Constraints as Constraints
@@ -35,10 +36,12 @@ transfer :: TransferParams -> Contract (Last Text) TransferSchema Text ()
3536
transfer (TransferParams outputPerTx allPayments) = do
3637
tell $ Last $ Just "Contract started"
3738
let txs =
38-
map (mconcat . map (uncurry Constraints.mustPayToPubKey . first PaymentPubKeyHash)) $
39-
group outputPerTx allPayments
39+
map toTx $ group outputPerTx allPayments
4040
forM_ txs $ \tx -> submitTx tx >> waitNSlots 1
4141
tell $ Last $ Just "Finished"
42+
where
43+
toTx :: [(PubKeyHash, Value)] -> TxConstraints Void Void
44+
toTx = mconcat . map (uncurry Constraints.mustPayToPubKey . first PaymentPubKeyHash)
4245

4346
group :: Int -> [a] -> [[a]]
4447
group n list

src/BotPlutusInterface/CardanoCLI.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import Control.Monad.Freer (Eff, Member)
3333
import Data.Aeson qualified as JSON
3434
import Data.Aeson.Extras (encodeByteString)
3535
import Data.Attoparsec.Text (parseOnly)
36+
import Data.Bool (bool)
3637
import Data.ByteString.Lazy qualified as LazyByteString
3738
import Data.ByteString.Lazy.Char8 qualified as Char8
3839
import Data.ByteString.Short qualified as ShortByteString
@@ -356,17 +357,17 @@ mintOpts pabConf buildMode mintingPolicies redeemers mintValue =
356357
else []
357358
]
358359

359-
-- | This function does not check if the range is valid, that
360+
-- | This function does not check if the range is valid, for that see `PreBalance.validateRange`
360361
validRangeOpts :: SlotRange -> [Text]
361362
validRangeOpts (Interval lowerBound upperBound) =
362363
mconcat
363364
[ case lowerBound of
364-
LowerBound (Finite (Slot x)) True -> ["--invalid-before", showText x]
365-
LowerBound (Finite (Slot x)) False -> ["--invalid-before", showText (x + 1)]
365+
LowerBound (Finite (Slot x)) closed ->
366+
["--invalid-before", showText (bool (x + 1) x closed)]
366367
_ -> []
367368
, case upperBound of
368-
UpperBound (Finite (Slot x)) True -> ["--invalid-hereafter", showText (x + 1)]
369-
UpperBound (Finite (Slot x)) False -> ["--invalid-hereafter", showText x]
369+
UpperBound (Finite (Slot x)) closed ->
370+
["--invalid-hereafter", showText (bool x (x + 1) closed)]
370371
_ -> []
371372
]
372373

src/BotPlutusInterface/PreBalance.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ validateRange (Interval (LowerBound PosInf _) _) = False
283283
validateRange (Interval _ (UpperBound NegInf _)) = False
284284
validateRange (Interval (LowerBound (Finite lowerBound) _) (UpperBound (Finite upperBound) _))
285285
| lowerBound >= upperBound = False
286-
| otherwise = True
287286
validateRange _ = True
288287

289288
showText :: forall (a :: Type). Show a => a -> Text

test/Spec/BotPlutusInterface/Contract.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ waitNextBlock = do
756756
contract :: Contract () (Endpoint "SendAda" ()) Text Slot
757757
contract = waitNSlots 1
758758

759-
let (result, state) = runContractPure contract initState
759+
(result, state) = runContractPure contract initState
760760

761761
case result of
762762
Left errMsg -> assertFailure (show errMsg)

test/Spec/MockContract.hs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,14 @@ mockQueryTip :: forall (w :: Type). MockContract w String
318318
mockQueryTip = do
319319
state <- get @(MockContractState w)
320320

321-
let slot = Text.pack $ show $ getSlot $ tipSlot (state ^. tip)
322-
blockId = decodeUtf8 $ getBlockId $ tipBlockId (state ^. tip)
323-
blockNo = Text.pack $ show $ unBlockNumber $ tipBlockNo (state ^. tip)
321+
let (slot, blockId, blockNo) =
322+
case state ^. tip of
323+
TipAtGenesis -> ("0", "00", "0")
324+
Tip {tipSlot, tipBlockId, tipBlockNo} ->
325+
( Text.pack $ show $ getSlot tipSlot
326+
, decodeUtf8 $ getBlockId tipBlockId
327+
, Text.pack $ show $ unBlockNumber tipBlockNo
328+
)
324329
pure $
325330
Text.unpack
326331
[text|{

0 commit comments

Comments
 (0)