@@ -21,6 +21,10 @@ type TxGenerator era = [Fund] -> [TxOut CtxTx era] -> Either String (Tx era, TxI
21
21
22
22
type ToUTxO era = Lovelace -> (TxOut CtxTx era , TxIx -> TxId -> Fund )
23
23
24
+ type ToUTxOList era = [Lovelace ] -> ([TxOut CtxTx era ], TxId -> [Fund ])
25
+ -- 'ToUTxOList era' is more powerful than '[ ToUTxO era ]' but
26
+ -- '[ ToUTxO era ]` is easier to construct.
27
+
24
28
data Wallet = Wallet {
25
29
walletSeqNumber :: ! SeqNumber
26
30
, walletFunds :: ! FundSet
@@ -74,15 +78,23 @@ mkWalletFundStore :: WalletRef -> FundToStore IO
74
78
mkWalletFundStore walletRef funds = modifyWalletRef walletRef
75
79
$ \ wallet -> return (foldl (flip walletInsertFund) wallet funds, () )
76
80
81
+ makeToUTxOList :: [ ToUTxO era ] -> ToUTxOList era
82
+ makeToUTxOList fkts values
83
+ = (outs, \ txId -> map (\ f -> f txId) fs)
84
+ where
85
+ (outs, fs) = unzip $ map worker $ zip3 fkts values [TxIx 0 .. ]
86
+ worker (toUTxO, value, idx)
87
+ = let (o, f ) = toUTxO value
88
+ in (o, f idx)
89
+
77
90
-- TODO use Error monad
78
91
sourceToStoreTransaction ::
79
- Monad m
80
- => TxGenerator era
81
- -> FundSource m
92
+ TxGenerator era
93
+ -> FundSource IO
82
94
-> ([Lovelace ] -> [Lovelace ])
83
- -> [ ToUTxO era ]
84
- -> FundToStore m
85
- -> m (Either String (Tx era ))
95
+ -> ToUTxOList era
96
+ -> FundToStore IO
97
+ -> IO (Either String (Tx era ))
86
98
sourceToStoreTransaction txGenerator fundSource inToOut mkTxOut fundToStore = do
87
99
fundSource >>= \ case
88
100
Left err -> return $ Left err
@@ -91,14 +103,11 @@ sourceToStoreTransaction txGenerator fundSource inToOut mkTxOut fundToStore = do
91
103
work inputFunds = do
92
104
let
93
105
outValues = inToOut $ map getFundLovelace inputFunds
94
- outs = zipWith ($) mkTxOut outValues
95
- case txGenerator inputFunds $ map fst outs of
106
+ (outputs, toFunds) = mkTxOut outValues
107
+ case txGenerator inputFunds outputs of
96
108
Left err -> return $ Left err
97
109
Right (tx, txId) -> do
98
- let
99
- fkt :: (a , TxIx -> TxId -> Fund ) -> TxIx -> Fund
100
- fkt a txIx = snd a txIx txId
101
- fundToStore $ zipWith fkt outs [TxIx 0 .. ]
110
+ fundToStore $ toFunds txId
102
111
return $ Right tx
103
112
104
113
includeChange :: Lovelace -> [Lovelace ] -> [Lovelace ] -> [Lovelace ]
@@ -226,7 +235,7 @@ benchmarkWalletScript :: forall era .
226
235
-> NumberOfTxs
227
236
-> (Target -> FundSource IO )
228
237
-> ([Lovelace ] -> [Lovelace ])
229
- -> ( Target -> SeqNumber -> [ToUTxO era ])
238
+ -> ( Target -> SeqNumber -> [ToUTxO era ] )
230
239
-> FundToStore IO
231
240
-> Target
232
241
-> WalletScript era
@@ -239,7 +248,7 @@ benchmarkWalletScript wRef txGenerator (NumberOfTxs maxCount) fundSource inOut t
239
248
walletStep = modifyMVarMasked wRef nextSeqNumber >>= \ case
240
249
Nothing -> return Done
241
250
Just seqNumber -> do
242
- sourceToStoreTransaction txGenerator (fundSource targetNode) inOut (toUTxO targetNode seqNumber) fundToStore >>= \ case
251
+ sourceToStoreTransaction txGenerator (fundSource targetNode) inOut (makeToUTxOList $ toUTxO targetNode seqNumber) fundToStore >>= \ case
243
252
Left err -> return $ Error err
244
253
Right tx -> return $ NextTx nextCall tx
245
254
0 commit comments