Skip to content

Commit 12d594a

Browse files
committed
added draft of adjust unbalanced
1 parent 1f18513 commit 12d594a

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/BotPlutusInterface/Contract.hs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ import Data.Vector qualified as V
5656
import Ledger (POSIXTime)
5757
import Ledger qualified
5858
import Ledger.Address (PaymentPubKeyHash (PaymentPubKeyHash))
59-
import Ledger.Constraints.OffChain (UnbalancedTx (..))
59+
import Ledger.Constraints.OffChain (UnbalancedTx (..), adjustUnbalancedTx)
60+
import Ledger.Params (Params(Params))
6061
import Ledger.Slot (Slot (Slot))
62+
import Ledger.TimeSlot (SlotConfig (..))
6163
import Ledger.Tx (CardanoTx (CardanoApiTx, EmulatorTx))
6264
import Ledger.Tx qualified as Tx
6365
import 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

Comments
 (0)