Skip to content

Commit

Permalink
update runtime.lifecycle createContract API
Browse files Browse the repository at this point in the history
  • Loading branch information
nhenin committed Dec 5, 2023
1 parent 226c785 commit dc9a56b
Show file tree
Hide file tree
Showing 20 changed files with 387 additions and 201 deletions.
2 changes: 1 addition & 1 deletion examples/get-my-contract-ids-flow/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
window.createContract = async () => {
const address = await window.runtimeLifeCycle.wallet.getChangeAddress();
return runtimeLifeCycle.contracts.createContract({
contract: mkContract(address, Date.now() + 1000 * 60 * 10),
contractOrSourceId: mkContract(address, Date.now() + 1000 * 60 * 10),
});
};
</script>
Expand Down
4 changes: 3 additions & 1 deletion examples/run-lite/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ <h2>Console</h2>
walletName,
});

const contractId = await runtime.contracts.createContract({ contract });
const contractId = await runtime.contracts.createContract({
contractOrSourceId: contract,
});
log("Contract created with id: " + contractId);
setContractIdIndicator(contractId);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/survey-workshop/participant/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async function createContract(

const lifecycle = await H.getLifecycle();
const [contractId] = await lifecycle.contracts.createContract({
contract,
contractOrSourceId: contract,
tags: { MarloweSurvey: "test 1" },
});

Expand Down
2 changes: 1 addition & 1 deletion examples/vesting-flow/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ <h2>Console</h2>

const [contractId, txIdCreated] =
await runtimeLifeCycle.contracts.createContract({
contract: vestingContract,
contractOrSourceId: vestingContract,
tags: { [dappId]: { scheme: request.scheme } },
});
log(
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

110 changes: 40 additions & 70 deletions jsdelivr-npm-importmap.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/runtime/client/rest/src/contract/details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const Payout = t.type({
*/
payoutId: TxOutRef,
/**
* The {@link RoleName} of the participant that has the unclaimed Payout.
* The {@link @marlowe.io/language-core-v1!index.RoleName | Role Name} of the participant that has the unclaimed Payout.
*/
role: G.RoleName,
});
Expand Down
25 changes: 12 additions & 13 deletions packages/runtime/client/rest/src/contract/endpoints/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,8 @@ export interface BuildCreateContractTxRequest {
* - **Quantities to create(Mint)** : When asking to mint the tokens within the Runtime, quantities can defined as well.
*
* Smart Constructors are available to ease these configuration:
* - {@link @marlowe.io/runtime-rest-client!contract.mkUseMintedRoleTokens}
* - {@link @marlowe.io/runtime-rest-client!contract.mkMintOpenRoleToken}
* - {@link @marlowe.io/runtime-rest-client!contract.mkMintClosedRoleToken}
* - {@link @marlowe.io/runtime-rest-client!contract.useMintedRoles}
* - {@link @marlowe.io/runtime-rest-client!contract.mintRole}
*
* @remarks
* - The Distribution can be a mix of Closed and Open Role Tokens configuration. See examples below.
Expand All @@ -382,13 +381,13 @@ export interface BuildCreateContractTxRequest {
*
* ```ts
* //////////////
* // #1 - Mint within the Runtime
* // #1 - Mint Role Tokens
* //////////////
* const anAddressBech32 = "addr_test1qqe342swyfn75mp2anj45f8ythjyxg6m7pu0pznptl6f2d84kwuzrh8c83gzhrq5zcw7ytmqc863z5rhhwst3w4x87eq0td9ja"
* const aMintingConfiguration =
* { "closed_Role_A_NFT" : mkMintClosedRoleToken(anAddressBech32)
* { "closed_Role_A_NFT" : mintRole(anAddressBech32)
* , "closed_Role_B_FT" :
* mkMintClosedRoleToken(
* mintRole(
* anAddressBech32,
* 5, // Quantities
* { "name": "closed_Role_B_FT Marlowe Role Token",
Expand All @@ -403,11 +402,12 @@ export interface BuildCreateContractTxRequest {
* }
* ]
* })
* , "open_Role_C" : mkMintOpenRoleToken()
* , "open_Role_D" : mkMintOpenRoleToken(
* , "open_Role_C" : mintRole(openRole)
* , "open_Role_D" : mintRole(
* openRole,
* 2, // Quantities
* { "name": "open_Role_D Marlowe Role Token",
"description": "These are metadata for closedRoleB",
* "description": "These are metadata for closedRoleB",
* image": "ipfs://QmaQMH7ybS9KmdYQpa4FMtAhwJH5cNaacpg4fTwhfPvcwj",
* "mediaType": "image/png",
* "files": [
Expand All @@ -423,16 +423,15 @@ export interface BuildCreateContractTxRequest {
* //////////////
* // #2 Use Minted Roles Tokens
* const aUseMintedRoleTokensConfiguration =
* mkUseMintedRoleTokens(
* useMintedRoles(
* "e68f1cea19752d1292b4be71b7f5d2b3219a15859c028f7454f66cdf",
* ["role_A","role_C"]
* )
* ```
*
* @see
* - {@link @marlowe.io/runtime-rest-client!contract.mkUseMintedRoleTokens}
* - {@link @marlowe.io/runtime-rest-client!contract.mkMintOpenRoleToken}
* - {@link @marlowe.io/runtime-rest-client!contract.mkMintClosedRoleToken}
* - {@link @marlowe.io/runtime-rest-client!contract.useMintedRoles}
* - {@link @marlowe.io/runtime-rest-client!contract.mintRole}
* - Open Roles Runtime Implementation : https://github.com/input-output-hk/marlowe-cardano/blob/main/marlowe-runtime/doc/open-roles.md
*/
rolesConfiguration?: RolesConfiguration;
Expand Down
9 changes: 4 additions & 5 deletions packages/runtime/client/rest/src/contract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
export { ContractHeader } from "./header.js";
export { ContractDetails } from "./details.js";
export {
mkUseMintedRoleTokens,
mkMintClosedRoleToken,
mkMintOpenRoleToken,
useMintedRoles,
mintRole,
AddressBech32Brand,
AddressBech32,
mkOpenRole,
openRole,
ClosedRole,
OpenRole,
Openess,
Openness,
UsePolicyWithClosedRoleTokens,
UsePolicyWithOpenRoleTokens,
MintRolesTokens,
Expand Down
52 changes: 21 additions & 31 deletions packages/runtime/client/rest/src/contract/rolesConfigurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ export const OpenRoleGuard = t.literal("OpenRole");
* Construction of an Open Role Token
* @category Roles Configuration
*/
export const mkOpenRole = "OpenRole";
export const openRole = "OpenRole";

/**
* Definition of the Openness of a Role Token
* @category Roles Configuration
*/
export type Openess = ClosedRole | OpenRole;
export const OpenessGuard: t.Type<Openess, string> = t.union([
export type Openness = ClosedRole | OpenRole;
export const OpenessGuard: t.Type<Openness, string> = t.union([
ClosedRoleGuard,
OpenRoleGuard,
]);
Expand Down Expand Up @@ -129,7 +129,7 @@ export interface ClosedNFTWithMetadata {
/**
* @category Roles Configuration
*/
export type Recipient = Openess;
export type Recipient = Openness;

export const RecipientGuard: t.Type<Recipient, string> = t.union([
OpenRoleGuard,
Expand Down Expand Up @@ -178,9 +178,8 @@ export const MintRolesTokensGuard: t.Type<MintRolesTokens> = t.record(
* Defines how to configure Roles over Cardano at the creation of a Marlowe Contract.
* @see
* Smart Constructors are available to ease the configuration:
* - {@link @marlowe.io/runtime-rest-client!contract.mkUseMintedRoleTokens}
* - {@link @marlowe.io/runtime-rest-client!contract.mkMintOpenRoleToken}
* - {@link @marlowe.io/runtime-rest-client!contract.mkMintClosedRoleToken}
* - {@link @marlowe.io/runtime-rest-client!contract.useMintedRoles}
* - {@link @marlowe.io/runtime-rest-client!contract.mintRole}
* @category Endpoint : Build Create Contract Tx
* @category Roles Configuration
*/
Expand Down Expand Up @@ -209,42 +208,33 @@ export const RolesConfigurationGuard = t.union([
* @category Endpoint : Build Create Contract Tx
* @category Roles Configuration
*/
export const mkUseMintedRoleTokens = (
export const useMintedRoles = (
policyId: PolicyId,
openRoleNames?: RoleName[]
): RolesConfiguration =>
openRoleNames
? { script: mkOpenRole, policyId: policyId, openRoleNames: openRoleNames }
? { script: openRole, policyId: policyId, openRoleNames: openRoleNames }
: (policyId as UsePolicyWithClosedRoleTokens);

/**
* Configure the minting of a Closed Role Token.
* @param address where to distribute the token that will be mint
* @param openness where to distribute the token (Either openly or closedly)
* @param quantity Quantity of the Closed Role Token (by Default an NFT (==1))
* @param metadata Token Metadata of the Token
* @category Endpoint : Build Create Contract Tx
* @category Roles Configuration
*/
export const mkMintClosedRoleToken: (
address: AddressBech32,
export const mintRole = (
openness: Openness,
quantity?: TokenQuantity,
metadata?: TokenMetadata
) => RoleTokenConfiguration = (address, quantity, metadata) => ({
recipients: { [address]: quantity ? quantity : 1n },
metadata: metadata,
});

/**
* Configure the minting of an Open Role Token.
* @param quantity Quantity of the Closed Role Token (by Default an NFT (==1))
* @param metadata Token Metadata of the Token
* @category Endpoint : Build Create Contract Tx
* @category Roles Configuration
*/
export const mkMintOpenRoleToken: (
quantity?: TokenQuantity,
metadata?: TokenMetadata
) => RoleTokenConfiguration = (quantity, metadata) => ({
recipients: { [mkOpenRole]: quantity ? quantity : 1n },
metadata: metadata,
});
): RoleTokenConfiguration =>
OpenRoleGuard.is(openness)
? {
recipients: { [openRole]: quantity ? quantity : 1n },
metadata: metadata,
}
: {
recipients: { [openness]: quantity ? quantity : 1n },
metadata: metadata,
};
2 changes: 1 addition & 1 deletion packages/runtime/client/rest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ export interface ContractsAPI {
* @description Dependency Injection for the Rest Client API
* @hidden
*/
export type RestDI = { rest: FPTSRestAPI };
export type RestDI = { deprecatedRestAPI: FPTSRestAPI; restClient: RestClient };

/**
* @hidden
Expand Down
Loading

0 comments on commit dc9a56b

Please sign in to comment.