From 0a6b6d70a800a7f4842e54f58805671fa5740e4a Mon Sep 17 00:00:00 2001 From: nhenin Date: Wed, 13 Dec 2023 17:32:16 +0100 Subject: [PATCH] re-enabled legacy way for defining Closed Role tokens --- examples/nodejs/src/escrow-flow.ts | 7 +------ .../rest/src/contract/rolesConfigurations.ts | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/examples/nodejs/src/escrow-flow.ts b/examples/nodejs/src/escrow-flow.ts index 21323c0f..5f2b7907 100644 --- a/examples/nodejs/src/escrow-flow.ts +++ b/examples/nodejs/src/escrow-flow.ts @@ -7,7 +7,6 @@ import { Lucid, Blockfrost } from "lucid-cardano"; import { readConfig } from "./config.js"; import { datetoTimeout } from "@marlowe.io/language-core-v1"; import { addressBech32 } from "@marlowe.io/runtime-core"; -import { mintRole } from "@marlowe.io/runtime-rest-client/contract"; const args = arg({ "--help": Boolean, @@ -113,11 +112,7 @@ async function main( const [contractId, txId] = await runtime.contracts.createContract({ contract: escrow, - roles: { - Buyer: mintRole(Buyer), - Seller: mintRole(Seller), - Mediator: mintRole(Mediator), - }, + roles: { Buyer, Seller, Mediator }, }); console.log("Contract ID: " + contractId); diff --git a/packages/runtime/client/rest/src/contract/rolesConfigurations.ts b/packages/runtime/client/rest/src/contract/rolesConfigurations.ts index 3374401d..31c11669 100644 --- a/packages/runtime/client/rest/src/contract/rolesConfigurations.ts +++ b/packages/runtime/client/rest/src/contract/rolesConfigurations.ts @@ -4,6 +4,7 @@ import { PolicyId, RoleName } from "@marlowe.io/language-core-v1"; import * as G from "@marlowe.io/language-core-v1/guards"; import { AddressBech32, AddressBech32Guard } from "@marlowe.io/runtime-core"; +import { assertGuardEqual, proxy } from "@marlowe.io/adapter/io-ts"; /** * Definition a of Closed Role Tlken @@ -148,11 +149,21 @@ export const RoleTokenConfigurationGuard: t.Type = /** * @category Roles Configuration */ -export type MintRolesTokens = { [x: RoleName]: RoleTokenConfiguration }; +export type RoleTokenConfigurations = RoleTokenConfiguration | ClosedRole; -export const MintRolesTokensGuard: t.Type = t.record( - G.RoleName, - RoleTokenConfigurationGuard +export const RoleConfigurationsGuard = t.union([ + RoleTokenConfigurationGuard, + ClosedRoleGuard, +]); + +/** + * @category Roles Configuration + */ +export type MintRolesTokens = { [x: RoleName]: RoleTokenConfigurations }; + +export const MintRolesTokensGuard = assertGuardEqual( + proxy(), + t.record(G.RoleName, RoleConfigurationsGuard) ); /**