@c7-digital/ledger 0.0.8 → 0.0.10

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.
@@ -17,7 +17,7 @@
17
17
  * you need access to Canton-specific endpoints or full control over API calls.
18
18
  */
19
19
  import { ContractId, Party, Choice, InterfaceCompanion, Template } from "@daml/types";
20
- import { AllocatePartyRequest, AllocatePartyResponse, Command, CreateCommand, CreateAndExerciseCommand, CreateEvent, ExerciseCommand, Event, Interface, LedgerOffset, Stream, InterfaceStream, InterfaceMapping, InterfaceMultiStream, PartyDetails, User, MultiStream, TemplateMapping, VersionedRegistry } from "./types.js";
20
+ import { AllocatePartyRequest, AllocatePartyResponse, AnyCommand, CreateCommand, CreateAndExerciseCommand, CreateEvent, ExerciseCommand, Event, Interface, LedgerOffset, Stream, InterfaceStream, InterfaceMapping, InterfaceMultiStream, PartyDetails, User, MultiStream, TemplateMapping, VersionedRegistry } from "./types.js";
21
21
  import { ValidationMode } from "./validation.js";
22
22
  import { PackageIdString } from "./valueTypes.js";
23
23
  export declare function createCmd<T extends object, K = unknown>(template: Template<T, K, string>, payload: T): CreateCommand<T, K>;
@@ -134,7 +134,7 @@ export declare class Ledger {
134
134
  * @param actAs Defaults to the actAs parties of the user in the token.
135
135
  * @returns Stream of events resulting from the submitted commands.
136
136
  */
137
- submit(commands: Command<any, any>[], actAs?: Party[]): Promise<Event<object, unknown>[]>;
137
+ submit(commands: AnyCommand[], actAs?: Party[]): Promise<Event<object, unknown>[]>;
138
138
  private initClient;
139
139
  /**
140
140
  * Stream functionality using WebSockets
@@ -63,6 +63,7 @@ function createEvent_(cantonEvent, versionedRegistry) {
63
63
  }
64
64
  }
65
65
  else {
66
+ console.debug(`Using default lookupTemplate for ${cantonEvent.templateId}`);
66
67
  t = lookupTemplate(cantonEvent.templateId);
67
68
  }
68
69
  return {
@@ -171,16 +172,16 @@ function convertCommand(command) {
171
172
  return {
172
173
  CreateCommand: {
173
174
  templateId: command.template.templateId,
174
- createArguments: command.payload,
175
+ createArguments: command.template.encode(command.payload),
175
176
  }
176
177
  };
177
178
  case 'createAndExercise':
178
179
  return {
179
180
  CreateAndExerciseCommand: {
180
181
  templateId: command.template.templateId,
181
- createArguments: command.payload,
182
+ createArguments: command.template.encode(command.payload),
182
183
  choice: createNameString(command.choice.choiceName),
183
- choiceArgument: command.argument,
184
+ choiceArgument: command.choice.argumentEncode(command.argument),
184
185
  }
185
186
  };
186
187
  case 'exercise':
@@ -189,7 +190,7 @@ function convertCommand(command) {
189
190
  templateId: command.choice.template().templateId,
190
191
  contractId: createLedgerString(command.contractId),
191
192
  choice: createNameString(command.choice.choiceName),
192
- choiceArgument: command.argument,
193
+ choiceArgument: command.choice.argumentEncode(command.argument),
193
194
  }
194
195
  };
195
196
  default:
@@ -679,7 +680,7 @@ export class Ledger {
679
680
  async create(template, payload, actAs) {
680
681
  const createCommand = {
681
682
  templateId: template.templateId,
682
- createArguments: payload,
683
+ createArguments: template.encode(payload),
683
684
  };
684
685
  const actAs_ = actAs || (await this.getTokenActAsParties());
685
686
  const commands = {
@@ -735,7 +736,7 @@ export class Ledger {
735
736
  templateId: choice.template().templateId,
736
737
  contractId: createLedgerString(contractId.toString()),
737
738
  choice: createNameString(choice.choiceName),
738
- choiceArgument: argument,
739
+ choiceArgument: choice.argumentEncode(argument),
739
740
  };
740
741
  const actAs_ = actAs || (await this.getTokenActAsParties());
741
742
  const commands = {
@@ -0,0 +1,29 @@
1
+ import { Map as DamlMap } from "@daml/types";
2
+ /**
3
+ * Immutable Set mirroring Daml's DA.Set.Types.Set<T>.
4
+ *
5
+ * Structurally compatible with the codegen's `{ map: DamlMap<T, {}> }`,
6
+ * so instances can be passed directly to template payloads and choice arguments.
7
+ */
8
+ export interface DamlSet<T> {
9
+ /** The underlying Map<T, Unit>. Exposed for codegen compatibility. */
10
+ readonly map: DamlMap<T, {}>;
11
+ /** Check if the set contains an item. */
12
+ has(item: T): boolean;
13
+ /** Add an item, returning a new set. */
14
+ add(item: T): DamlSet<T>;
15
+ /** Remove an item, returning a new set. */
16
+ delete(item: T): DamlSet<T>;
17
+ /** Return an iterator over the set's items. */
18
+ values(): Iterator<T, undefined, undefined>;
19
+ /** Return the set's items as an array. */
20
+ toArray(): T[];
21
+ /** Return the number of items in the set. */
22
+ readonly size: number;
23
+ /** Call a function for each item in the set. */
24
+ forEach(f: (item: T) => void): void;
25
+ }
26
+ /** Create a DamlSet from an array of items. */
27
+ export declare function create<T>(items: T[]): DamlSet<T>;
28
+ /** Create an empty DamlSet. */
29
+ export declare function empty<T>(): DamlSet<T>;
@@ -0,0 +1,39 @@
1
+ import { emptyMap } from "@daml/types";
2
+ class DamlSetImpl {
3
+ constructor(map) {
4
+ this.map = map;
5
+ }
6
+ has(item) {
7
+ return this.map.has(item);
8
+ }
9
+ add(item) {
10
+ return new DamlSetImpl(this.map.set(item, {}));
11
+ }
12
+ delete(item) {
13
+ return new DamlSetImpl(this.map.delete(item));
14
+ }
15
+ values() {
16
+ return this.map.keys();
17
+ }
18
+ toArray() {
19
+ return this.map.entriesArray().map(([k]) => k);
20
+ }
21
+ get size() {
22
+ return this.map.entriesArray().length;
23
+ }
24
+ forEach(f) {
25
+ this.map.forEach((_v, k) => f(k));
26
+ }
27
+ }
28
+ /** Create a DamlSet from an array of items. */
29
+ export function create(items) {
30
+ let map = emptyMap();
31
+ for (const item of items) {
32
+ map = map.set(item, {});
33
+ }
34
+ return new DamlSetImpl(map);
35
+ }
36
+ /** Create an empty DamlSet. */
37
+ export function empty() {
38
+ return new DamlSetImpl(emptyMap());
39
+ }
@@ -226,6 +226,13 @@ export type ExerciseCommand<T extends object, C, R, K = unknown> = {
226
226
  argument: C;
227
227
  };
228
228
  export type Command<T extends object, C, R = unknown, K = unknown> = CreateCommand<T, K> | CreateAndExerciseCommand<T, C, R, K> | ExerciseCommand<T, C, R, K>;
229
+ /**
230
+ * A command with erased type parameters, suitable for heterogeneous arrays
231
+ * passed to `Ledger.submit()`. Each variant is independently widened to `any`,
232
+ * so a `CreateCommand<A, KA>` and an `ExerciseCommand<B, CB, RB, KB>` can
233
+ * coexist in the same `AnyCommand[]` without a cast.
234
+ */
235
+ export type AnyCommand = CreateCommand<any, any> | CreateAndExerciseCommand<any, any, any, any> | ExerciseCommand<any, any, any, any>;
229
236
  export interface AllocatePartyRequest {
230
237
  partyIdHint?: PartyIdString;
231
238
  displayName?: string;