Skip to content

Commit

Permalink
Merge pull request #54 from input-output-hk/PLT-8261
Browse files Browse the repository at this point in the history
Open Roles & Clean buildCreateContractTx Request
  • Loading branch information
nhenin authored Dec 8, 2023
2 parents 03f231f + 09fc3cd commit ebf25e7
Show file tree
Hide file tree
Showing 34 changed files with 1,062 additions and 279 deletions.
8 changes: 8 additions & 0 deletions changelog.d/20231208_095010_nicolas.henin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### @marlowe.io/runtime-rest-client

- `createContract` Endpoint has been renamed to `buildCreateContractTx` ([PR#54](https://github.com/input-output-hk/marlowe-ts-sdk/pull/54))
- `buildCreateContractTx` is 1-1 parity with REST API request-wise ([PR#54](https://github.com/input-output-hk/marlowe-ts-sdk/pull/54))

### @marlowe.io/runtime-lifecycle

- `createContract` is complete request-wise for creating non-merkleized contracts ([PR#54](https://github.com/input-output-hk/marlowe-ts-sdk/pull/54))
6 changes: 3 additions & 3 deletions examples/rest-client-flow/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ <h2>Request</h2>
>
<br />
<input
id="createContract"
id="buildCreateContractTx"
type="button"
value="Create Contract"
value="Build Create Contract Tx"
class="endpoint"
/>
POSTs a new contract
<a
href="https://input-output-hk.github.io/marlowe-ts-sdk/interfaces/_marlowe_io_runtime_rest_client.index.RestClient.html#createContract"
href="https://input-output-hk.github.io/marlowe-ts-sdk/interfaces/_marlowe_io_runtime_rest_client.index.RestClient.html#buildCreateContractTx"
>/contracts</a
>
<br />
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({
contract: 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,
contract: contract,
tags: { MarloweSurvey: "test 1" },
});

Expand Down
113 changes: 41 additions & 72 deletions jsdelivr-npm-importmap.js

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

20 changes: 20 additions & 0 deletions packages/adapter/src/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ import JSONbigint from "json-bigint";

export type DecodingError = string[];

/**
* ```ts
* try {
* myRuntimeEndpoint(myRequest);
* } catch (error){
* if(error instanceOf UnexpectedRuntimeResponse) {
* console.error("The Runtime answered an unexpected message, please contact our desk support",error)
* } else {
* console.error("another type of error",error)
* }
* }
* ```
*/
export class UnexpectedRuntimeResponse extends Error {
public type = "UnexpectedRuntimeResponse" as const;
constructor(message: string) {
super(message);
}
}

export const MarloweJSON = JSONbigint({
alwaysParseAsBig: true,
useNativeBigInt: true,
Expand Down
3 changes: 1 addition & 2 deletions packages/language/core/v1/src/address.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as t from "io-ts/lib/index.js";

// TODO: This should be DELETED as there is a newtype for this in runtime-core,
// but a preliminary change broke the build with weird type errors
// TODO: This should be replaced by a Branded Version available in the Runtime Rest Client Package,
export type AddressBech32 = string;
export const AddressBech32 = t.string;
3 changes: 3 additions & 0 deletions packages/language/core/v1/src/guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@packageDocumentation
*/

export { PolicyIdGuard as PolicyId } from "./policyId.js";

export {
ActionGuard as Action,
DepositGuard as Deposit,
Expand Down Expand Up @@ -58,6 +60,7 @@ export {

export {
RoleGuard as Role,
RoleNameGuard as RoleName,
PartyGuard as Party,
AddressGuard as Address,
} from "./participants.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/language/core/v1/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export {
MerkleizedInput,
} from "./inputs.js";

export { role, Party, Address, Role } from "./participants.js";
export { role, Party, Address, Role, RoleName } from "./participants.js";

export { Payee, PayeeAccount, PayeeParty, AccountId } from "./payee.js";

Expand Down
4 changes: 2 additions & 2 deletions packages/language/core/v1/src/participants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export interface Address {
*/
export const AddressGuard: t.Type<Address> = t.type({ address: AddressBech32 });

type RoleName = string;
const RoleNameGuard: t.Type<RoleName> = t.string;
export type RoleName = string;
export const RoleNameGuard: t.Type<RoleName> = t.string;

/**
* Search [[lower-name-builders]]
Expand Down
2 changes: 1 addition & 1 deletion packages/language/core/v1/src/policyId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export type PolicyId = string;
/**
* @category Token
*/
export const PolicyId = t.string;
export const PolicyIdGuard = t.string;
4 changes: 2 additions & 2 deletions packages/language/core/v1/src/token.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Sort, strCmp } from "@marlowe.io/adapter/assoc-map";
import * as t from "io-ts/lib/index.js";
import { PolicyId } from "./policyId.js";
import { PolicyId, PolicyIdGuard } from "./policyId.js";
/**
* @see {@link @marlowe.io/language-core-v1!index.Token}.
* @category Token
Expand All @@ -26,7 +26,7 @@ export interface Token {
* @category Token
*/
export const TokenGuard: t.Type<Token> = t.type({
currency_symbol: PolicyId,
currency_symbol: PolicyIdGuard,
token_name: TokenNameGuard,
});

Expand Down
11 changes: 10 additions & 1 deletion packages/runtime/client/rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,21 @@
"require": "./dist/bundled/cjs/transaction.cjs",
"types": "./dist/esm/contract/transaction/index.d.ts"
},
"./payout": {
"import": "./dist/esm/payout/index.js",
"require": "./dist/bundled/cjs/payout.cjs",
"types": "./dist/esm/payout/index.d.ts"
},
"./withdrawal": {
"import": "./dist/esm/withdrawal/index.js",
"require": "./dist/bundled/cjs/withdrawal.cjs",
"types": "./dist/esm/withdrawal/index.d.ts"
},
"./contract/*": "./dist/esm/contract/*.js"
"./contract": {
"import": "./dist/esm/contract/index.js",
"require": "./dist/bundled/cjs/contract.cjs",
"types": "./dist/esm/contract/index.d.ts"
}
},
"dependencies": {
"@marlowe.io/adapter": "0.3.0-beta-rc1",
Expand Down
10 changes: 5 additions & 5 deletions packages/runtime/client/rest/src/contract/details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import { Contract, MarloweState } from "@marlowe.io/language-core-v1";
import * as G from "@marlowe.io/language-core-v1/guards";
import { MarloweVersion } from "@marlowe.io/language-core-v1/version";
import { ContractIdGuard } from "@marlowe.io/runtime-core";

import { TxStatus } from "./transaction/status.js";

import { RoleName } from "./role.js";
import {
TxOutRef,
BlockHeaderGuard,
Expand All @@ -34,21 +32,23 @@ 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: RoleName,
role: G.RoleName,
});

/**
* Represents the response of the {@link index.RestClient#getContractById | Get contract by id } endpoint
* Represents the response of the {@link index.RestClient#getContractById | Get Contract By Id } endpoint
* @see The {@link ContractDetails:var | dynamic validator} for this type.
* @interface
* @category Endpoint : Get Contract By Id
*/
export interface ContractDetails extends t.TypeOf<typeof ContractDetails> {}

/**
* This is a {@link !io-ts-usage | Dynamic type validator} for the {@link ContractDetails:type}.
* @category Validator
* @category Endpoint : Get Contract By Id
*/
// DISCUSSION : Tags are missing in the ts-sdk and available in the REST API
export const ContractDetails = t.type({
Expand Down
Loading

0 comments on commit ebf25e7

Please sign in to comment.