Skip to content

Commit d666eaf

Browse files
author
Jamie Bertram
committed
Remove txbody POST response and tx PUT request
1 parent 6457498 commit d666eaf

File tree

18 files changed

+337
-1027
lines changed

18 files changed

+337
-1027
lines changed

marlowe-integration-tests/test/Language/Marlowe/Runtime/Web/Common.hs

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ module Language.Marlowe.Runtime.Web.Common (
1414
) where
1515

1616
import 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
)
2527
import Control.Concurrent (threadDelay)
2628
import Control.Monad.IO.Class (MonadIO (liftIO))
2729
import Data.Set (Set)
2830
import qualified Data.Set as Set
29-
import Data.String (IsString (..))
30-
import qualified Data.Text as T
3131
import qualified Language.Marlowe as V1
3232
import 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

112112
submitContract
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

122122
submitTransaction
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

132132
submitWithdrawal
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
150150
deposit 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
160160
choose wallet contractId choice party chosenNum =
161161
applyInputs wallet contractId [NormalInput $ IChoice (ChoiceId choice party) chosenNum]
162162

163163
notify
164164
:: Wallet
165165
-> Web.TxOutRef
166-
-> ClientM (Web.ApplyInputsTxEnvelope Web.CardanoTxBody)
166+
-> ClientM Web.ApplyInputsTxEnvelope
167167
notify wallet contractId = applyInputs wallet contractId [NormalInput INotify]
168168

169169
withdraw
170170
:: Wallet
171171
-> Set Web.TxOutRef
172-
-> ClientM (Web.WithdrawTxEnvelope Web.CardanoTxBody)
172+
-> ClientM Web.WithdrawTxEnvelope
173173
withdraw 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
191191
applyInputs 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

225230
waitUntilConfirmed :: (MonadIO m) => (a -> Web.TxStatus) -> m a -> m a
226231
waitUntilConfirmed getStatus getResource = do

marlowe-integration-tests/test/Language/Marlowe/Runtime/Web/Contracts/Contract/Post.hs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ module Language.Marlowe.Runtime.Web.Contracts.Contract.Post where
55
import Control.Monad.IO.Class (MonadIO (liftIO))
66

77
import Cardano.Api (
8-
AsType (..),
8+
BabbageEra,
99
TxBody (..),
1010
TxBodyContent (..),
1111
TxMetadata (TxMetadata),
1212
TxMetadataInEra (..),
1313
TxMetadataSupportedInEra (TxMetadataInBabbageEra),
1414
TxMetadataValue (..),
15-
deserialiseFromTextEnvelope,
15+
getTxBody,
1616
)
1717
import Data.Aeson (Value (String))
1818
import qualified Data.Aeson.Key as Key
@@ -132,10 +132,8 @@ bugPLT8712 = do
132132
, tags = mempty
133133
}
134134
liftIO do
135-
textEnvelope <- expectJust "Failed to convert text envelope" $ fromDTO txEnvelope
136-
TxBody TxBodyContent{..} <-
137-
expectRight "Failed to deserialise tx body" $
138-
deserialiseFromTextEnvelope (AsTxBody AsBabbageEra) textEnvelope
135+
tx' <- expectJust "Failed to convert text envelope" $ fromDTO tx
136+
let TxBody TxBodyContent{..} = getTxBody @BabbageEra tx'
139137
case txMetadata of
140138
TxMetadataNone -> fail "expected metadata"
141139
TxMetadataInEra TxMetadataInBabbageEra (TxMetadata m) -> do

marlowe-integration-tests/test/Language/Marlowe/Runtime/Web/Contracts/Contract/Put.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ spec = describe "POST /contracts/{contractId}/transactions" do
3636

3737
let (contract, _, _) = standardContract partyBAddress now $ secondsToNominalDiffTime 100
3838

39-
Web.CreateTxEnvelope{contractId, txEnvelope} <-
39+
Web.CreateTxEnvelope{contractId, tx} <-
4040
postContract
4141
Nothing
4242
partyAWebChangeAddress
@@ -55,7 +55,7 @@ spec = describe "POST /contracts/{contractId}/transactions" do
5555
, minUTxODeposit = Nothing
5656
, tags = mempty
5757
}
58-
signedCreateTx <- liftIO $ signShelleyTransaction' txEnvelope signingKeys
58+
signedCreateTx <- liftIO $ signShelleyTransaction' tx signingKeys
5959
putContract contractId signedCreateTx
6060
case result of
6161
Left _ -> fail $ "Expected 200 response code - got " <> show result

marlowe-integration-tests/test/Language/Marlowe/Runtime/Web/Contracts/Transactions/Transaction/Put.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ spec = describe "PUT /contracts/{contractId}/transactions/{transaction}" do
6868

6969
let inputs = [NormalInput $ IDeposit partyA partyA ada 100_000_000]
7070

71-
Web.ApplyInputsTxEnvelope{transactionId, txEnvelope} <-
71+
Web.ApplyInputsTxEnvelope{transactionId, tx} <-
7272
postTransaction
7373
partyAWebChangeAddress
7474
(Just partyAWebExtraAddresses)
@@ -82,7 +82,7 @@ spec = describe "PUT /contracts/{contractId}/transactions/{transaction}" do
8282
, inputs
8383
, tags = mempty
8484
}
85-
applyTx <- liftIO $ signShelleyTransaction' txEnvelope signingKeys
85+
applyTx <- liftIO $ signShelleyTransaction' tx signingKeys
8686
putTransaction contractId transactionId applyTx
8787
case result of
8888
Left _ -> fail $ "Expected 200 response code - got " <> show result

marlowe-integration-tests/test/Language/Marlowe/Runtime/Web/StandardContract.hs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import Language.Marlowe.Runtime.Transaction.Api (WalletAddresses (..))
2222
import Language.Marlowe.Runtime.Web (
2323
ApplyInputsTxEnvelope,
2424
BlockHeader,
25-
CardanoTxBody,
2625
ContractOrSourceId (..),
2726
CreateTxEnvelope,
2827
PayoutHeader (..),
@@ -49,31 +48,31 @@ import Servant.Client.Streaming (ClientM)
4948

5049
data StandardContractInit = StandardContractInit
5150
{ makeInitialDeposit :: ClientM StandardContractFundsDeposited
52-
, contractCreated :: CreateTxEnvelope CardanoTxBody
51+
, contractCreated :: CreateTxEnvelope
5352
, createdBlock :: BlockHeader
5453
}
5554

5655
data StandardContractFundsDeposited = StandardContractFundsDeposited
5756
{ chooseGimmeTheMoney :: ClientM StandardContractChoiceMade
58-
, initialFundsDeposited :: ApplyInputsTxEnvelope CardanoTxBody
57+
, initialFundsDeposited :: ApplyInputsTxEnvelope
5958
, initialDepositBlock :: BlockHeader
6059
}
6160

6261
data StandardContractChoiceMade = StandardContractChoiceMade
6362
{ sendNotify :: ClientM StandardContractNotified
64-
, gimmeTheMoneyChosen :: ApplyInputsTxEnvelope CardanoTxBody
63+
, gimmeTheMoneyChosen :: ApplyInputsTxEnvelope
6564
, choiceBlock :: BlockHeader
6665
}
6766

6867
data StandardContractNotified = StandardContractNotified
6968
{ makeReturnDeposit :: ClientM StandardContractClosed
70-
, notified :: ApplyInputsTxEnvelope CardanoTxBody
69+
, notified :: ApplyInputsTxEnvelope
7170
, notifiedBlock :: BlockHeader
7271
}
7372

7473
data StandardContractClosed = StandardContractClosed
75-
{ withdrawPartyAFunds :: ClientM (WithdrawTxEnvelope CardanoTxBody, BlockHeader)
76-
, returnDeposited :: ApplyInputsTxEnvelope CardanoTxBody
74+
{ withdrawPartyAFunds :: ClientM (WithdrawTxEnvelope, BlockHeader)
75+
, returnDeposited :: ApplyInputsTxEnvelope
7776
, returnDepositBlock :: BlockHeader
7877
}
7978

marlowe-integration-tests/test/Language/Marlowe/Runtime/Web/Withdrawal/Put.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ spec = describe "PUT /contracts/{contractId}/withdrawals/{withdrawalId}" do
4444
Page{..} <- getPayouts (Just $ Set.singleton contractId) Nothing (Just Available) Nothing
4545
let payouts = Set.fromList $ payoutId <$> items
4646

47-
Web.WithdrawTxEnvelope{withdrawalId, txEnvelope} <-
47+
Web.WithdrawTxEnvelope{withdrawalId, tx} <-
4848
postWithdrawal webChangeAddress (Just webExtraAddresses) (Just webCollateralUtxos) Web.PostWithdrawalsRequest{..}
49-
signedWithdrawalTx <- liftIO $ signShelleyTransaction' txEnvelope signingKeys
49+
signedWithdrawalTx <- liftIO $ signShelleyTransaction' tx signingKeys
5050
putWithdrawal withdrawalId signedWithdrawalTx
5151

5252
case result of

0 commit comments

Comments
 (0)