From 14686e53712b7bea1f733cfd6460aab250d8910c Mon Sep 17 00:00:00 2001 From: leirbag95 Date: Fri, 5 Jan 2024 09:13:41 +0100 Subject: [PATCH 1/3] Payment solution field added to program and instance --- src/messages/instance/types.ts | 8 +++++++- src/messages/program/programModel.ts | 14 +++++++++++++- src/messages/types/base.ts | 8 ++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/messages/instance/types.ts b/src/messages/instance/types.ts index 517ad2a7..fa77c875 100644 --- a/src/messages/instance/types.ts +++ b/src/messages/instance/types.ts @@ -1,4 +1,4 @@ -import { BaseExecutableContent, ParentVolume, VolumePersistence } from "../types"; +import { BaseExecutableContent, ParentVolume, VolumePersistence, Chain, PaymentType } from "../types"; /** * Root file system of a VM instance. @@ -10,6 +10,12 @@ export type RootfsVolume = { size_mib: number; //Limit to 1 GiB }; +export type Payment = { + chain: Chain; + receiver: string; + type: PaymentType; +}; + /** * Message content for scheduling a VM instance on the network. * diff --git a/src/messages/program/programModel.ts b/src/messages/program/programModel.ts index 0f262dcd..5aa8fea0 100644 --- a/src/messages/program/programModel.ts +++ b/src/messages/program/programModel.ts @@ -1,5 +1,5 @@ import { BaseContent, MachineVolume } from "../types"; -import { FunctionEnvironment, MachineResources } from "../types"; +import { FunctionEnvironment, MachineResources, Chain, PaymentType } from "../types"; /** * Type of Encoding @@ -25,6 +25,8 @@ export type CodeContent = { entrypoint: string; ref: string; use_latest: boolean; + interface: string; + args: string[]; }; /** @@ -63,6 +65,15 @@ export type FunctionRuntime = { comment: string; }; +/** + * Payment solution + */ +export type Payment = { + chain: Chain; + receiver: string; + type: PaymentType; +}; + export type ProgramContent = BaseContent & { type: MachineType; allow_amend: boolean; @@ -76,5 +87,6 @@ export type ProgramContent = BaseContent & { resources: MachineResources; runtime: FunctionRuntime; volumes: MachineVolume[]; + payment?: Payment; replaces?: string; }; diff --git a/src/messages/types/base.ts b/src/messages/types/base.ts index 1d48c7d1..85e00b61 100644 --- a/src/messages/types/base.ts +++ b/src/messages/types/base.ts @@ -19,6 +19,14 @@ export enum Chain { TEZOS = "TEZOS", } +/** + * Payment Type concerning payment solution + */ +export enum PaymentType { + hold = "hold", + superfluid = "superfluid", +} + /** * Supported hash functions */ From a772d434dda65b36bb3ce889169fb229d1c34a07 Mon Sep 17 00:00:00 2001 From: leirbag95 Date: Fri, 5 Jan 2024 09:15:50 +0100 Subject: [PATCH 2/3] receiver from Payment type set to optionnal --- src/messages/program/programModel.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/messages/program/programModel.ts b/src/messages/program/programModel.ts index 5aa8fea0..0c82ed61 100644 --- a/src/messages/program/programModel.ts +++ b/src/messages/program/programModel.ts @@ -70,7 +70,7 @@ export type FunctionRuntime = { */ export type Payment = { chain: Chain; - receiver: string; + receiver?: string; type: PaymentType; }; From 82efd1f73a7419ee96d52bc2b599c24ec521e4c6 Mon Sep 17 00:00:00 2001 From: mhh Date: Fri, 5 Jan 2024 21:48:13 +0100 Subject: [PATCH 3/3] refactor program and instance content types and move all to types folder --- src/messages/instance/publish.ts | 2 +- src/messages/program/publish.ts | 13 ++++++- src/messages/program/spawn.ts | 2 +- src/messages/types/base.ts | 4 +- src/messages/types/execution.ts | 12 +++++- src/messages/types/index.ts | 2 + .../{instance/types.ts => types/instance.ts} | 8 +--- .../programModel.ts => types/program.ts} | 38 +++++++------------ 8 files changed, 43 insertions(+), 38 deletions(-) rename src/messages/{instance/types.ts => types/instance.ts} (74%) rename src/messages/{program/programModel.ts => types/program.ts} (64%) diff --git a/src/messages/instance/publish.ts b/src/messages/instance/publish.ts index 4beb2482..904cf6c0 100644 --- a/src/messages/instance/publish.ts +++ b/src/messages/instance/publish.ts @@ -8,8 +8,8 @@ import { FunctionEnvironment, MachineResources, VolumePersistence, + InstanceContent, } from "../types"; -import { InstanceContent } from "./types"; import { PutContentToStorageEngine } from "../create/publish"; import { SignAndBroadcast } from "../create/signature"; import { DEFAULT_API_V2 } from "../../global"; diff --git a/src/messages/program/publish.ts b/src/messages/program/publish.ts index 5877dd02..7014b67e 100644 --- a/src/messages/program/publish.ts +++ b/src/messages/program/publish.ts @@ -1,7 +1,16 @@ import { Account } from "../../accounts/account"; -import { ItemType, MessageType, ProgramMessage, StoreMessage, MachineVolume } from "../types"; +import { + ItemType, + MessageType, + ProgramMessage, + StoreMessage, + MachineVolume, + Encoding, + FunctionTriggers, + MachineType, + ProgramContent, +} from "../types"; import { Publish as storePublish } from "../../messages/store/index"; -import { Encoding, FunctionTriggers, MachineType, ProgramContent } from "./programModel"; import { PutContentToStorageEngine } from "../create/publish"; import { SignAndBroadcast } from "../create/signature"; import { DEFAULT_API_V2 } from "../../global"; diff --git a/src/messages/program/spawn.ts b/src/messages/program/spawn.ts index 2aa3c32b..998156c7 100644 --- a/src/messages/program/spawn.ts +++ b/src/messages/program/spawn.ts @@ -1,6 +1,6 @@ import { Account } from "../../accounts/account"; import { ItemType, ProgramMessage, MachineVolume } from "../types"; -import { Encoding } from "./programModel"; +import { Encoding } from "../types/program"; import { DEFAULT_API_V2 } from "../../global"; import { publish } from "./publish"; diff --git a/src/messages/types/base.ts b/src/messages/types/base.ts index 85e00b61..75f1bd52 100644 --- a/src/messages/types/base.ts +++ b/src/messages/types/base.ts @@ -4,8 +4,8 @@ * * Warning: Avax, CSDK, NEO are currently not supported by the TS sdk. */ -import { InstanceContent } from "../instance/types"; -import { ProgramContent } from "../program/programModel"; +import { InstanceContent } from "./instance"; +import { ProgramContent } from "./program"; export enum Chain { DOT = "DOT", diff --git a/src/messages/types/execution.ts b/src/messages/types/execution.ts index 179edfa3..3b0b5d9f 100644 --- a/src/messages/types/execution.ts +++ b/src/messages/types/execution.ts @@ -1,4 +1,4 @@ -import { BaseContent } from "./base"; +import { BaseContent, Chain, PaymentType } from "./base"; import { MachineVolume } from "./volumes"; /** @@ -47,6 +47,15 @@ export type HostRequirements = { node?: NodeRequirements; }; +/** + * Payment solution + */ +export type Payment = { + chain: Chain; + receiver?: string; + type: PaymentType; +}; + /** * Abstract content for execution messages (Instances, Programs). * @@ -67,6 +76,7 @@ export type BaseExecutableContent = BaseContent & { variables?: Record; environment: FunctionEnvironment; resources: MachineResources; + payment?: Payment; requirements?: HostRequirements; volumes: MachineVolume[]; replaces?: string; diff --git a/src/messages/types/index.ts b/src/messages/types/index.ts index 2fe8f9b2..09c7de57 100644 --- a/src/messages/types/index.ts +++ b/src/messages/types/index.ts @@ -1,3 +1,5 @@ export * from "./base"; export * from "./volumes"; export * from "./execution"; +export * from "./program"; +export * from "./instance"; diff --git a/src/messages/instance/types.ts b/src/messages/types/instance.ts similarity index 74% rename from src/messages/instance/types.ts rename to src/messages/types/instance.ts index fa77c875..b06ee18a 100644 --- a/src/messages/instance/types.ts +++ b/src/messages/types/instance.ts @@ -1,4 +1,4 @@ -import { BaseExecutableContent, ParentVolume, VolumePersistence, Chain, PaymentType } from "../types"; +import { BaseExecutableContent, ParentVolume, VolumePersistence } from "./index"; /** * Root file system of a VM instance. @@ -10,12 +10,6 @@ export type RootfsVolume = { size_mib: number; //Limit to 1 GiB }; -export type Payment = { - chain: Chain; - receiver: string; - type: PaymentType; -}; - /** * Message content for scheduling a VM instance on the network. * diff --git a/src/messages/program/programModel.ts b/src/messages/types/program.ts similarity index 64% rename from src/messages/program/programModel.ts rename to src/messages/types/program.ts index 0c82ed61..4014395d 100644 --- a/src/messages/program/programModel.ts +++ b/src/messages/types/program.ts @@ -1,5 +1,4 @@ -import { BaseContent, MachineVolume } from "../types"; -import { FunctionEnvironment, MachineResources, Chain, PaymentType } from "../types"; +import { BaseExecutableContent } from "./execution"; /** * Type of Encoding @@ -17,6 +16,14 @@ export enum MachineType { vm_function = "vm-function", } +/** + * Type of interface + */ +export enum InterfaceType { + asgi = "asgi", + binary = "binary", +} + /** * Code to execute */ @@ -25,8 +32,8 @@ export type CodeContent = { entrypoint: string; ref: string; use_latest: boolean; - interface: string; - args: string[]; + interface?: InterfaceType; + args?: string[]; }; /** @@ -65,28 +72,11 @@ export type FunctionRuntime = { comment: string; }; -/** - * Payment solution - */ -export type Payment = { - chain: Chain; - receiver?: string; - type: PaymentType; -}; - -export type ProgramContent = BaseContent & { - type: MachineType; - allow_amend: boolean; +export type ProgramContent = BaseExecutableContent & { + type: MachineType.vm_function; code: CodeContent; - variables?: { [key: string]: string }; + runtime: FunctionRuntime; data?: DataContent; export?: Export; on: FunctionTriggers; - metadata?: Record; - environment: FunctionEnvironment; - resources: MachineResources; - runtime: FunctionRuntime; - volumes: MachineVolume[]; - payment?: Payment; - replaces?: string; };