@@ -56,8 +56,10 @@ import Data.Vector qualified as V
5656import Ledger (POSIXTime )
5757import Ledger qualified
5858import Ledger.Address (PaymentPubKeyHash (PaymentPubKeyHash ))
59- import Ledger.Constraints.OffChain (UnbalancedTx (.. ))
59+ import Ledger.Constraints.OffChain (UnbalancedTx (.. ), adjustUnbalancedTx )
60+ import Ledger.Params (Params (Params ))
6061import Ledger.Slot (Slot (Slot ))
62+ import Ledger.TimeSlot (SlotConfig (.. ))
6163import Ledger.Tx (CardanoTx (CardanoApiTx , EmulatorTx ))
6264import Ledger.Tx qualified as Tx
6365import Plutus.ChainIndex.TxIdState (fromTx , transactionStatus )
@@ -189,6 +191,7 @@ handlePABReq contractEnv req = do
189191 either (error . show ) (PosixTimeRangeToContainedSlotRangeResp . Right )
190192 <$> posixTimeRangeToContainedSlotRange @ w posixTimeRange
191193 AwaitTxStatusChangeReq txId -> AwaitTxStatusChangeResp txId <$> awaitTxStatusChange @ w contractEnv txId
194+ AdjustUnbalancedTxReq unbalancedTx -> AdjustUnbalancedTxResp <$> adjustUnbalancedTx' @ w contractEnv unbalancedTx
192195 ------------------------
193196 -- Unhandled requests --
194197 ------------------------
@@ -203,6 +206,28 @@ handlePABReq contractEnv req = do
203206 printBpiLog @ w Debug $ pretty resp
204207 pure resp
205208
209+
210+ adjustUnbalancedTx' ::
211+ forall (w :: Type ) (effs :: [Type -> Type ]).
212+ -- Member (PABEffect w) effs =>
213+ ContractEnvironment w ->
214+ UnbalancedTx ->
215+ Eff effs (Either Tx. ToCardanoError UnbalancedTx )
216+ adjustUnbalancedTx' contractEnv unbalancedTx = do
217+ let slotConfig = SlotConfig 20000 1654524000
218+ maybeProtocolParams = contractEnv. cePABConfig. pcProtocolParams
219+ networkId = contractEnv. cePABConfig. pcNetwork
220+ maybeParams = do {pparams <- maybeProtocolParams; return $ Params slotConfig pparams networkId}
221+ case maybeParams of
222+ Just params -> pure $ snd <$> adjustUnbalancedTx params unbalancedTx
223+ _ -> pure . Left $ Tx. TxBodyError " no protocol params"
224+
225+
226+
227+
228+
229+
230+
206231{- | Await till transaction status change to something from `Unknown`.
207232 Uses `chain-index` to query transaction by id.
208233 Important notes:
0 commit comments