Skip to content

Commit

Permalink
Merge pull request #36 from input-output-hk/hrajchert/PLT-7500-compat…
Browse files Browse the repository at this point in the history
…ibility-layer

Refactor language-core-v1
  • Loading branch information
nhenin authored Sep 29, 2023
2 parents 374a82e + 576b9d9 commit a661074
Show file tree
Hide file tree
Showing 66 changed files with 460 additions and 461 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### @marlowe.io/language-core-v1

- Moved the examples to the `@marlowe.io/language-examples` package.
2 changes: 1 addition & 1 deletion changelog.d/scriv.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[scriv]
format = md
categories = General, @marlowe.io/wallet, @marlowe.io/adapter, @marlowe.io/language-core-v1, @marlowe.io/runtime-rest-client, @marlowe.io/runtime-core, @marlowe.io/runtime-lifecycle
categories = General, @marlowe.io/wallet, @marlowe.io/adapter, @marlowe.io/language-core-v1, @marlowe.io/language-examples, @marlowe.io/runtime-rest-client, @marlowe.io/runtime-core, @marlowe.io/runtime-lifecycle
12 changes: 2 additions & 10 deletions jsdelivr-npm-importmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,12 @@ const importMap = {
"https:/cdn.jsdelivr.net/npm/@marlowe.io/adapter@0.2.0-alpha-3/dist/bundled/esm/time.js",
"@marlowe.io/language-core-v1":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/language-core-v1@0.2.0-alpha-3/dist/bundled/esm/language-core-v1.js",
"@marlowe.io/language-core-v1/environment":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/language-core-v1@0.2.0-alpha-3/dist/bundled/esm/environment.js",
"@marlowe.io/language-core-v1/examples":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/language-core-v1@0.2.0-alpha-3/dist/bundled/esm/examples.js",
"@marlowe.io/language-core-v1/next":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/language-core-v1@0.2.0-alpha-3/dist/bundled/esm/next.js",
"@marlowe.io/language-core-v1/state":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/language-core-v1@0.2.0-alpha-3/dist/bundled/esm/state.js",
"@marlowe.io/language-core-v1/token":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/language-core-v1@0.2.0-alpha-3/dist/bundled/esm/token.js",
"@marlowe.io/language-core-v1/tokenValue":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/language-core-v1@0.2.0-alpha-3/dist/bundled/esm/tokenValue.js",
"@marlowe.io/language-core-v1/version":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/language-core-v1@0.2.0-alpha-3/dist/bundled/esm/version.js",
"@marlowe.io/language-examples":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/language-examples@0.2.0-alpha-3/dist/bundled/esm/language-examples.js",
"@marlowe.io/token-metadata-client":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/token-metadata-client@0.2.0-alpha-3/dist/bundled/esm/token-metadata-client.js",
"@marlowe.io/wallet":
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"workspaces": [
"packages/adapter",
"packages/language/core/v1",
"packages/language/examples",
"packages/token-metadata-client",
"packages/wallet",
"packages/runtime/client/rest",
Expand Down
46 changes: 10 additions & 36 deletions packages/language/core/v1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,28 @@
"test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest --config test/jest.unit.config.mjs"
},
"type": "module",
"module": "./dist/esm/semantics/contract/index.js",
"main": "./dist/esm/semantics/contract/index.js",
"types": "./dist/esm/semantics/contract/index.d.ts",
"module": "./dist/esm/index.js",
"main": "./dist/esm/index.js",
"types": "./dist/esm/index.d.ts",
"files": [
"dist"
],
"exports": {
".": {
"import": "./dist/esm/semantics/contract/index.js",
"import": "./dist/esm/index.js",
"require": "./dist/bundled/cjs/language-core-v1.cjs",
"types": "./dist/esm/semantics/contract/index.d.ts"
"types": "./dist/esm/index.d.ts"
},
"./next": {
"import": "./dist/esm/semantics/next/index.js",
"import": "./dist/esm/next/index.js",
"require": "./dist/bundled/cjs/next.cjs",
"types": "./dist/esm/semantics/next/index.d.ts"
},
"./environment": {
"import": "./dist/esm/semantics/environment.js",
"require": "./dist/bundled/cjs/environment.cjs",
"types": "./dist/esm/semantics/environment.d.ts"
},
"./state": {
"import": "./dist/esm/semantics/state.js",
"require": "./dist/bundled/cjs/state.cjs",
"types": "./dist/esm/semantics/state.d.ts"
},
"./token": {
"import": "./dist/esm/semantics/contract/common/token.js",
"require": "./dist/bundled/cjs/token.cjs",
"types": "./dist/esm/semantics/contract/common/token.d.ts"
},
"./tokenValue": {
"import": "./dist/esm/semantics/contract/common/tokenValue.js",
"require": "./dist/bundled/cjs/tokenValue.cjs",
"types": "./dist/esm/semantics/contract/common/tokenValue.d.ts"
"types": "./dist/esm/next/index.d.ts"
},
"./version": {
"import": "./dist/esm/semantics/version.js",
"import": "./dist/esm/version.js",
"require": "./dist/bundled/cjs/version.cjs",
"types": "./dist/esm/semantics/version.d.ts"
},
"./examples": {
"import": "./dist/esm/examples/index.js",
"require": "./dist/bundled/cjs/examples.cjs",
"types": "./dist/esm/examples/index.d.ts"
},
"./contract/*": "./dist/esm/semantics/contract/*.js"
"types": "./dist/esm/version.d.ts"
}
},
"dependencies": {
"date-fns": "2.29.3",
Expand Down
46 changes: 46 additions & 0 deletions packages/language/core/v1/src/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as t from "io-ts/lib/index.js";

import { Observation } from "./value-and-observation.js";
import { ChoiceId } from "./value-and-observation.js";
import { Party } from "./participants.js";
import { AccountId } from "./payee.js";
import { Token } from "./token.js";
import { Value } from "./value-and-observation.js";

export type Bound = { from: bigint; to: bigint };

export const Bound: t.Type<Bound> = t.recursion("Bound", () =>
t.type({ from: t.bigint, to: t.bigint })
);

export type Choice = { choose_between: Bound[]; for_choice: ChoiceId };

export const Choice: t.Type<Choice> = t.recursion("Choice", () =>
t.type({ choose_between: t.array(Bound), for_choice: ChoiceId })
);

export type Deposit = {
party: Party;
deposits: Value;
of_token: Token;
into_account: AccountId;
};

export const Deposit: t.Type<Deposit> = t.type({
party: Party,
deposits: Value,
of_token: Token,
into_account: AccountId,
});

export type Notify = { notify_if: Observation };

export const Notify: t.Type<Notify> = t.recursion("Notify", () =>
t.type({ notify_if: Observation })
);

export type Action = Deposit | Choice | Notify;

export const Action: t.Type<Action> = t.recursion("Action", () =>
t.union([Deposit, Choice, Notify])
);
6 changes: 6 additions & 0 deletions packages/language/core/v1/src/address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
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
export type AddressBech32 = string;
export const AddressBech32 = t.string;
101 changes: 101 additions & 0 deletions packages/language/core/v1/src/contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import * as t from "io-ts/lib/index.js";
import { Observation } from "./value-and-observation.js";
import { AccountId } from "./payee.js";
import { Payee } from "./payee.js";
import { Token } from "./token.js";
import { Value, ValueId } from "./value-and-observation.js";
import { Action } from "./actions.js";
import { pipe } from "fp-ts/lib/function.js";
import getUnixTime from "date-fns/getUnixTime/index.js";

export const close = "close";
export type Close = t.TypeOf<typeof Close>;
export const Close = t.literal("close");

export const pay = (
pay: Value,
token: Token,
from_account: AccountId,
to: Payee,
then: Contract
) => ({
pay: pay,
token: token,
from_account: from_account,
to: to,
then: then,
});

export type Pay = {
pay: Value;
token: Token;
from_account: AccountId;
to: Payee;
then: Contract;
};

export const Pay = t.recursion<Pay>("Pay", () =>
t.type({
pay: Value,
token: Token,
from_account: AccountId,
to: Payee,
then: Contract,
})
);

export type If = { if: Observation; then: Contract; else: Contract };

export const If: t.Type<If> = t.recursion("If", () =>
t.type({ if: Observation, then: Contract, else: Contract })
);

export type Let = { let: ValueId; be: Value; then: Contract };

export const Let: t.Type<Let> = t.recursion("Let", () =>
t.type({ let: ValueId, be: Value, then: Contract })
);

export type Assert = { assert: Observation; then: Contract };

export const Assert: t.Type<Assert> = t.recursion("Assert", () =>
t.type({ assert: Observation, then: Contract })
);

export type When = {
when: Case[];
timeout: Timeout;
timeout_continuation: Contract;
};

export const When: t.Type<When> = t.recursion("When", () =>
t.type({
when: t.array(Case),
timeout: Timeout,
timeout_continuation: Contract,
})
);

export type Case = { case: Action; then: Contract };

export const Case: t.Type<Case> = t.recursion("Case", () =>
t.type({ case: Action, then: Contract })
);

export type Timeout = t.TypeOf<typeof Timeout>;
export const Timeout = t.bigint;

export const datetoTimeout = (date: Date): Timeout =>
pipe(
date,
getUnixTime,
(a) => a * 1_000,
BigInt,
(a) => a.valueOf()
);

export type Contract = Close | Pay | If | When | Let | Assert;

export const Contract: t.Type<Contract> = t.recursion("Contract", () =>
t.union([Close, Pay, If, When, Let, Assert])
);
25 changes: 25 additions & 0 deletions packages/language/core/v1/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// TODO: REVISIT

export {
Contract,
Assert,
Close,
close,
If,
Let,
Pay,
When,
datetoTimeout,
Timeout,
} from "./contract.js";
export { role, Party } from "./participants.js";
export { Action } from "./actions.js";
export { inputNotify } from "./inputs.js";
export { Input, BuiltinByteString } from "./inputs.js";
export { Value } from "./value-and-observation.js";
export { Accounts } from "./state.js";
export { Token, TokenName, tokenToString, token } from "./token.js";
export { TokenValue, tokenValue, adaValue } from "./tokenValue.js";
export { PolicyId } from "./policyId.js";
export { MarloweState } from "./state.js";
export { Environment, mkEnvironment } from "./environment.js";
49 changes: 49 additions & 0 deletions packages/language/core/v1/src/inputs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import * as t from "io-ts/lib/index.js";
import { Contract } from "./contract.js";
import { ChoiceId } from "./value-and-observation.js";
import { Party } from "./participants.js";
import { AccountId } from "./payee.js";
import { Token } from "./token.js";

export type ChosenNum = t.TypeOf<typeof ChosenNum>;
export const ChosenNum = t.bigint;

export type InputChoice = t.TypeOf<typeof InputChoice>;
export const InputChoice = t.type({
for_choice_id: ChoiceId,
input_that_chooses_num: ChosenNum,
});

export type InputDeposit = t.TypeOf<typeof InputDeposit>;
export const InputDeposit = t.type({
input_from_party: Party,
that_deposits: t.bigint,
of_token: Token,
into_account: AccountId,
});

export const inputNotify = "input_notify";
export type InputNotify = t.TypeOf<typeof InputNotify>;
export const InputNotify = t.literal("input_notify");

// Maybe this should be a newtype
export type BuiltinByteString = t.TypeOf<typeof BuiltinByteString>;
export const BuiltinByteString = t.string;

export type InputContent = t.TypeOf<typeof InputContent>;
export const InputContent = t.union([InputDeposit, InputChoice, InputNotify]);

export type NormalInput = t.TypeOf<typeof NormalInput>;
export const NormalInput = InputContent;

export type MerkleizedInput = t.TypeOf<typeof MerkleizedInput>;
export const MerkleizedInput = t.intersection([
InputContent,
t.partial({
continuation_hash: BuiltinByteString,
merkleized_continuation: Contract,
}),
]);

export type Input = t.TypeOf<typeof Input>;
export const Input = t.union([NormalInput, MerkleizedInput]);
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as t from "io-ts/lib/index.js";
import { Bound } from "../../contract/when/action/choice.js";
import { ChoiceId } from "../../contract/common/value.js";
import { ChoiceId } from "../../value-and-observation.js";
import { IsMerkleizedContinuation } from "../common/IsMerkleizedContinuation.js";
import { CaseIndex } from "../common/caseIndex.js";
import { ChosenNum, InputChoice } from "../../contract/when/input/choice.js";
import { ChosenNum, InputChoice } from "../../inputs.js";
import { Bound } from "../../actions.js";

export type CanChoose = t.TypeOf<typeof CanChoose>;
export const CanChoose = t.type({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { optionFromNullable } from "io-ts-types";
import * as t from "io-ts/lib/index.js";
import { AccountId } from "../../contract/common/payee/account.js";
import { Party } from "../../contract/common/payee/party.js";
import { Token } from "../../contract/common/token.js";
import { Token } from "../../token.js";
import { IsMerkleizedContinuation } from "../common/IsMerkleizedContinuation.js";
import { CaseIndex } from "../common/caseIndex.js";
import { InputDeposit } from "../../contract/when/input/deposit.js";
import { InputDeposit } from "../../inputs.js";
import { Party } from "../../participants.js";
import { AccountId } from "../../payee.js";

export type CanDeposit = t.TypeOf<typeof CanDeposit>;
export const CanDeposit = t.type({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as t from "io-ts/lib/index.js";
import { IsMerkleizedContinuation } from "../common/IsMerkleizedContinuation.js";
import { CaseIndex } from "../common/caseIndex.js";
import { InputNotify } from "../../contract/when/input/notify.js";
import { InputNotify } from "../../inputs.js";

export type CanNotify = t.TypeOf<typeof CanNotify>;
export const CanNotify = t.type({
Expand Down
File renamed without changes.
Loading

0 comments on commit a661074

Please sign in to comment.