@c7-digital/ledger 0.0.8 → 0.0.9
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/lib/src/ledger.js +7 -6
- package/lib/src/sets.d.ts +29 -0
- package/lib/src/sets.js +39 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib-lite/src/ledger.js +7 -6
- package/lib-lite/src/sets.d.ts +29 -0
- package/lib-lite/src/sets.js +39 -0
- package/lib-lite/tsconfig.temp.tsbuildinfo +1 -1
- package/package.json +5 -1
package/lib/src/ledger.js
CHANGED
|
@@ -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>;
|
package/lib/src/sets.js
ADDED
|
@@ -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
|
+
}
|