@distrohelena/canton-typescript-sdk 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/types/commands/create-and-exercise-command.d.ts +12 -0
- package/dist/core/types/commands/create-and-exercise-command.js +19 -0
- package/dist/core/types/commands/create-command.js +4 -0
- package/dist/core/types/commands/exercise-by-key-command.d.ts +12 -0
- package/dist/core/types/commands/exercise-by-key-command.js +22 -0
- package/dist/core/types/commands/exercise-command.d.ts +12 -0
- package/dist/core/types/commands/exercise-command.js +22 -0
- package/dist/core/types/commands/ledger-command.d.ts +5 -0
- package/dist/core/types/commands/ledger-command.js +1 -0
- package/dist/core/types/requests/submit-command-request.d.ts +3 -3
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/services/commands/command-payload-builder.js +42 -4
- package/dist/transports/grpc/mappers/commands-mapper.js +53 -4
- package/dist/transports/json/json-transport.js +2 -8
- package/dist/transports/json/mappers/commands-mapper.d.ts +11 -0
- package/dist/transports/json/mappers/commands-mapper.js +60 -1
- package/package.json +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class CreateAndExerciseCommand {
|
|
2
|
+
readonly templateId: string;
|
|
3
|
+
readonly payload: Record<string, unknown>;
|
|
4
|
+
readonly choice: string;
|
|
5
|
+
readonly argument: unknown;
|
|
6
|
+
constructor(init: {
|
|
7
|
+
templateId: string;
|
|
8
|
+
payload: Record<string, unknown>;
|
|
9
|
+
choice: string;
|
|
10
|
+
argument: unknown;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ValidationError } from "../../errors/validation-error.js";
|
|
2
|
+
export class CreateAndExerciseCommand {
|
|
3
|
+
templateId;
|
|
4
|
+
payload;
|
|
5
|
+
choice;
|
|
6
|
+
argument;
|
|
7
|
+
constructor(init) {
|
|
8
|
+
if (!init.templateId) {
|
|
9
|
+
throw new ValidationError("create-and-exercise commands require a templateId");
|
|
10
|
+
}
|
|
11
|
+
if (!init.choice) {
|
|
12
|
+
throw new ValidationError("create-and-exercise commands require a choice");
|
|
13
|
+
}
|
|
14
|
+
this.templateId = init.templateId;
|
|
15
|
+
this.payload = init.payload;
|
|
16
|
+
this.choice = init.choice;
|
|
17
|
+
this.argument = init.argument;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { ValidationError } from "../../errors/validation-error.js";
|
|
1
2
|
export class CreateCommand {
|
|
2
3
|
templateId;
|
|
3
4
|
payload;
|
|
4
5
|
constructor(init) {
|
|
6
|
+
if (!init.templateId) {
|
|
7
|
+
throw new ValidationError("create commands require a templateId");
|
|
8
|
+
}
|
|
5
9
|
this.templateId = init.templateId;
|
|
6
10
|
this.payload = init.payload;
|
|
7
11
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class ExerciseByKeyCommand {
|
|
2
|
+
readonly templateId: string;
|
|
3
|
+
readonly contractKey: unknown;
|
|
4
|
+
readonly choice: string;
|
|
5
|
+
readonly argument: unknown;
|
|
6
|
+
constructor(init: {
|
|
7
|
+
templateId: string;
|
|
8
|
+
contractKey: unknown;
|
|
9
|
+
choice: string;
|
|
10
|
+
argument: unknown;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ValidationError } from "../../errors/validation-error.js";
|
|
2
|
+
export class ExerciseByKeyCommand {
|
|
3
|
+
templateId;
|
|
4
|
+
contractKey;
|
|
5
|
+
choice;
|
|
6
|
+
argument;
|
|
7
|
+
constructor(init) {
|
|
8
|
+
if (!init.templateId) {
|
|
9
|
+
throw new ValidationError("exercise-by-key commands require a templateId");
|
|
10
|
+
}
|
|
11
|
+
if (init.contractKey === undefined) {
|
|
12
|
+
throw new ValidationError("exercise-by-key commands require a contractKey");
|
|
13
|
+
}
|
|
14
|
+
if (!init.choice) {
|
|
15
|
+
throw new ValidationError("exercise-by-key commands require a choice");
|
|
16
|
+
}
|
|
17
|
+
this.templateId = init.templateId;
|
|
18
|
+
this.contractKey = init.contractKey;
|
|
19
|
+
this.choice = init.choice;
|
|
20
|
+
this.argument = init.argument;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class ExerciseCommand {
|
|
2
|
+
readonly templateId: string;
|
|
3
|
+
readonly contractId: string;
|
|
4
|
+
readonly choice: string;
|
|
5
|
+
readonly argument: unknown;
|
|
6
|
+
constructor(init: {
|
|
7
|
+
templateId: string;
|
|
8
|
+
contractId: string;
|
|
9
|
+
choice: string;
|
|
10
|
+
argument: unknown;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ValidationError } from "../../errors/validation-error.js";
|
|
2
|
+
export class ExerciseCommand {
|
|
3
|
+
templateId;
|
|
4
|
+
contractId;
|
|
5
|
+
choice;
|
|
6
|
+
argument;
|
|
7
|
+
constructor(init) {
|
|
8
|
+
if (!init.templateId) {
|
|
9
|
+
throw new ValidationError("exercise commands require a templateId");
|
|
10
|
+
}
|
|
11
|
+
if (!init.contractId) {
|
|
12
|
+
throw new ValidationError("exercise commands require a contractId");
|
|
13
|
+
}
|
|
14
|
+
if (!init.choice) {
|
|
15
|
+
throw new ValidationError("exercise commands require a choice");
|
|
16
|
+
}
|
|
17
|
+
this.templateId = init.templateId;
|
|
18
|
+
this.contractId = init.contractId;
|
|
19
|
+
this.choice = init.choice;
|
|
20
|
+
this.argument = init.argument;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CreateAndExerciseCommand } from "./create-and-exercise-command.js";
|
|
2
|
+
import { CreateCommand } from "./create-command.js";
|
|
3
|
+
import { ExerciseByKeyCommand } from "./exercise-by-key-command.js";
|
|
4
|
+
import { ExerciseCommand } from "./exercise-command.js";
|
|
5
|
+
export type LedgerCommand = CreateCommand | ExerciseCommand | ExerciseByKeyCommand | CreateAndExerciseCommand;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LedgerCommand } from "../commands/ledger-command.js";
|
|
2
2
|
export declare class SubmitCommandRequest {
|
|
3
3
|
readonly applicationId: string;
|
|
4
4
|
readonly actAs: readonly string[];
|
|
5
5
|
readonly readAs: readonly string[];
|
|
6
|
-
readonly command:
|
|
6
|
+
readonly command: LedgerCommand;
|
|
7
7
|
constructor(init: {
|
|
8
8
|
applicationId: string;
|
|
9
9
|
actAs: readonly string[];
|
|
10
10
|
readAs?: readonly string[];
|
|
11
|
-
command:
|
|
11
|
+
command: LedgerCommand;
|
|
12
12
|
});
|
|
13
13
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -180,7 +180,11 @@ export { VettedPackage } from "./core/types/vetted-package.js";
|
|
|
180
180
|
export { VettedPackages } from "./core/types/vetted-packages.js";
|
|
181
181
|
export { PreparedTopologyTransaction } from "./core/types/topology/prepared-topology-transaction.js";
|
|
182
182
|
export { SignedTopologyTransaction } from "./core/types/topology/signed-topology-transaction.js";
|
|
183
|
+
export { CreateAndExerciseCommand } from "./core/types/commands/create-and-exercise-command.js";
|
|
183
184
|
export { CreateCommand } from "./core/types/commands/create-command.js";
|
|
185
|
+
export { ExerciseByKeyCommand } from "./core/types/commands/exercise-by-key-command.js";
|
|
186
|
+
export { ExerciseCommand } from "./core/types/commands/exercise-command.js";
|
|
187
|
+
export type { LedgerCommand } from "./core/types/commands/ledger-command.js";
|
|
184
188
|
export { AddTopologyTransactionsRequest } from "./core/types/requests/add-topology-transactions-request.js";
|
|
185
189
|
export { AllocateExternalPartyRequest } from "./core/types/requests/allocate-external-party-request.js";
|
|
186
190
|
export { AllocatePartyRequest } from "./core/types/requests/allocate-party-request.js";
|
package/dist/index.js
CHANGED
|
@@ -175,7 +175,10 @@ export { VettedPackage } from "./core/types/vetted-package.js";
|
|
|
175
175
|
export { VettedPackages } from "./core/types/vetted-packages.js";
|
|
176
176
|
export { PreparedTopologyTransaction } from "./core/types/topology/prepared-topology-transaction.js";
|
|
177
177
|
export { SignedTopologyTransaction } from "./core/types/topology/signed-topology-transaction.js";
|
|
178
|
+
export { CreateAndExerciseCommand } from "./core/types/commands/create-and-exercise-command.js";
|
|
178
179
|
export { CreateCommand } from "./core/types/commands/create-command.js";
|
|
180
|
+
export { ExerciseByKeyCommand } from "./core/types/commands/exercise-by-key-command.js";
|
|
181
|
+
export { ExerciseCommand } from "./core/types/commands/exercise-command.js";
|
|
179
182
|
export { AddTopologyTransactionsRequest } from "./core/types/requests/add-topology-transactions-request.js";
|
|
180
183
|
export { AllocateExternalPartyRequest } from "./core/types/requests/allocate-external-party-request.js";
|
|
181
184
|
export { AllocatePartyRequest } from "./core/types/requests/allocate-party-request.js";
|
|
@@ -1,11 +1,49 @@
|
|
|
1
|
+
import { CreateAndExerciseCommand } from "../../core/types/commands/create-and-exercise-command.js";
|
|
2
|
+
import { CreateCommand } from "../../core/types/commands/create-command.js";
|
|
3
|
+
import { ExerciseByKeyCommand } from "../../core/types/commands/exercise-by-key-command.js";
|
|
4
|
+
import { ExerciseCommand } from "../../core/types/commands/exercise-command.js";
|
|
1
5
|
export function buildCanonicalCommandPayload(request) {
|
|
2
6
|
return new TextEncoder().encode(JSON.stringify({
|
|
3
7
|
applicationId: request.applicationId,
|
|
4
8
|
actAs: request.actAs,
|
|
5
9
|
readAs: request.readAs,
|
|
6
|
-
command:
|
|
7
|
-
templateId: request.command.templateId,
|
|
8
|
-
payload: request.command.payload,
|
|
9
|
-
},
|
|
10
|
+
command: mapCanonicalCommand(request.command),
|
|
10
11
|
}));
|
|
11
12
|
}
|
|
13
|
+
function mapCanonicalCommand(command) {
|
|
14
|
+
if (command instanceof CreateCommand) {
|
|
15
|
+
return {
|
|
16
|
+
kind: "create",
|
|
17
|
+
templateId: command.templateId,
|
|
18
|
+
payload: command.payload,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
if (command instanceof ExerciseCommand) {
|
|
22
|
+
return {
|
|
23
|
+
kind: "exercise",
|
|
24
|
+
templateId: command.templateId,
|
|
25
|
+
contractId: command.contractId,
|
|
26
|
+
choice: command.choice,
|
|
27
|
+
argument: command.argument,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (command instanceof ExerciseByKeyCommand) {
|
|
31
|
+
return {
|
|
32
|
+
kind: "exerciseByKey",
|
|
33
|
+
templateId: command.templateId,
|
|
34
|
+
contractKey: command.contractKey,
|
|
35
|
+
choice: command.choice,
|
|
36
|
+
argument: command.argument,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (command instanceof CreateAndExerciseCommand) {
|
|
40
|
+
return {
|
|
41
|
+
kind: "createAndExercise",
|
|
42
|
+
templateId: command.templateId,
|
|
43
|
+
payload: command.payload,
|
|
44
|
+
choice: command.choice,
|
|
45
|
+
argument: command.argument,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return {};
|
|
49
|
+
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { ValidationError } from "../../../core/errors/validation-error.js";
|
|
3
|
+
import { CreateAndExerciseCommand } from "../../../core/types/commands/create-and-exercise-command.js";
|
|
4
|
+
import { CreateCommand } from "../../../core/types/commands/create-command.js";
|
|
5
|
+
import { ExerciseByKeyCommand } from "../../../core/types/commands/exercise-by-key-command.js";
|
|
6
|
+
import { ExerciseCommand } from "../../../core/types/commands/exercise-command.js";
|
|
3
7
|
import { SubmitCommandResponse } from "../../../core/types/responses/submit-command-response.js";
|
|
4
8
|
export function mapGrpcSubmitCommandRequest(request, _signed) {
|
|
5
9
|
return {
|
|
@@ -7,7 +11,7 @@ export function mapGrpcSubmitCommandRequest(request, _signed) {
|
|
|
7
11
|
workflowId: "",
|
|
8
12
|
userId: "",
|
|
9
13
|
commandId: randomUUID(),
|
|
10
|
-
commands: [
|
|
14
|
+
commands: [mapCommand(request.command)],
|
|
11
15
|
deduplicationPeriod: {
|
|
12
16
|
oneofKind: undefined,
|
|
13
17
|
},
|
|
@@ -29,13 +33,58 @@ export function mapGrpcSubmitCommand(payload) {
|
|
|
29
33
|
: payload.updateId,
|
|
30
34
|
});
|
|
31
35
|
}
|
|
32
|
-
function
|
|
36
|
+
function mapCommand(command) {
|
|
37
|
+
if (command instanceof CreateCommand) {
|
|
38
|
+
return mapCreateCommand(command);
|
|
39
|
+
}
|
|
40
|
+
if (command instanceof ExerciseCommand) {
|
|
41
|
+
return {
|
|
42
|
+
command: {
|
|
43
|
+
oneofKind: "exercise",
|
|
44
|
+
exercise: {
|
|
45
|
+
templateId: parseTemplateIdentifier(command.templateId),
|
|
46
|
+
contractId: command.contractId,
|
|
47
|
+
choice: command.choice,
|
|
48
|
+
choiceArgument: mapValue(command.argument),
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (command instanceof ExerciseByKeyCommand) {
|
|
54
|
+
return {
|
|
55
|
+
command: {
|
|
56
|
+
oneofKind: "exerciseByKey",
|
|
57
|
+
exerciseByKey: {
|
|
58
|
+
templateId: parseTemplateIdentifier(command.templateId),
|
|
59
|
+
contractKey: mapValue(command.contractKey),
|
|
60
|
+
choice: command.choice,
|
|
61
|
+
choiceArgument: mapValue(command.argument),
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (command instanceof CreateAndExerciseCommand) {
|
|
67
|
+
return {
|
|
68
|
+
command: {
|
|
69
|
+
oneofKind: "createAndExercise",
|
|
70
|
+
createAndExercise: {
|
|
71
|
+
templateId: parseTemplateIdentifier(command.templateId),
|
|
72
|
+
createArguments: mapRecord(command.payload),
|
|
73
|
+
choice: command.choice,
|
|
74
|
+
choiceArgument: mapValue(command.argument),
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
throw new ValidationError("unsupported submit command type");
|
|
80
|
+
}
|
|
81
|
+
function mapCreateCommand(command) {
|
|
33
82
|
return {
|
|
34
83
|
command: {
|
|
35
84
|
oneofKind: "create",
|
|
36
85
|
create: {
|
|
37
|
-
templateId: parseTemplateIdentifier(
|
|
38
|
-
createArguments: mapRecord(
|
|
86
|
+
templateId: parseTemplateIdentifier(command.templateId),
|
|
87
|
+
createArguments: mapRecord(command.payload),
|
|
39
88
|
},
|
|
40
89
|
},
|
|
41
90
|
};
|
|
@@ -5,7 +5,7 @@ import { ListKnownPartiesResponse } from "../../core/types/responses/list-known-
|
|
|
5
5
|
import { UploadDarFileResponse } from "../../core/types/responses/upload-dar-file-response.js";
|
|
6
6
|
import { NotSupportedError } from "../../core/errors/not-supported-error.js";
|
|
7
7
|
import { ObjectDisposedError } from "../../core/errors/object-disposed-error.js";
|
|
8
|
-
import { mapJsonSubmitCommand } from "./mappers/commands-mapper.js";
|
|
8
|
+
import { mapJsonSubmitCommand, mapJsonSubmitCommandRequest, } from "./mappers/commands-mapper.js";
|
|
9
9
|
import { mapJsonUploadPackage } from "./mappers/packages-mapper.js";
|
|
10
10
|
import { mapJsonAllocatePartyRequest, mapJsonCreateParty, mapJsonListParties, } from "./mappers/parties-mapper.js";
|
|
11
11
|
import { mapJsonQueryContracts } from "./mappers/contracts-mapper.js";
|
|
@@ -458,13 +458,7 @@ export class JsonTransport {
|
|
|
458
458
|
if (signed) {
|
|
459
459
|
throw new NotSupportedError("command signing is not supported by json transport");
|
|
460
460
|
}
|
|
461
|
-
const payload = await this.httpClient.postAsync("/
|
|
462
|
-
templateId: request.command.templateId,
|
|
463
|
-
payload: request.command.payload,
|
|
464
|
-
applicationId: request.applicationId,
|
|
465
|
-
actAs: request.actAs,
|
|
466
|
-
readAs: request.readAs,
|
|
467
|
-
}, options);
|
|
461
|
+
const payload = await this.httpClient.postAsync("/v2/commands/submit-and-wait", mapJsonSubmitCommandRequest(request), options);
|
|
468
462
|
return mapJsonSubmitCommand(payload);
|
|
469
463
|
}
|
|
470
464
|
throwIfDisposed() {
|
|
@@ -1,9 +1,20 @@
|
|
|
1
|
+
import { SubmitCommandRequest } from "../../../core/types/requests/submit-command-request.js";
|
|
1
2
|
import { SubmitCommandResponse } from "../../../core/types/responses/submit-command-response.js";
|
|
3
|
+
export declare function mapJsonSubmitCommandRequest(request: SubmitCommandRequest): {
|
|
4
|
+
commandId: string;
|
|
5
|
+
actAs: readonly string[];
|
|
6
|
+
readAs: readonly string[];
|
|
7
|
+
commands: unknown[];
|
|
8
|
+
applicationId?: string;
|
|
9
|
+
};
|
|
2
10
|
export declare function mapJsonSubmitCommand(payload: {
|
|
3
11
|
result?: {
|
|
4
12
|
commandId?: string;
|
|
5
13
|
transactionId?: string;
|
|
14
|
+
updateId?: string;
|
|
6
15
|
};
|
|
7
16
|
commandId?: string;
|
|
8
17
|
transactionId?: string;
|
|
18
|
+
updateId?: string;
|
|
19
|
+
completionOffset?: string;
|
|
9
20
|
}): SubmitCommandResponse;
|
|
@@ -1,7 +1,66 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { ValidationError } from "../../../core/errors/validation-error.js";
|
|
3
|
+
import { CreateAndExerciseCommand } from "../../../core/types/commands/create-and-exercise-command.js";
|
|
4
|
+
import { CreateCommand } from "../../../core/types/commands/create-command.js";
|
|
5
|
+
import { ExerciseByKeyCommand } from "../../../core/types/commands/exercise-by-key-command.js";
|
|
6
|
+
import { ExerciseCommand } from "../../../core/types/commands/exercise-command.js";
|
|
1
7
|
import { SubmitCommandResponse } from "../../../core/types/responses/submit-command-response.js";
|
|
8
|
+
export function mapJsonSubmitCommandRequest(request) {
|
|
9
|
+
return {
|
|
10
|
+
commandId: randomUUID(),
|
|
11
|
+
actAs: request.actAs,
|
|
12
|
+
readAs: request.readAs,
|
|
13
|
+
commands: [mapJsonCommand(request.command)],
|
|
14
|
+
applicationId: request.applicationId || undefined,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
2
17
|
export function mapJsonSubmitCommand(payload) {
|
|
3
18
|
return new SubmitCommandResponse({
|
|
4
19
|
commandId: payload.result?.commandId ?? payload.commandId,
|
|
5
|
-
transactionId: payload.result?.transactionId
|
|
20
|
+
transactionId: payload.result?.transactionId
|
|
21
|
+
?? payload.result?.updateId
|
|
22
|
+
?? payload.transactionId
|
|
23
|
+
?? payload.updateId,
|
|
6
24
|
});
|
|
7
25
|
}
|
|
26
|
+
function mapJsonCommand(command) {
|
|
27
|
+
if (command instanceof CreateCommand) {
|
|
28
|
+
return {
|
|
29
|
+
CreateCommand: {
|
|
30
|
+
templateId: command.templateId,
|
|
31
|
+
createArguments: command.payload,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
if (command instanceof ExerciseCommand) {
|
|
36
|
+
return {
|
|
37
|
+
ExerciseCommand: {
|
|
38
|
+
templateId: command.templateId,
|
|
39
|
+
contractId: command.contractId,
|
|
40
|
+
choice: command.choice,
|
|
41
|
+
choiceArgument: command.argument,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (command instanceof ExerciseByKeyCommand) {
|
|
46
|
+
return {
|
|
47
|
+
ExerciseByKeyCommand: {
|
|
48
|
+
templateId: command.templateId,
|
|
49
|
+
contractKey: command.contractKey,
|
|
50
|
+
choice: command.choice,
|
|
51
|
+
choiceArgument: command.argument,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (command instanceof CreateAndExerciseCommand) {
|
|
56
|
+
return {
|
|
57
|
+
CreateAndExerciseCommand: {
|
|
58
|
+
templateId: command.templateId,
|
|
59
|
+
createArguments: command.payload,
|
|
60
|
+
choice: command.choice,
|
|
61
|
+
choiceArgument: command.argument,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
throw new ValidationError("unsupported submit command type");
|
|
66
|
+
}
|