Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 60602d3

Browse files
committedDec 7, 2023
sum type for BuildCreateContractTxRequest
1 parent 3c03e79 commit 60602d3

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed
 

‎packages/runtime/client/rest/src/contract/endpoints/collection.ts

+35-9
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,37 @@ export const ContractOrSourceIdGuard: t.Type<ContractOrSourceId> = t.union([
213213
SourceIdGuard,
214214
]);
215215

216+
/**
217+
* Request for the {@link index.RestClient#buildCreateContractTx | Build Create Contract Tx } endpoint using a source Id (merkleized contract)
218+
* @category Endpoint : Build Create Contract Tx
219+
*/
220+
export type BuildCreateContractTxRequestWithContract = {
221+
/**
222+
* A Marlowe Contract to create over Cardano
223+
*/
224+
contract: Contract;
225+
} & BuildCreateContractTxRequestOptions;
226+
227+
/**
228+
* Request for the {@link index.RestClient#buildCreateContractTx | Build Create Contract Tx } endpoint using a contract
229+
* @category Endpoint : Build Create Contract Tx
230+
*/
231+
export type BuildCreateContractTxRequestWithSourceId = {
232+
/**
233+
* A merkleized Contract (referred by its source Id) to create over Cardano
234+
* @see Large/Deep Contracts Support (Contract Merkleization) and `@marlowe.io/language-core`
235+
*/
236+
sourceId: SourceId;
237+
} & BuildCreateContractTxRequestOptions;
238+
216239
/**
217240
* Request options for the {@link index.RestClient#buildCreateContractTx | Build Create Contract Tx } endpoint
218241
* @category Endpoint : Build Create Contract Tx
219242
* @example
220243
* - Minimal Simple Contract Close
221244
* ```json
222245
* { "changeAddress" : "addr_test1qqe342swyfn75mp2anj45f8ythjyxg6m7pu0pznptl6f2d84kwuzrh8c83gzhrq5zcw7ytmqc863z5rhhwst3w4x87eq0td9ja",
223-
* "contractOrSourceId" : "close",
246+
* "contract" : "close",
224247
* "tags" : {"ts-sdk.documentation.example" : {"infoA" : 5} },
225248
* "version" : "v1"
226249
* }
@@ -230,7 +253,7 @@ export const ContractOrSourceIdGuard: t.Type<ContractOrSourceId> = t.union([
230253
* { "changeAddress" : "addr_test1qqe342swyfn75mp2anj45f8ythjyxg6m7pu0pznptl6f2d84kwuzrh8c83gzhrq5zcw7ytmqc863z5rhhwst3w4x87eq0td9ja",
231254
* "usedAddresses": ["addr_test1qqe342swyfn75mp2anj45f8ythjyxg6m7pu0pznptl6f2d84kwuzrh8c83gzhrq5zcw7ytmqc863z5rhhwst3w4x87eq0td9ja"],
232255
* "collateralUTxOs": [],
233-
* "contractOrSourceId" : "close",
256+
* "contract" : "close",
234257
* "tags" : {"ts-sdk.documentation.example" : {"infoA" : 5} },
235258
* "minimumLovelaceUTxODeposit" : 3000000,
236259
* "threadRoleName" : "ThreadRoleToken",
@@ -242,7 +265,7 @@ export const ContractOrSourceIdGuard: t.Type<ContractOrSourceId> = t.union([
242265
* { "changeAddress" : "addr_test1qqe342swyfn75mp2anj45f8ythjyxg6m7pu0pznptl6f2d84kwuzrh8c83gzhrq5zcw7ytmqc863z5rhhwst3w4x87eq0td9ja",
243266
* "usedAddresses": ["addr_test1qqe342swyfn75mp2anj45f8ythjyxg6m7pu0pznptl6f2d84kwuzrh8c83gzhrq5zcw7ytmqc863z5rhhwst3w4x87eq0td9ja"],
244267
* "collateralUTxOs": [],
245-
* "contractOrSourceId" : {"when":[{"then":{"when":[{"then":{"token":{"token_name":"","currency_symbol":""},"to":{"party":{"role_token":"Dollar provider"}},"then":{"token":{"token_name":"dollar","currency_symbol":"85bb65"},"to":{"party":{"role_token":"Ada provider"}},"then":"close","pay":0,"from_account":{"role_token":"Dollar provider"}},"pay":{"times":0,"multiply":1000000},"from_account":{"role_token":"Ada provider"}},"case":{"party":{"role_token":"Dollar provider"},"of_token":{"token_name":"dollar","currency_symbol":"85bb65"},"into_account":{"role_token":"Dollar provider"},"deposits":0}}],"timeout_continuation":"close","timeout":1701773934770},"case":{"party":{"role_token":"Ada provider"},"of_token":{"token_name":"","currency_symbol":""},"into_account":{"role_token":"Ada provider"},"deposits":{"times":0,"multiply":1000000}}}],"timeout_continuation":"close","timeout":1701772134770},
268+
* "contract" : {"when":[{"then":{"when":[{"then":{"token":{"token_name":"","currency_symbol":""},"to":{"party":{"role_token":"Dollar provider"}},"then":{"token":{"token_name":"dollar","currency_symbol":"85bb65"},"to":{"party":{"role_token":"Ada provider"}},"then":"close","pay":0,"from_account":{"role_token":"Dollar provider"}},"pay":{"times":0,"multiply":1000000},"from_account":{"role_token":"Ada provider"}},"case":{"party":{"role_token":"Dollar provider"},"of_token":{"token_name":"dollar","currency_symbol":"85bb65"},"into_account":{"role_token":"Dollar provider"},"deposits":0}}],"timeout_continuation":"close","timeout":1701773934770},"case":{"party":{"role_token":"Ada provider"},"of_token":{"token_name":"","currency_symbol":""},"into_account":{"role_token":"Ada provider"},"deposits":{"times":0,"multiply":1000000}}}],"timeout_continuation":"close","timeout":1701772134770},
246269
* "tags" : {"ts-sdk.documentation.example" : {"infoA" : 5} },
247270
* "roles" : {"Ada provider" : {"recipients": {"OpenRole" : 1} }
248271
* ,"Dollar provider" : {"recipients": {"OpenRole" : 1} } },
@@ -252,7 +275,15 @@ export const ContractOrSourceIdGuard: t.Type<ContractOrSourceId> = t.union([
252275
* }
253276
* ```
254277
*/
255-
export interface BuildCreateContractTxRequest {
278+
export type BuildCreateContractTxRequest =
279+
| BuildCreateContractTxRequestWithContract
280+
| BuildCreateContractTxRequestWithSourceId;
281+
282+
/**
283+
* Request options for the {@link index.RestClient#buildCreateContractTx | Build Create Contract Tx } endpoint
284+
* @category Endpoint : Build Create Contract Tx
285+
*/
286+
export interface BuildCreateContractTxRequestOptions {
256287
/**
257288
* Marlowe contracts can have staking rewards for the ADA locked in the contract.
258289
* Use this field to set the recipient address of those rewards
@@ -306,11 +337,6 @@ export interface BuildCreateContractTxRequest {
306337
*/
307338
collateralUTxOs?: TxOutRef[];
308339

309-
/**
310-
* A Marlowe Contract or a Merkleized One (referred by its source Id) to create over Cardano
311-
* @see Large/Deep Contracts Support (Contract Merkleization) and `@marlowe.io/language-core`
312-
*/
313-
contractOrSourceId: ContractOrSourceId;
314340
/**
315341
* Marlowe Tags are stored as Metadata within the Transaction Metadata under the top-level Marlowe Reserved Key (`1564`).
316342
* Tags allows to Query created Marlowe Contracts via {@link index.RestClient#getContracts | Get contracts }

‎packages/runtime/client/rest/src/contract/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export {
3838
ContractsRange,
3939
ContractOrSourceId,
4040
BuildCreateContractTxRequest,
41+
BuildCreateContractTxRequestWithContract,
42+
BuildCreateContractTxRequestWithSourceId,
43+
BuildCreateContractTxRequestOptions,
4144
BuildCreateContractTxResponse,
4245
} from "./endpoints/collection.js";
4346
export { TxHeader } from "./transaction/header.js";

‎packages/runtime/client/rest/src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { submitContractViaAxios } from "./contract/endpoints/singleton.js";
4141
import { ContractDetails } from "./contract/details.js";
4242
import { TransactionDetails } from "./contract/transaction/details.js";
4343
import { CreateContractSourcesResponse } from "./contract/endpoints/sources.js";
44+
import { BuildCreateContractTxRequestWithContract } from "./contract/index.js";
4445
// import curlirize from 'axios-curlirize';
4546

4647
/**
@@ -236,7 +237,7 @@ export function mkRestClient(baseURL: string): RestClient {
236237
},
237238
buildCreateContractTx(request) {
238239
const postContractsRequest = {
239-
contract: request.contractOrSourceId,
240+
contract: "contract" in request ? request.contract : request.sourceId,
240241
version: request.version,
241242
metadata: request.metadata ?? {},
242243
tags: request.tags ?? {},

‎packages/runtime/lifecycle/src/generic/contracts.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export const submitCreateTxFpTs: (
158158
collateralUTxOs: addressesAndCollaterals.collateralUTxOs,
159159
stakeAddress: createContractRequest.stakeAddress,
160160

161-
contractOrSourceId: createContractRequest.contract,
161+
contract: createContractRequest.contract,
162162
threadRoleName: createContractRequest.threadRoleName,
163163
roles: createContractRequest.roles,
164164

0 commit comments

Comments
 (0)
Please sign in to comment.