@@ -14,20 +14,20 @@ module Language.Marlowe.Runtime.Web.Common (
1414) where
1515
1616import Cardano.Api (
17- AsType (.. ),
17+ CardanoEra (.. ),
18+ ShelleyBasedEra (ShelleyBasedEraBabbage ),
1819 ShelleyWitnessSigningKey (.. ),
19- TextEnvelope (.. ),
20- TextEnvelopeType (.. ),
21- deserialiseFromTextEnvelope ,
22- serialiseToTextEnvelope ,
20+ TextEnvelopeCddl (.. ),
21+ deserialiseTxLedgerCddl ,
22+ getTxBody ,
23+ getTxWitnesses ,
24+ serialiseWitnessLedgerCddl ,
2325 signShelleyTransaction ,
2426 )
2527import Control.Concurrent (threadDelay )
2628import Control.Monad.IO.Class (MonadIO (liftIO ))
2729import Data.Set (Set )
2830import qualified Data.Set as Set
29- import Data.String (IsString (.. ))
30- import qualified Data.Text as T
3131import qualified Language.Marlowe as V1
3232import Language.Marlowe.Core.V1.Semantics.Types (
3333 ChoiceId (ChoiceId ),
@@ -60,7 +60,7 @@ createCloseContract Wallet{..} = do
6060 let webExtraAddresses = Set. map toDTO extraAddresses
6161 let webCollateralUtxos = Set. map toDTO collateralUtxos
6262
63- Web. CreateTxEnvelope {txEnvelope , .. } <-
63+ Web. CreateTxEnvelope {tx , .. } <-
6464 postContract
6565 Nothing
6666 webChangeAddress
@@ -76,7 +76,7 @@ createCloseContract Wallet{..} = do
7676 , tags = mempty
7777 }
7878
79- createTx <- liftIO $ signShelleyTransaction' txEnvelope signingKeys
79+ createTx <- liftIO $ signShelleyTransaction' tx signingKeys
8080 putContract contractId createTx
8181 _ <- waitUntilConfirmed (\ Web. ContractState {status} -> status) $ getContract contractId
8282 pure contractId
@@ -87,7 +87,7 @@ applyCloseTransaction Wallet{..} contractId = do
8787 let webChangeAddress = toDTO changeAddress
8888 let webExtraAddresses = Set. map toDTO extraAddresses
8989 let webCollateralUtxos = Set. map toDTO collateralUtxos
90- Web. ApplyInputsTxEnvelope {transactionId, txEnvelope } <-
90+ Web. ApplyInputsTxEnvelope {transactionId, tx } <-
9191 postTransaction
9292 webChangeAddress
9393 (Just webExtraAddresses)
@@ -102,7 +102,7 @@ applyCloseTransaction Wallet{..} contractId = do
102102 , tags = mempty
103103 }
104104
105- applyTx <- liftIO $ signShelleyTransaction' txEnvelope signingKeys
105+ applyTx <- liftIO $ signShelleyTransaction' tx signingKeys
106106
107107 putTransaction contractId transactionId applyTx
108108
@@ -111,30 +111,30 @@ applyCloseTransaction Wallet{..} contractId = do
111111
112112submitContract
113113 :: Wallet
114- -> Web. CreateTxEnvelope Web. CardanoTxBody
114+ -> Web. CreateTxEnvelope
115115 -> ClientM Web. BlockHeader
116- submitContract Wallet {.. } Web. CreateTxEnvelope {contractId, txEnvelope } = do
117- signedCreateTx <- liftIO $ signShelleyTransaction' txEnvelope signingKeys
116+ submitContract Wallet {.. } Web. CreateTxEnvelope {contractId, tx } = do
117+ signedCreateTx <- liftIO $ signShelleyTransaction' tx signingKeys
118118 putContract contractId signedCreateTx
119119 Web. ContractState {block} <- waitUntilConfirmed (\ Web. ContractState {status} -> status) $ getContract contractId
120120 liftIO $ expectJust " Expected block header" block
121121
122122submitTransaction
123123 :: Wallet
124- -> Web. ApplyInputsTxEnvelope Web. CardanoTxBody
124+ -> Web. ApplyInputsTxEnvelope
125125 -> ClientM Web. BlockHeader
126- submitTransaction Wallet {.. } Web. ApplyInputsTxEnvelope {contractId, transactionId, txEnvelope } = do
127- signedTx <- liftIO $ signShelleyTransaction' txEnvelope signingKeys
126+ submitTransaction Wallet {.. } Web. ApplyInputsTxEnvelope {contractId, transactionId, tx } = do
127+ signedTx <- liftIO $ signShelleyTransaction' tx signingKeys
128128 putTransaction contractId transactionId signedTx
129129 Web. Tx {block} <- waitUntilConfirmed (\ Web. Tx {status} -> status) $ getTransaction contractId transactionId
130130 liftIO $ expectJust " Expected a block header" block
131131
132132submitWithdrawal
133133 :: Wallet
134- -> Web. WithdrawTxEnvelope Web. CardanoTxBody
134+ -> Web. WithdrawTxEnvelope
135135 -> ClientM Web. BlockHeader
136- submitWithdrawal Wallet {.. } Web. WithdrawTxEnvelope {withdrawalId, txEnvelope } = do
137- signedWithdrawalTx <- liftIO $ signShelleyTransaction' txEnvelope signingKeys
136+ submitWithdrawal Wallet {.. } Web. WithdrawTxEnvelope {withdrawalId, tx } = do
137+ signedWithdrawalTx <- liftIO $ signShelleyTransaction' tx signingKeys
138138 putWithdrawal withdrawalId signedWithdrawalTx
139139 Web. Withdrawal {block} <- waitUntilConfirmed (\ Web. Withdrawal {status} -> status) $ getWithdrawal withdrawalId
140140 liftIO $ expectJust " Expected a block header" block
@@ -146,7 +146,7 @@ deposit
146146 -> V1. Party
147147 -> V1. Token
148148 -> Integer
149- -> ClientM ( Web. ApplyInputsTxEnvelope Web. CardanoTxBody )
149+ -> ClientM Web. ApplyInputsTxEnvelope
150150deposit wallet contractId intoAccount fromParty ofToken quantity =
151151 applyInputs wallet contractId [NormalInput $ IDeposit intoAccount fromParty ofToken quantity]
152152
@@ -156,20 +156,20 @@ choose
156156 -> PV2. BuiltinByteString
157157 -> V1. Party
158158 -> Integer
159- -> ClientM ( Web. ApplyInputsTxEnvelope Web. CardanoTxBody )
159+ -> ClientM Web. ApplyInputsTxEnvelope
160160choose wallet contractId choice party chosenNum =
161161 applyInputs wallet contractId [NormalInput $ IChoice (ChoiceId choice party) chosenNum]
162162
163163notify
164164 :: Wallet
165165 -> Web. TxOutRef
166- -> ClientM ( Web. ApplyInputsTxEnvelope Web. CardanoTxBody )
166+ -> ClientM Web. ApplyInputsTxEnvelope
167167notify wallet contractId = applyInputs wallet contractId [NormalInput INotify ]
168168
169169withdraw
170170 :: Wallet
171171 -> Set Web. TxOutRef
172- -> ClientM ( Web. WithdrawTxEnvelope Web. CardanoTxBody )
172+ -> ClientM Web. WithdrawTxEnvelope
173173withdraw Wallet {.. } payouts = do
174174 let WalletAddresses {.. } = addresses
175175 let webChangeAddress = toDTO changeAddress
@@ -187,7 +187,7 @@ applyInputs
187187 :: Wallet
188188 -> Web. TxOutRef
189189 -> [V1. Input ]
190- -> ClientM ( Web. ApplyInputsTxEnvelope Web. CardanoTxBody )
190+ -> ClientM Web. ApplyInputsTxEnvelope
191191applyInputs Wallet {.. } contractId inputs = do
192192 let WalletAddresses {.. } = addresses
193193 let webChangeAddress = toDTO changeAddress
@@ -208,19 +208,24 @@ applyInputs Wallet{..} contractId inputs = do
208208 , tags = mempty
209209 }
210210
211- signShelleyTransaction' :: Web. TextEnvelope -> [ShelleyWitnessSigningKey ] -> IO Web. TextEnvelope
212- signShelleyTransaction' Web. TextEnvelope {.. } wits = do
211+ signShelleyTransaction' :: Web. UnwitnessedTx -> [ShelleyWitnessSigningKey ] -> IO Web. TxWitness
212+ signShelleyTransaction' Web. UnwitnessedTx {.. } wits = do
213213 let te =
214- TextEnvelope
215- { teType = TextEnvelopeType ( T. unpack teType)
216- , teDescription = fromString ( T. unpack teDescription)
217- , teRawCBOR = Web. unBase16 teCborHex
214+ TextEnvelopeCddl
215+ { teCddlType = utType
216+ , teCddlDescription = utDescription
217+ , teCddlRawCBOR = Web. unBase16 utCborHex
218218 }
219- txBody <- case deserialiseFromTextEnvelope ( AsTxBody AsBabbage ) te of
219+ txBody <- case deserialiseTxLedgerCddl BabbageEra te of
220220 Left err -> fail $ show err
221221 Right a -> pure a
222- pure case serialiseToTextEnvelope Nothing $ signShelleyTransaction txBody wits of
223- TextEnvelope (TextEnvelopeType ty) _ bytes -> Web. TextEnvelope (T. pack ty) " " $ Web. Base16 bytes
222+ let witnessCddl =
223+ serialiseWitnessLedgerCddl ShelleyBasedEraBabbage $
224+ head $
225+ getTxWitnesses $
226+ signShelleyTransaction (getTxBody txBody) wits
227+ pure case witnessCddl of
228+ TextEnvelopeCddl ty _ bytes -> Web. TxWitness ty " " $ Web. Base16 bytes
224229
225230waitUntilConfirmed :: (MonadIO m ) => (a -> Web. TxStatus ) -> m a -> m a
226231waitUntilConfirmed getStatus getResource = do
0 commit comments