@distrohelena/canton-typescript-sdk 0.1.4 → 0.1.6
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/README.md +333 -1
- package/dist/client/canton-client-options.d.ts +3 -0
- package/dist/client/canton-client-options.js +2 -0
- package/dist/client/service-registry.js +4 -3
- package/dist/core/errors/grpc-transport-error.d.ts +14 -0
- package/dist/core/errors/grpc-transport-error.js +76 -0
- package/dist/core/signing/sign-command-request.d.ts +4 -0
- package/dist/core/signing/sign-command-request.js +4 -0
- package/dist/core/signing/sign-command-result.d.ts +2 -0
- package/dist/core/signing/sign-command-result.js +9 -0
- package/dist/core/transports/transport.interface.d.ts +2 -2
- package/dist/core/types/canton-hash-purpose.d.ts +2 -1
- package/dist/core/types/canton-hash-purpose.js +1 -0
- package/dist/core/types/commands/create-and-exercise-command.js +1 -1
- package/dist/core/types/commands/exercise-by-key-command.js +2 -2
- package/dist/core/types/commands/exercise-command.js +2 -2
- package/dist/core/types/daml-numeric.d.ts +6 -0
- package/dist/core/types/daml-numeric.js +14 -0
- package/dist/core/types/daml-party.d.ts +6 -0
- package/dist/core/types/daml-party.js +14 -0
- package/dist/core/types/requests/create-decentralized-party-request.d.ts +41 -0
- package/dist/core/types/requests/create-decentralized-party-request.js +82 -0
- package/dist/core/types/requests/create-external-party-request.d.ts +42 -0
- package/dist/core/types/requests/create-external-party-request.js +47 -0
- package/dist/core/types/requests/finalize-decentralized-party-request.d.ts +39 -0
- package/dist/core/types/requests/finalize-decentralized-party-request.js +42 -0
- package/dist/core/types/requests/get-active-contracts-page-request.d.ts +15 -2
- package/dist/core/types/requests/get-active-contracts-page-request.js +4 -0
- package/dist/core/types/requests/submit-command-request.d.ts +2 -0
- package/dist/core/types/requests/submit-command-request.js +2 -0
- package/dist/core/types/topology/topology-signature-format.d.ts +2 -1
- package/dist/core/types/topology/topology-signature-format.js +1 -0
- package/dist/daml-lf/container/dar-archive-entry.d.ts +8 -0
- package/dist/daml-lf/container/dar-archive-entry.js +8 -0
- package/dist/daml-lf/container/dar-archive-loader.js +14 -0
- package/dist/daml-lf/container/dar-archive.d.ts +6 -0
- package/dist/daml-lf/container/dar-archive.js +4 -0
- package/dist/daml-lf/container/dar-source-bundle-loader.d.ts +5 -0
- package/dist/daml-lf/container/dar-source-bundle-loader.js +33 -0
- package/dist/daml-lf/container/dar-source-bundle.d.ts +45 -0
- package/dist/daml-lf/container/dar-source-bundle.js +11 -0
- package/dist/daml-lf/container/dar-source-file-entry.d.ts +8 -0
- package/dist/daml-lf/container/dar-source-file-entry.js +8 -0
- package/dist/daml-lf/daml-lf-compilation.d.ts +12 -0
- package/dist/daml-lf/daml-lf-compilation.js +35 -0
- package/dist/daml-lf/index.d.ts +11 -0
- package/dist/daml-lf/index.js +10 -0
- package/dist/daml-lf/interpreter/daml-lf-builtin-dispatch.d.ts +43 -0
- package/dist/daml-lf/interpreter/daml-lf-builtin-dispatch.js +933 -0
- package/dist/daml-lf/interpreter/daml-lf-evaluator.d.ts +95 -0
- package/dist/daml-lf/interpreter/daml-lf-evaluator.js +1131 -0
- package/dist/daml-lf/interpreter/daml-lf-interpreter-scaffold.d.ts +3 -0
- package/dist/daml-lf/interpreter/daml-lf-interpreter-scaffold.js +6 -1
- package/dist/daml-lf/interpreter/daml-lf-lexical-scope.d.ts +13 -0
- package/dist/daml-lf/interpreter/daml-lf-lexical-scope.js +46 -0
- package/dist/daml-lf/interpreter/daml-lf-runtime-frame.d.ts +16 -0
- package/dist/daml-lf/interpreter/daml-lf-runtime-frame.js +15 -0
- package/dist/daml-lf/interpreter/daml-lf-runtime-value.d.ts +21 -0
- package/dist/daml-lf/interpreter/daml-lf-runtime-value.js +4 -1
- package/dist/daml-lf/interpreter/daml-lf-step-kind.d.ts +7 -0
- package/dist/daml-lf/interpreter/daml-lf-step-kind.js +8 -0
- package/dist/daml-lf/interpreter/daml-lf-trace-sink.interface.d.ts +30 -0
- package/dist/daml-lf/interpreter/daml-lf-trace-sink.interface.js +1 -0
- package/dist/daml-lf/model/daml-lf-builtin-type.d.ts +3 -0
- package/dist/daml-lf/model/daml-lf-builtin-type.js +3 -0
- package/dist/daml-lf/model/daml-lf-choice.d.ts +5 -0
- package/dist/daml-lf/model/daml-lf-choice.js +4 -0
- package/dist/daml-lf/model/daml-lf-expression-path.d.ts +2 -0
- package/dist/daml-lf/model/daml-lf-expression-path.js +81 -0
- package/dist/daml-lf/model/daml-lf-expression.d.ts +146 -0
- package/dist/daml-lf/model/daml-lf-expression.js +71 -0
- package/dist/daml-lf/model/daml-lf-template.d.ts +2 -0
- package/dist/daml-lf/model/daml-lf-template.js +2 -0
- package/dist/daml-lf/model/daml-lf-type.d.ts +2 -0
- package/dist/daml-lf/model/daml-lf-type.js +4 -0
- package/dist/daml-lf/model/lf-2-model-mapper.d.ts +5 -0
- package/dist/daml-lf/model/lf-2-model-mapper.js +445 -12
- package/dist/debugger/errors/replay-determinism.exception.d.ts +3 -0
- package/dist/debugger/errors/replay-determinism.exception.js +3 -0
- package/dist/debugger/errors/replay-missing-package.exception.d.ts +3 -0
- package/dist/debugger/errors/replay-missing-package.exception.js +3 -0
- package/dist/debugger/errors/replay-missing-source.exception.d.ts +3 -0
- package/dist/debugger/errors/replay-missing-source.exception.js +3 -0
- package/dist/debugger/errors/replay-source-map.exception.d.ts +3 -0
- package/dist/debugger/errors/replay-source-map.exception.js +3 -0
- package/dist/debugger/errors/replay-state-hydration.exception.d.ts +3 -0
- package/dist/debugger/errors/replay-state-hydration.exception.js +3 -0
- package/dist/debugger/errors/replay-unsupported-lf-construct.exception.d.ts +3 -0
- package/dist/debugger/errors/replay-unsupported-lf-construct.exception.js +3 -0
- package/dist/debugger/errors/replay-unsupported-update.exception.d.ts +3 -0
- package/dist/debugger/errors/replay-unsupported-update.exception.js +3 -0
- package/dist/debugger/index.d.ts +31 -0
- package/dist/debugger/index.js +31 -0
- package/dist/debugger/ledger-replay-debugger-client.d.ts +31 -0
- package/dist/debugger/ledger-replay-debugger-client.js +53 -0
- package/dist/debugger/replay/ledger-replay-environment-builder.d.ts +95 -0
- package/dist/debugger/replay/ledger-replay-environment-builder.js +249 -0
- package/dist/debugger/replay/ledger-replay-session-loader.d.ts +78 -0
- package/dist/debugger/replay/ledger-replay-session-loader.js +565 -0
- package/dist/debugger/replay/replay-artifact-resolver.d.ts +30 -0
- package/dist/debugger/replay/replay-artifact-resolver.js +210 -0
- package/dist/debugger/replay/replay-determinism-validator.d.ts +12 -0
- package/dist/debugger/replay/replay-determinism-validator.js +161 -0
- package/dist/debugger/replay/replay-entrypoint-definition-resolver.d.ts +40 -0
- package/dist/debugger/replay/replay-entrypoint-definition-resolver.js +337 -0
- package/dist/debugger/replay/replay-entrypoint.d.ts +22 -0
- package/dist/debugger/replay/replay-entrypoint.js +14 -0
- package/dist/debugger/replay/replay-ledger-value-normalizer.d.ts +7 -0
- package/dist/debugger/replay/replay-ledger-value-normalizer.js +194 -0
- package/dist/debugger/replay/replay-update-loader.d.ts +24 -0
- package/dist/debugger/replay/replay-update-loader.js +94 -0
- package/dist/debugger/replay/replay-update-visibility-validator.d.ts +19 -0
- package/dist/debugger/replay/replay-update-visibility-validator.js +19 -0
- package/dist/debugger/session/in-memory-replay-session-store.d.ts +27 -0
- package/dist/debugger/session/in-memory-replay-session-store.js +109 -0
- package/dist/debugger/session/replay-phase.d.ts +7 -0
- package/dist/debugger/session/replay-phase.js +8 -0
- package/dist/debugger/session/replay-scope.d.ts +10 -0
- package/dist/debugger/session/replay-scope.js +10 -0
- package/dist/debugger/session/replay-session-metadata.d.ts +10 -0
- package/dist/debugger/session/replay-session-metadata.js +10 -0
- package/dist/debugger/session/replay-session-request.d.ts +6 -0
- package/dist/debugger/session/replay-session-request.js +10 -0
- package/dist/debugger/session/replay-session.d.ts +12 -0
- package/dist/debugger/session/replay-session.js +10 -0
- package/dist/debugger/session/replay-source-location.d.ts +17 -0
- package/dist/debugger/session/replay-source-location.js +16 -0
- package/dist/debugger/session/replay-stack-frame.d.ts +8 -0
- package/dist/debugger/session/replay-stack-frame.js +8 -0
- package/dist/debugger/session/replay-state-delta.d.ts +29 -0
- package/dist/debugger/session/replay-state-delta.js +24 -0
- package/dist/debugger/session/replay-step-advance-result.d.ts +24 -0
- package/dist/debugger/session/replay-step-advance-result.js +16 -0
- package/dist/debugger/session/replay-step.d.ts +30 -0
- package/dist/debugger/session/replay-step.js +24 -0
- package/dist/debugger/session/replay-value-preview.d.ts +8 -0
- package/dist/debugger/session/replay-value-preview.js +15 -0
- package/dist/debugger/source/daml-source-mapper.d.ts +12 -0
- package/dist/debugger/source/daml-source-mapper.js +21 -0
- package/dist/debugger/source/dar-source-map-metadata.d.ts +26 -0
- package/dist/debugger/source/dar-source-map-metadata.js +10 -0
- package/dist/debugger/source/source-coverage-validator.d.ts +8 -0
- package/dist/debugger/source/source-coverage-validator.js +16 -0
- package/dist/debugger/source/source-indexed-compilation.d.ts +45 -0
- package/dist/debugger/source/source-indexed-compilation.js +110 -0
- package/dist/debugger/source/source-mapping-precision.d.ts +5 -0
- package/dist/debugger/source/source-mapping-precision.js +4 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +12 -0
- package/dist/query/cache/memory-query-cache.d.ts +9 -0
- package/dist/query/cache/memory-query-cache.js +24 -0
- package/dist/query/cache/query-cache-store.d.ts +5 -0
- package/dist/query/cache/query-cache-store.js +1 -0
- package/dist/query/canton-manager-options.d.ts +17 -0
- package/dist/query/canton-manager-options.js +1 -0
- package/dist/query/canton-manager.d.ts +11 -0
- package/dist/query/canton-manager.js +42 -0
- package/dist/query/errors/pqs-query-error.d.ts +10 -0
- package/dist/query/errors/pqs-query-error.js +11 -0
- package/dist/query/errors/pqs-schema-profile-error.d.ts +3 -0
- package/dist/query/errors/pqs-schema-profile-error.js +3 -0
- package/dist/query/errors/query-capability-error.d.ts +7 -0
- package/dist/query/errors/query-capability-error.js +10 -0
- package/dist/query/grpc/grpc-contract-query-client.d.ts +32 -0
- package/dist/query/grpc/grpc-contract-query-client.js +126 -0
- package/dist/query/model-types.d.ts +258 -0
- package/dist/query/model-types.js +14 -0
- package/dist/query/pqs/pqs-pool.d.ts +13 -0
- package/dist/query/pqs/pqs-pool.js +18 -0
- package/dist/query/pqs/pqs-query-client.d.ts +49 -0
- package/dist/query/pqs/pqs-query-client.js +324 -0
- package/dist/query/pqs/pqs-schema-profile.d.ts +25 -0
- package/dist/query/pqs/pqs-schema-profile.js +120 -0
- package/dist/query/pqs/pqs-sql-compiler.d.ts +7 -0
- package/dist/query/pqs/pqs-sql-compiler.js +132 -0
- package/dist/query/pqs/read-only-sql.d.ts +1 -0
- package/dist/query/pqs/read-only-sql.js +35 -0
- package/dist/query/query-client.d.ts +61 -0
- package/dist/query/query-client.js +1 -0
- package/dist/query/query-source.d.ts +4 -0
- package/dist/query/query-source.js +5 -0
- package/dist/services/commands/command-payload-builder.js +3 -3
- package/dist/services/commands/command-submission-pipeline.js +1 -7
- package/dist/services/party-management/decentralized-party-lifecycle.d.ts +6 -0
- package/dist/services/party-management/decentralized-party-lifecycle.js +82 -0
- package/dist/services/party-management/party-management-service-client.d.ts +16 -1
- package/dist/services/party-management/party-management-service-client.js +142 -1
- package/dist/services/topology-manager-write/topology-signed-transaction-assembler.js +4 -0
- package/dist/testing/campaign/campaign-artifact.d.ts +20 -0
- package/dist/testing/campaign/campaign-artifact.js +147 -0
- package/dist/testing/campaign/campaign-definition.d.ts +9 -0
- package/dist/testing/campaign/campaign-definition.js +78 -0
- package/dist/testing/campaign/campaign-metrics.d.ts +32 -0
- package/dist/testing/campaign/campaign-metrics.js +26 -0
- package/dist/testing/campaign/campaign-model.d.ts +11 -0
- package/dist/testing/campaign/campaign-model.js +21 -0
- package/dist/testing/campaign/campaign-runner.d.ts +99 -0
- package/dist/testing/campaign/campaign-runner.js +194 -0
- package/dist/testing/campaign/campaign-scheduler.d.ts +40 -0
- package/dist/testing/campaign/campaign-scheduler.js +75 -0
- package/dist/testing/campaign/campaign-types.d.ts +52 -0
- package/dist/testing/campaign/campaign-types.js +11 -0
- package/dist/testing/daml/daml-action-arbitrary.d.ts +13 -0
- package/dist/testing/daml/daml-action-arbitrary.js +24 -0
- package/dist/testing/daml/daml-choice-action-arbitrary.d.ts +18 -0
- package/dist/testing/daml/daml-choice-action-arbitrary.js +27 -0
- package/dist/testing/daml/daml-create-action-arbitrary.d.ts +19 -0
- package/dist/testing/daml/daml-create-action-arbitrary.js +34 -0
- package/dist/testing/daml/daml-testing-catalog.d.ts +38 -0
- package/dist/testing/daml/daml-testing-catalog.js +40 -0
- package/dist/testing/daml/daml-value-arbitrary.d.ts +8 -0
- package/dist/testing/daml/daml-value-arbitrary.js +43 -0
- package/dist/testing/daml/declarative-campaign-arbitrary.d.ts +15 -0
- package/dist/testing/daml/declarative-campaign-arbitrary.js +30 -0
- package/dist/testing/errors/invariant-campaign-failure.d.ts +24 -0
- package/dist/testing/errors/invariant-campaign-failure.js +37 -0
- package/dist/testing/errors/testing-configuration-error.d.ts +3 -0
- package/dist/testing/errors/testing-configuration-error.js +6 -0
- package/dist/testing/handlers/handler.d.ts +19 -0
- package/dist/testing/handlers/handler.js +31 -0
- package/dist/testing/index.d.ts +22 -0
- package/dist/testing/index.js +22 -0
- package/dist/testing/runtime/campaign-isolation.d.ts +14 -0
- package/dist/testing/runtime/campaign-isolation.js +23 -0
- package/dist/testing/runtime/canton-test-runtime.d.ts +58 -0
- package/dist/testing/runtime/canton-test-runtime.js +138 -0
- package/dist/testing/runtime/declarative-action-executor.d.ts +16 -0
- package/dist/testing/runtime/declarative-action-executor.js +41 -0
- package/dist/testing/targets/target.d.ts +49 -0
- package/dist/testing/targets/target.js +121 -0
- package/dist/transports/grpc/grpc-channel-factory.d.ts +4 -0
- package/dist/transports/grpc/grpc-channel-factory.js +42 -1
- package/dist/transports/grpc/grpc-transport.d.ts +2 -2
- package/dist/transports/grpc/grpc-transport.js +42 -3
- package/dist/transports/grpc/mappers/commands-mapper.d.ts +10 -2
- package/dist/transports/grpc/mappers/commands-mapper.js +30 -12
- package/dist/transports/grpc/mappers/contracts-mapper.d.ts +3 -1
- package/dist/transports/grpc/mappers/contracts-mapper.js +16 -3
- package/dist/transports/grpc/mappers/interactive-command-mapper.d.ts +15 -0
- package/dist/transports/grpc/mappers/interactive-command-mapper.js +54 -0
- package/dist/transports/grpc/mappers/topology-manager-write-mapper.js +59 -1
- package/dist/transports/json/json-transport.d.ts +2 -2
- package/dist/transports/json/json-transport.js +2 -2
- package/dist/transports/json/mappers/commands-mapper.js +23 -9
- package/node/.generated/start-local/additional-config.extra-participants.conf +37 -0
- package/node/.generated/start-local/additional-config.extra-validators.conf +35 -0
- package/node/.generated/start-local/compose-extra-participants.yaml +147 -0
- package/node/.generated/start-local/extra-participants.env +30 -0
- package/node/es256-jwt.mjs +177 -0
- package/node/start-local.sh +886 -0
- package/node/stop-local.sh +200 -0
- package/node/test-start-local.sh +354 -0
- package/node/test-stop-local.sh +112 -0
- package/package.json +21 -2
|
@@ -1,2 +1,935 @@
|
|
|
1
|
+
import { ValidationError } from "../../core/errors/validation-error.js";
|
|
2
|
+
import { DAML_LF_CONTRACT_ID_MARKER_KEY, DAML_LF_PARTY_MARKER_KEY, } from "./daml-lf-runtime-value.js";
|
|
1
3
|
export class DamlLfBuiltinDispatch {
|
|
4
|
+
applyOrThrow(builtin, argumentValues) {
|
|
5
|
+
const appliedArguments = [
|
|
6
|
+
...builtin.appliedArguments,
|
|
7
|
+
...argumentValues,
|
|
8
|
+
];
|
|
9
|
+
const nonUnitArguments = appliedArguments.filter((argument) => argument.kind !== "unit");
|
|
10
|
+
const numericArguments = appliedArguments.filter((argument) => this.isNumericCompatible(argument));
|
|
11
|
+
switch (builtin.builtinFunction) {
|
|
12
|
+
case "equal":
|
|
13
|
+
if (appliedArguments.length < 2) {
|
|
14
|
+
return {
|
|
15
|
+
kind: "builtin",
|
|
16
|
+
builtinFunction: builtin.builtinFunction,
|
|
17
|
+
appliedArguments,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
kind: "boolean",
|
|
22
|
+
value: this.areEqual(appliedArguments[0], appliedArguments[1]),
|
|
23
|
+
};
|
|
24
|
+
case "LESS":
|
|
25
|
+
if (nonUnitArguments.length < 2) {
|
|
26
|
+
return {
|
|
27
|
+
kind: "builtin",
|
|
28
|
+
builtinFunction: builtin.builtinFunction,
|
|
29
|
+
appliedArguments,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
kind: "boolean",
|
|
34
|
+
value: this.compareValues(nonUnitArguments[0], nonUnitArguments[1]) < 0,
|
|
35
|
+
};
|
|
36
|
+
case "LESS_EQ":
|
|
37
|
+
if (nonUnitArguments.length < 2) {
|
|
38
|
+
return {
|
|
39
|
+
kind: "builtin",
|
|
40
|
+
builtinFunction: builtin.builtinFunction,
|
|
41
|
+
appliedArguments,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
kind: "boolean",
|
|
46
|
+
value: this.compareValues(nonUnitArguments[0], nonUnitArguments[1]) <= 0,
|
|
47
|
+
};
|
|
48
|
+
case "ADD_INT64":
|
|
49
|
+
if (nonUnitArguments.length < 2) {
|
|
50
|
+
return {
|
|
51
|
+
kind: "builtin",
|
|
52
|
+
builtinFunction: builtin.builtinFunction,
|
|
53
|
+
appliedArguments,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
kind: "int64",
|
|
58
|
+
value: String(this.readInt64(nonUnitArguments[0])
|
|
59
|
+
+ this.readInt64(nonUnitArguments[1])),
|
|
60
|
+
};
|
|
61
|
+
case "SUB_INT64":
|
|
62
|
+
if (nonUnitArguments.length < 2) {
|
|
63
|
+
return {
|
|
64
|
+
kind: "builtin",
|
|
65
|
+
builtinFunction: builtin.builtinFunction,
|
|
66
|
+
appliedArguments,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
kind: "int64",
|
|
71
|
+
value: String(this.readInt64(nonUnitArguments[0])
|
|
72
|
+
- this.readInt64(nonUnitArguments[1])),
|
|
73
|
+
};
|
|
74
|
+
case "GREATER_EQ":
|
|
75
|
+
if (nonUnitArguments.length < 2) {
|
|
76
|
+
return {
|
|
77
|
+
kind: "builtin",
|
|
78
|
+
builtinFunction: builtin.builtinFunction,
|
|
79
|
+
appliedArguments,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
kind: "boolean",
|
|
84
|
+
value: this.compareValues(nonUnitArguments[0], nonUnitArguments[1]) >= 0,
|
|
85
|
+
};
|
|
86
|
+
case "greater":
|
|
87
|
+
case "GREATER":
|
|
88
|
+
if (nonUnitArguments.length < 2) {
|
|
89
|
+
return {
|
|
90
|
+
kind: "builtin",
|
|
91
|
+
builtinFunction: builtin.builtinFunction,
|
|
92
|
+
appliedArguments,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
kind: "boolean",
|
|
97
|
+
value: this.compareValues(nonUnitArguments[0], nonUnitArguments[1]) > 0,
|
|
98
|
+
};
|
|
99
|
+
case "ADD_NUMERIC":
|
|
100
|
+
if (numericArguments.length < 2) {
|
|
101
|
+
return {
|
|
102
|
+
kind: "builtin",
|
|
103
|
+
builtinFunction: builtin.builtinFunction,
|
|
104
|
+
appliedArguments,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const addNumericOperands = numericArguments.slice(-2);
|
|
108
|
+
return {
|
|
109
|
+
kind: "numeric",
|
|
110
|
+
value: this.formatExactDecimal(this.addExactDecimals(this.readExactDecimal(addNumericOperands[0]), this.readExactDecimal(addNumericOperands[1]))),
|
|
111
|
+
};
|
|
112
|
+
case "SUB_NUMERIC":
|
|
113
|
+
if (numericArguments.length < 2) {
|
|
114
|
+
return {
|
|
115
|
+
kind: "builtin",
|
|
116
|
+
builtinFunction: builtin.builtinFunction,
|
|
117
|
+
appliedArguments,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const subNumericOperands = numericArguments.slice(-2);
|
|
121
|
+
return {
|
|
122
|
+
kind: "numeric",
|
|
123
|
+
value: this.formatExactDecimal(this.subtractExactDecimals(this.readExactDecimal(subNumericOperands[0]), this.readExactDecimal(subNumericOperands[1]))),
|
|
124
|
+
};
|
|
125
|
+
case "MUL_NUMERIC":
|
|
126
|
+
if (numericArguments.length < 3) {
|
|
127
|
+
return {
|
|
128
|
+
kind: "builtin",
|
|
129
|
+
builtinFunction: builtin.builtinFunction,
|
|
130
|
+
appliedArguments,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
const mulNumericScale = this.readNumericScaleWitnessOrThrow(numericArguments[0]);
|
|
134
|
+
return {
|
|
135
|
+
kind: "numeric",
|
|
136
|
+
value: this.formatExactNumeric(this.quantizeExactDecimal(this.multiplyExactDecimals(this.readExactDecimal(numericArguments[1]), this.readExactDecimal(numericArguments[2])), mulNumericScale, "halfEven"), mulNumericScale),
|
|
137
|
+
};
|
|
138
|
+
case "DIV_NUMERIC":
|
|
139
|
+
if (numericArguments.length < 3) {
|
|
140
|
+
return {
|
|
141
|
+
kind: "builtin",
|
|
142
|
+
builtinFunction: builtin.builtinFunction,
|
|
143
|
+
appliedArguments,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const divNumericScale = this.readNumericScaleWitnessOrThrow(numericArguments[0]);
|
|
147
|
+
return {
|
|
148
|
+
kind: "numeric",
|
|
149
|
+
value: this.formatExactNumeric(this.divideExactDecimals(this.readExactDecimal(numericArguments[1]), this.readExactDecimal(numericArguments[2]), divNumericScale), divNumericScale),
|
|
150
|
+
};
|
|
151
|
+
case "INT64_TO_NUMERIC":
|
|
152
|
+
if (numericArguments.length < 2) {
|
|
153
|
+
return {
|
|
154
|
+
kind: "builtin",
|
|
155
|
+
builtinFunction: builtin.builtinFunction,
|
|
156
|
+
appliedArguments,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
const int64ToNumericScale = this.readNumericScaleWitnessOrThrow(numericArguments[0]);
|
|
160
|
+
return {
|
|
161
|
+
kind: "numeric",
|
|
162
|
+
value: this.formatExactNumeric(this.quantizeExactDecimal({
|
|
163
|
+
significand: this.readInt64(numericArguments[1]),
|
|
164
|
+
scale: 0,
|
|
165
|
+
}, int64ToNumericScale, "unnecessary"), int64ToNumericScale),
|
|
166
|
+
};
|
|
167
|
+
case "NUMERIC_TO_INT64":
|
|
168
|
+
if (numericArguments.length < 1) {
|
|
169
|
+
return {
|
|
170
|
+
kind: "builtin",
|
|
171
|
+
builtinFunction: builtin.builtinFunction,
|
|
172
|
+
appliedArguments,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
kind: "int64",
|
|
177
|
+
value: String(this.truncateExactDecimalToInt64(this.readExactDecimal(numericArguments.at(-1)))),
|
|
178
|
+
};
|
|
179
|
+
case "CAST_NUMERIC":
|
|
180
|
+
if (numericArguments.length < 2) {
|
|
181
|
+
return {
|
|
182
|
+
kind: "builtin",
|
|
183
|
+
builtinFunction: builtin.builtinFunction,
|
|
184
|
+
appliedArguments,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
const castNumericScale = this.readNumericScaleWitnessOrThrow(numericArguments[0]);
|
|
188
|
+
return {
|
|
189
|
+
kind: "numeric",
|
|
190
|
+
value: this.formatExactNumeric(this.quantizeExactDecimal(this.readExactDecimal(numericArguments[1]), castNumericScale, "unnecessary"), castNumericScale),
|
|
191
|
+
};
|
|
192
|
+
case "SHIFT_NUMERIC":
|
|
193
|
+
if (numericArguments.length < 2) {
|
|
194
|
+
return {
|
|
195
|
+
kind: "builtin",
|
|
196
|
+
builtinFunction: builtin.builtinFunction,
|
|
197
|
+
appliedArguments,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
const shiftNumericScale = this.readNumericScaleWitnessOrThrow(numericArguments[0]);
|
|
201
|
+
return {
|
|
202
|
+
kind: "numeric",
|
|
203
|
+
value: this.formatExactNumeric(this.shiftExactDecimal(this.readExactDecimal(numericArguments[1]), shiftNumericScale), shiftNumericScale),
|
|
204
|
+
};
|
|
205
|
+
case "ROUND_NUMERIC":
|
|
206
|
+
if (appliedArguments.length < 2) {
|
|
207
|
+
return {
|
|
208
|
+
kind: "builtin",
|
|
209
|
+
builtinFunction: builtin.builtinFunction,
|
|
210
|
+
appliedArguments,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const roundNumericScale = Number(this.readInt64(appliedArguments[0]));
|
|
214
|
+
return {
|
|
215
|
+
kind: "numeric",
|
|
216
|
+
value: this.formatExactDecimal(this.quantizeExactDecimal(this.readExactDecimal(appliedArguments[1]), roundNumericScale, "halfEven")),
|
|
217
|
+
};
|
|
218
|
+
case "INT64_TO_TEXT":
|
|
219
|
+
if (nonUnitArguments.length < 1) {
|
|
220
|
+
return {
|
|
221
|
+
kind: "builtin",
|
|
222
|
+
builtinFunction: builtin.builtinFunction,
|
|
223
|
+
appliedArguments,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
kind: "text",
|
|
228
|
+
value: String(this.readInt64(nonUnitArguments[0])),
|
|
229
|
+
};
|
|
230
|
+
case "PARTY_TO_TEXT":
|
|
231
|
+
if (nonUnitArguments.length < 1) {
|
|
232
|
+
return {
|
|
233
|
+
kind: "builtin",
|
|
234
|
+
builtinFunction: builtin.builtinFunction,
|
|
235
|
+
appliedArguments,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
kind: "text",
|
|
240
|
+
value: this.readPartyLike(nonUnitArguments[0]),
|
|
241
|
+
};
|
|
242
|
+
case "COERCE_CONTRACT_ID":
|
|
243
|
+
if (nonUnitArguments.length < 1) {
|
|
244
|
+
return {
|
|
245
|
+
kind: "builtin",
|
|
246
|
+
builtinFunction: builtin.builtinFunction,
|
|
247
|
+
appliedArguments,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
return {
|
|
251
|
+
kind: "contractId",
|
|
252
|
+
value: this.readContractIdLike(nonUnitArguments[0]),
|
|
253
|
+
};
|
|
254
|
+
case "TEXTMAP_EMPTY":
|
|
255
|
+
return {
|
|
256
|
+
kind: "ledgerValue",
|
|
257
|
+
value: {},
|
|
258
|
+
};
|
|
259
|
+
case "TEXTMAP_INSERT":
|
|
260
|
+
if (appliedArguments.length < 3) {
|
|
261
|
+
return {
|
|
262
|
+
kind: "builtin",
|
|
263
|
+
builtinFunction: builtin.builtinFunction,
|
|
264
|
+
appliedArguments,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
kind: "ledgerValue",
|
|
269
|
+
value: {
|
|
270
|
+
...this.readTextMap(appliedArguments[2]),
|
|
271
|
+
[this.readText(appliedArguments[0])]: this.unwrapValue(appliedArguments[1]),
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
case "TEXTMAP_LOOKUP":
|
|
275
|
+
if (appliedArguments.length < 2) {
|
|
276
|
+
return {
|
|
277
|
+
kind: "builtin",
|
|
278
|
+
builtinFunction: builtin.builtinFunction,
|
|
279
|
+
appliedArguments,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
const textMapLookupValue = this.readTextMap(appliedArguments[1])[this.readText(appliedArguments[0])];
|
|
283
|
+
return textMapLookupValue === undefined
|
|
284
|
+
? {
|
|
285
|
+
kind: "unit",
|
|
286
|
+
}
|
|
287
|
+
: this.hydrateValue(textMapLookupValue);
|
|
288
|
+
case "TEXTMAP_DELETE":
|
|
289
|
+
if (appliedArguments.length < 2) {
|
|
290
|
+
return {
|
|
291
|
+
kind: "builtin",
|
|
292
|
+
builtinFunction: builtin.builtinFunction,
|
|
293
|
+
appliedArguments,
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
const textMapAfterDelete = {
|
|
297
|
+
...this.readTextMap(appliedArguments[1]),
|
|
298
|
+
};
|
|
299
|
+
delete textMapAfterDelete[this.readText(appliedArguments[0])];
|
|
300
|
+
return {
|
|
301
|
+
kind: "ledgerValue",
|
|
302
|
+
value: textMapAfterDelete,
|
|
303
|
+
};
|
|
304
|
+
case "TEXTMAP_TO_LIST":
|
|
305
|
+
if (appliedArguments.length < 1) {
|
|
306
|
+
return {
|
|
307
|
+
kind: "builtin",
|
|
308
|
+
builtinFunction: builtin.builtinFunction,
|
|
309
|
+
appliedArguments,
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
return {
|
|
313
|
+
kind: "ledgerValue",
|
|
314
|
+
value: Object.entries(this.readTextMap(appliedArguments[0])).map(([key, value]) => ({
|
|
315
|
+
"0": key,
|
|
316
|
+
"1": value,
|
|
317
|
+
})),
|
|
318
|
+
};
|
|
319
|
+
case "TEXTMAP_SIZE":
|
|
320
|
+
if (appliedArguments.length < 1) {
|
|
321
|
+
return {
|
|
322
|
+
kind: "builtin",
|
|
323
|
+
builtinFunction: builtin.builtinFunction,
|
|
324
|
+
appliedArguments,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
return {
|
|
328
|
+
kind: "int64",
|
|
329
|
+
value: String(Object.keys(this.readTextMap(appliedArguments[0])).length),
|
|
330
|
+
};
|
|
331
|
+
case "GENMAP_EMPTY":
|
|
332
|
+
return {
|
|
333
|
+
kind: "ledgerValue",
|
|
334
|
+
value: [],
|
|
335
|
+
};
|
|
336
|
+
case "GENMAP_INSERT":
|
|
337
|
+
if (appliedArguments.length < 3) {
|
|
338
|
+
return {
|
|
339
|
+
kind: "builtin",
|
|
340
|
+
builtinFunction: builtin.builtinFunction,
|
|
341
|
+
appliedArguments,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
return {
|
|
345
|
+
kind: "ledgerValue",
|
|
346
|
+
value: this.insertGenMapEntry(this.readGenMap(appliedArguments[2]), appliedArguments[0], appliedArguments[1]),
|
|
347
|
+
};
|
|
348
|
+
case "GENMAP_LOOKUP":
|
|
349
|
+
if (appliedArguments.length < 2) {
|
|
350
|
+
return {
|
|
351
|
+
kind: "builtin",
|
|
352
|
+
builtinFunction: builtin.builtinFunction,
|
|
353
|
+
appliedArguments,
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
const matchingGenMapEntry = this.readGenMap(appliedArguments[1]).find((entry) => this.areEqual(this.hydrateValue(entry.key), appliedArguments[0]));
|
|
357
|
+
return matchingGenMapEntry === undefined
|
|
358
|
+
? {
|
|
359
|
+
kind: "unit",
|
|
360
|
+
}
|
|
361
|
+
: this.hydrateValue(matchingGenMapEntry.value);
|
|
362
|
+
case "GENMAP_DELETE":
|
|
363
|
+
if (appliedArguments.length < 2) {
|
|
364
|
+
return {
|
|
365
|
+
kind: "builtin",
|
|
366
|
+
builtinFunction: builtin.builtinFunction,
|
|
367
|
+
appliedArguments,
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
return {
|
|
371
|
+
kind: "ledgerValue",
|
|
372
|
+
value: this.readGenMap(appliedArguments[1]).filter((entry) => !this.areEqual(this.hydrateValue(entry.key), appliedArguments[0])),
|
|
373
|
+
};
|
|
374
|
+
case "GENMAP_KEYS":
|
|
375
|
+
if (appliedArguments.length < 1) {
|
|
376
|
+
return {
|
|
377
|
+
kind: "builtin",
|
|
378
|
+
builtinFunction: builtin.builtinFunction,
|
|
379
|
+
appliedArguments,
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
return {
|
|
383
|
+
kind: "ledgerValue",
|
|
384
|
+
value: this.readGenMap(appliedArguments[0]).map((entry) => entry.key),
|
|
385
|
+
};
|
|
386
|
+
case "GENMAP_VALUES":
|
|
387
|
+
if (appliedArguments.length < 1) {
|
|
388
|
+
return {
|
|
389
|
+
kind: "builtin",
|
|
390
|
+
builtinFunction: builtin.builtinFunction,
|
|
391
|
+
appliedArguments,
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
return {
|
|
395
|
+
kind: "ledgerValue",
|
|
396
|
+
value: this.readGenMap(appliedArguments[0]).map((entry) => entry.value),
|
|
397
|
+
};
|
|
398
|
+
case "GENMAP_SIZE":
|
|
399
|
+
if (appliedArguments.length < 1) {
|
|
400
|
+
return {
|
|
401
|
+
kind: "builtin",
|
|
402
|
+
builtinFunction: builtin.builtinFunction,
|
|
403
|
+
appliedArguments,
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
return {
|
|
407
|
+
kind: "int64",
|
|
408
|
+
value: String(this.readGenMap(appliedArguments[0]).length),
|
|
409
|
+
};
|
|
410
|
+
case "appendText":
|
|
411
|
+
if (appliedArguments.length < 2) {
|
|
412
|
+
return {
|
|
413
|
+
kind: "builtin",
|
|
414
|
+
builtinFunction: builtin.builtinFunction,
|
|
415
|
+
appliedArguments,
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
return {
|
|
419
|
+
kind: "text",
|
|
420
|
+
value: this.readText(appliedArguments[0])
|
|
421
|
+
+ this.readText(appliedArguments[1]),
|
|
422
|
+
};
|
|
423
|
+
case "EXPLODE_TEXT":
|
|
424
|
+
if (nonUnitArguments.length < 1) {
|
|
425
|
+
return {
|
|
426
|
+
kind: "builtin",
|
|
427
|
+
builtinFunction: builtin.builtinFunction,
|
|
428
|
+
appliedArguments,
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
return {
|
|
432
|
+
kind: "ledgerValue",
|
|
433
|
+
value: [...this.readText(nonUnitArguments.at(-1))],
|
|
434
|
+
};
|
|
435
|
+
case "IMPLODE_TEXT":
|
|
436
|
+
if (nonUnitArguments.length < 1) {
|
|
437
|
+
return {
|
|
438
|
+
kind: "builtin",
|
|
439
|
+
builtinFunction: builtin.builtinFunction,
|
|
440
|
+
appliedArguments,
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
return {
|
|
444
|
+
kind: "text",
|
|
445
|
+
value: this.readTextList(nonUnitArguments.at(-1)).join(""),
|
|
446
|
+
};
|
|
447
|
+
case "NUMERIC_TO_TEXT":
|
|
448
|
+
if (appliedArguments.length < 1) {
|
|
449
|
+
return {
|
|
450
|
+
kind: "builtin",
|
|
451
|
+
builtinFunction: builtin.builtinFunction,
|
|
452
|
+
appliedArguments,
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
const numericArgument = numericArguments.at(-1);
|
|
456
|
+
if (numericArgument === undefined) {
|
|
457
|
+
return {
|
|
458
|
+
kind: "builtin",
|
|
459
|
+
builtinFunction: builtin.builtinFunction,
|
|
460
|
+
appliedArguments,
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
return {
|
|
464
|
+
kind: "text",
|
|
465
|
+
value: this.readTextLike(numericArgument),
|
|
466
|
+
};
|
|
467
|
+
default:
|
|
468
|
+
throw new ValidationError(`daml lf builtin '${builtin.builtinFunction}' is not supported yet`);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
areEqual(left, right) {
|
|
472
|
+
const leftString = this.readStringLikeOrUndefined(left);
|
|
473
|
+
const rightString = this.readStringLikeOrUndefined(right);
|
|
474
|
+
if (leftString !== undefined && rightString !== undefined) {
|
|
475
|
+
return leftString === rightString;
|
|
476
|
+
}
|
|
477
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
478
|
+
}
|
|
479
|
+
readInt64(value) {
|
|
480
|
+
if (value.kind === "int64") {
|
|
481
|
+
return BigInt(value.value);
|
|
482
|
+
}
|
|
483
|
+
if (value.kind === "text") {
|
|
484
|
+
return BigInt(value.value);
|
|
485
|
+
}
|
|
486
|
+
if (value.kind === "ledgerValue"
|
|
487
|
+
&& "value" in value
|
|
488
|
+
&& (typeof value.value === "string"
|
|
489
|
+
|| typeof value.value === "number"
|
|
490
|
+
|| typeof value.value === "bigint")) {
|
|
491
|
+
return BigInt(value.value);
|
|
492
|
+
}
|
|
493
|
+
throw new ValidationError(`daml lf builtin expected int64, got '${value.kind}'`);
|
|
494
|
+
}
|
|
495
|
+
compareValues(left, right) {
|
|
496
|
+
const leftDecimal = this.tryReadExactDecimal(left);
|
|
497
|
+
const rightDecimal = this.tryReadExactDecimal(right);
|
|
498
|
+
if (leftDecimal !== undefined && rightDecimal !== undefined) {
|
|
499
|
+
return this.compareExactDecimals(leftDecimal, rightDecimal);
|
|
500
|
+
}
|
|
501
|
+
const leftString = this.readTextLike(left);
|
|
502
|
+
const rightString = this.readTextLike(right);
|
|
503
|
+
if (leftString < rightString) {
|
|
504
|
+
return -1;
|
|
505
|
+
}
|
|
506
|
+
if (leftString > rightString) {
|
|
507
|
+
return 1;
|
|
508
|
+
}
|
|
509
|
+
return 0;
|
|
510
|
+
}
|
|
511
|
+
readText(value) {
|
|
512
|
+
if (value.kind !== "text") {
|
|
513
|
+
throw new ValidationError(`daml lf builtin expected text, got '${value.kind}'`);
|
|
514
|
+
}
|
|
515
|
+
return value.value;
|
|
516
|
+
}
|
|
517
|
+
readPartyLike(value) {
|
|
518
|
+
if (value.kind === "party" || value.kind === "text") {
|
|
519
|
+
return value.value;
|
|
520
|
+
}
|
|
521
|
+
if (value.kind === "ledgerValue"
|
|
522
|
+
&& "value" in value
|
|
523
|
+
&& typeof value.value === "string") {
|
|
524
|
+
return value.value;
|
|
525
|
+
}
|
|
526
|
+
throw new ValidationError(`daml lf builtin expected party, got '${value.kind}'`);
|
|
527
|
+
}
|
|
528
|
+
readTextLike(value) {
|
|
529
|
+
if (value.kind === "text"
|
|
530
|
+
|| value.kind === "numeric"
|
|
531
|
+
|| value.kind === "int64") {
|
|
532
|
+
return String(value.value);
|
|
533
|
+
}
|
|
534
|
+
if (value.kind === "ledgerValue"
|
|
535
|
+
&& "value" in value
|
|
536
|
+
&& (typeof value.value === "string"
|
|
537
|
+
|| typeof value.value === "number"
|
|
538
|
+
|| typeof value.value === "bigint")) {
|
|
539
|
+
return String(value.value);
|
|
540
|
+
}
|
|
541
|
+
throw new ValidationError(`daml lf builtin expected a text-compatible value, got '${value.kind}'`);
|
|
542
|
+
}
|
|
543
|
+
readStringLikeOrUndefined(value) {
|
|
544
|
+
if (value.kind === "text"
|
|
545
|
+
|| value.kind === "numeric"
|
|
546
|
+
|| value.kind === "party"
|
|
547
|
+
|| value.kind === "int64") {
|
|
548
|
+
return String(value.value);
|
|
549
|
+
}
|
|
550
|
+
if (value.kind === "ledgerValue"
|
|
551
|
+
&& "value" in value
|
|
552
|
+
&& typeof value.value === "string") {
|
|
553
|
+
return value.value;
|
|
554
|
+
}
|
|
555
|
+
return undefined;
|
|
556
|
+
}
|
|
557
|
+
readContractIdLike(value) {
|
|
558
|
+
if (value.kind === "contractId"
|
|
559
|
+
|| value.kind === "text") {
|
|
560
|
+
return String(value.value);
|
|
561
|
+
}
|
|
562
|
+
if (value.kind === "ledgerValue"
|
|
563
|
+
&& "contractId" in value
|
|
564
|
+
&& typeof value.contractId === "string") {
|
|
565
|
+
return value.contractId;
|
|
566
|
+
}
|
|
567
|
+
if (value.kind === "ledgerValue"
|
|
568
|
+
&& "value" in value
|
|
569
|
+
&& value.value !== null
|
|
570
|
+
&& typeof value.value === "object"
|
|
571
|
+
&& DAML_LF_CONTRACT_ID_MARKER_KEY in value.value
|
|
572
|
+
&& typeof value.value[DAML_LF_CONTRACT_ID_MARKER_KEY] === "string") {
|
|
573
|
+
return value.value[DAML_LF_CONTRACT_ID_MARKER_KEY];
|
|
574
|
+
}
|
|
575
|
+
throw new ValidationError(`daml lf builtin expected contract id, got '${value.kind}'`);
|
|
576
|
+
}
|
|
577
|
+
readExactDecimal(value) {
|
|
578
|
+
if (value.kind === "numeric") {
|
|
579
|
+
return this.parseExactDecimal(value.value);
|
|
580
|
+
}
|
|
581
|
+
return this.parseExactDecimal(this.readTextLike(value));
|
|
582
|
+
}
|
|
583
|
+
tryReadExactDecimal(value) {
|
|
584
|
+
try {
|
|
585
|
+
return this.readExactDecimal(value);
|
|
586
|
+
}
|
|
587
|
+
catch {
|
|
588
|
+
return undefined;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
parseExactDecimal(value) {
|
|
592
|
+
const trimmed = value.trim();
|
|
593
|
+
if (!/^-?\d+(?:\.\d+)?$/.test(trimmed)) {
|
|
594
|
+
throw new ValidationError(`daml lf builtin expected an exact decimal-compatible value, got '${value}'`);
|
|
595
|
+
}
|
|
596
|
+
const negative = trimmed.startsWith("-");
|
|
597
|
+
const unsigned = negative ? trimmed.slice(1) : trimmed;
|
|
598
|
+
const [integerPart, fractionalPart = ""] = unsigned.split(".");
|
|
599
|
+
const normalizedInteger = integerPart.replace(/^0+(?=\d)/, "") || "0";
|
|
600
|
+
const normalizedFraction = fractionalPart.replace(/0+$/, "");
|
|
601
|
+
const scale = normalizedFraction.length;
|
|
602
|
+
const digits = `${normalizedInteger}${normalizedFraction}`.replace(/^0+(?=\d)/, "") || "0";
|
|
603
|
+
const significand = BigInt(negative ? `-${digits}` : digits);
|
|
604
|
+
return {
|
|
605
|
+
significand,
|
|
606
|
+
scale,
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
addExactDecimals(left, right) {
|
|
610
|
+
const scale = Math.max(left.scale, right.scale);
|
|
611
|
+
return this.normalizeExactDecimal({
|
|
612
|
+
significand: left.significand * this.pow10(scale - left.scale)
|
|
613
|
+
+ right.significand * this.pow10(scale - right.scale),
|
|
614
|
+
scale,
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
subtractExactDecimals(left, right) {
|
|
618
|
+
const scale = Math.max(left.scale, right.scale);
|
|
619
|
+
return this.normalizeExactDecimal({
|
|
620
|
+
significand: left.significand * this.pow10(scale - left.scale)
|
|
621
|
+
- right.significand * this.pow10(scale - right.scale),
|
|
622
|
+
scale,
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
multiplyExactDecimals(left, right) {
|
|
626
|
+
return this.normalizeExactDecimal({
|
|
627
|
+
significand: left.significand * right.significand,
|
|
628
|
+
scale: left.scale + right.scale,
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
divideExactDecimals(left, right, targetScale) {
|
|
632
|
+
if (right.significand === 0n) {
|
|
633
|
+
throw new ValidationError("daml lf builtin DIV_NUMERIC cannot divide by zero");
|
|
634
|
+
}
|
|
635
|
+
const exponent = targetScale + right.scale - left.scale;
|
|
636
|
+
const scaleFactor = this.pow10(Math.max(exponent, 0));
|
|
637
|
+
const dividend = exponent >= 0
|
|
638
|
+
? left.significand * scaleFactor
|
|
639
|
+
: left.significand;
|
|
640
|
+
const divisor = exponent >= 0
|
|
641
|
+
? right.significand
|
|
642
|
+
: right.significand * this.pow10(-exponent);
|
|
643
|
+
return this.assertNumericBoundsOrThrow(this.quantizeQuotientToScale(dividend, divisor, targetScale, "halfEven"), targetScale);
|
|
644
|
+
}
|
|
645
|
+
compareExactDecimals(left, right) {
|
|
646
|
+
const scale = Math.max(left.scale, right.scale);
|
|
647
|
+
const leftValue = left.significand * this.pow10(scale - left.scale);
|
|
648
|
+
const rightValue = right.significand * this.pow10(scale - right.scale);
|
|
649
|
+
if (leftValue < rightValue) {
|
|
650
|
+
return -1;
|
|
651
|
+
}
|
|
652
|
+
if (leftValue > rightValue) {
|
|
653
|
+
return 1;
|
|
654
|
+
}
|
|
655
|
+
return 0;
|
|
656
|
+
}
|
|
657
|
+
normalizeExactDecimal(value) {
|
|
658
|
+
let significand = value.significand;
|
|
659
|
+
let scale = value.scale;
|
|
660
|
+
while (scale > 0 && significand % 10n === 0n) {
|
|
661
|
+
significand /= 10n;
|
|
662
|
+
scale -= 1;
|
|
663
|
+
}
|
|
664
|
+
return {
|
|
665
|
+
significand,
|
|
666
|
+
scale,
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
quantizeExactDecimal(value, targetScale, roundingMode) {
|
|
670
|
+
if (targetScale >= value.scale) {
|
|
671
|
+
const scaledValue = this.normalizeExactDecimal({
|
|
672
|
+
significand: value.significand * this.pow10(targetScale - value.scale),
|
|
673
|
+
scale: targetScale,
|
|
674
|
+
});
|
|
675
|
+
return this.assertNumericBoundsOrThrow(scaledValue, targetScale);
|
|
676
|
+
}
|
|
677
|
+
const delta = value.scale - targetScale;
|
|
678
|
+
const divisor = this.pow10(delta);
|
|
679
|
+
const truncated = value.significand / divisor;
|
|
680
|
+
const remainder = value.significand % divisor;
|
|
681
|
+
if (remainder === 0n) {
|
|
682
|
+
return this.assertNumericBoundsOrThrow(this.createExactDecimalFromScaledSignificand(truncated, targetScale), targetScale);
|
|
683
|
+
}
|
|
684
|
+
if (roundingMode === "unnecessary") {
|
|
685
|
+
throw new ValidationError("daml lf builtin CAST_NUMERIC requires an exact representation");
|
|
686
|
+
}
|
|
687
|
+
const rounded = this.roundHalfEvenQuotient(truncated, remainder, divisor);
|
|
688
|
+
return this.assertNumericBoundsOrThrow(this.createExactDecimalFromScaledSignificand(rounded, targetScale), targetScale);
|
|
689
|
+
}
|
|
690
|
+
shiftExactDecimal(value, targetScale) {
|
|
691
|
+
return this.assertNumericBoundsOrThrow(this.normalizeExactDecimal({
|
|
692
|
+
significand: value.significand,
|
|
693
|
+
scale: targetScale,
|
|
694
|
+
}), targetScale);
|
|
695
|
+
}
|
|
696
|
+
quantizeQuotientToScale(dividend, divisor, targetScale, roundingMode) {
|
|
697
|
+
const quotient = dividend / divisor;
|
|
698
|
+
const remainder = dividend % divisor;
|
|
699
|
+
if (remainder === 0n) {
|
|
700
|
+
return this.createExactDecimalFromScaledSignificand(quotient, targetScale);
|
|
701
|
+
}
|
|
702
|
+
if (roundingMode === "unnecessary") {
|
|
703
|
+
throw new ValidationError("daml lf builtin DIV_NUMERIC requires an exact representation");
|
|
704
|
+
}
|
|
705
|
+
return this.createExactDecimalFromScaledSignificand(this.roundHalfEvenQuotient(quotient, remainder, divisor), targetScale);
|
|
706
|
+
}
|
|
707
|
+
roundHalfEvenQuotient(quotient, remainder, divisor) {
|
|
708
|
+
const absoluteRemainder = remainder < 0n ? -remainder : remainder;
|
|
709
|
+
const absoluteDivisor = divisor < 0n ? -divisor : divisor;
|
|
710
|
+
const doubledRemainder = absoluteRemainder * 2n;
|
|
711
|
+
if (doubledRemainder < absoluteDivisor) {
|
|
712
|
+
return quotient;
|
|
713
|
+
}
|
|
714
|
+
const shouldRoundAwayFromZero = doubledRemainder > absoluteDivisor
|
|
715
|
+
|| quotient % 2n !== 0n;
|
|
716
|
+
if (!shouldRoundAwayFromZero) {
|
|
717
|
+
return quotient;
|
|
718
|
+
}
|
|
719
|
+
const direction = quotient !== 0n
|
|
720
|
+
? (quotient < 0n ? -1n : 1n)
|
|
721
|
+
: ((remainder < 0n) !== (divisor < 0n)
|
|
722
|
+
? -1n
|
|
723
|
+
: 1n);
|
|
724
|
+
return quotient + direction;
|
|
725
|
+
}
|
|
726
|
+
createExactDecimalFromScaledSignificand(significand, scale) {
|
|
727
|
+
if (scale >= 0) {
|
|
728
|
+
return this.normalizeExactDecimal({
|
|
729
|
+
significand,
|
|
730
|
+
scale,
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
return this.normalizeExactDecimal({
|
|
734
|
+
significand: significand * this.pow10(-scale),
|
|
735
|
+
scale: 0,
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
formatExactDecimal(value) {
|
|
739
|
+
const normalized = this.normalizeExactDecimal(value);
|
|
740
|
+
const negative = normalized.significand < 0n;
|
|
741
|
+
const digits = (negative
|
|
742
|
+
? -normalized.significand
|
|
743
|
+
: normalized.significand).toString();
|
|
744
|
+
if (normalized.scale === 0) {
|
|
745
|
+
return `${negative ? "-" : ""}${digits}`;
|
|
746
|
+
}
|
|
747
|
+
const paddedDigits = digits.padStart(normalized.scale + 1, "0");
|
|
748
|
+
const splitIndex = paddedDigits.length - normalized.scale;
|
|
749
|
+
const integerPart = paddedDigits.slice(0, splitIndex);
|
|
750
|
+
const fractionalPart = paddedDigits.slice(splitIndex);
|
|
751
|
+
return `${negative ? "-" : ""}${integerPart}.${fractionalPart}`;
|
|
752
|
+
}
|
|
753
|
+
formatExactNumeric(value, _targetScale) {
|
|
754
|
+
return this.formatExactDecimal(value);
|
|
755
|
+
}
|
|
756
|
+
truncateExactDecimalToInt64(value) {
|
|
757
|
+
if (value.scale === 0) {
|
|
758
|
+
return value.significand;
|
|
759
|
+
}
|
|
760
|
+
return value.significand / this.pow10(value.scale);
|
|
761
|
+
}
|
|
762
|
+
readNumericScaleWitnessOrThrow(value) {
|
|
763
|
+
const text = this.readTextLike(value).trim();
|
|
764
|
+
const match = /^-?\d+(?:\.(\d+))?$/.exec(text);
|
|
765
|
+
if (match === null) {
|
|
766
|
+
throw new ValidationError(`daml lf builtin expected a numeric scale witness, got '${text}'`);
|
|
767
|
+
}
|
|
768
|
+
return match[1]?.length ?? 0;
|
|
769
|
+
}
|
|
770
|
+
assertNumericBoundsOrThrow(value, targetScale) {
|
|
771
|
+
const normalized = this.normalizeExactDecimal(value);
|
|
772
|
+
const scaledSignificand = targetScale !== undefined
|
|
773
|
+
&& targetScale >= 0
|
|
774
|
+
&& targetScale >= normalized.scale
|
|
775
|
+
? normalized.significand * this.pow10(targetScale - normalized.scale)
|
|
776
|
+
: normalized.significand;
|
|
777
|
+
const digits = (scaledSignificand < 0n
|
|
778
|
+
? -scaledSignificand
|
|
779
|
+
: scaledSignificand).toString().length;
|
|
780
|
+
if (digits > 38) {
|
|
781
|
+
throw new ValidationError("daml lf numeric overflow");
|
|
782
|
+
}
|
|
783
|
+
return normalized;
|
|
784
|
+
}
|
|
785
|
+
pow10(exponent) {
|
|
786
|
+
return 10n ** BigInt(exponent);
|
|
787
|
+
}
|
|
788
|
+
readTextList(value) {
|
|
789
|
+
if (value.kind === "ledgerValue"
|
|
790
|
+
&& "value" in value
|
|
791
|
+
&& Array.isArray(value.value)) {
|
|
792
|
+
return value.value.map((item) => {
|
|
793
|
+
if (typeof item !== "string") {
|
|
794
|
+
throw new ValidationError("daml lf builtin expected a text list");
|
|
795
|
+
}
|
|
796
|
+
return item;
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
throw new ValidationError(`daml lf builtin expected a text-list-compatible value, got '${value.kind}'`);
|
|
800
|
+
}
|
|
801
|
+
readTextMap(value) {
|
|
802
|
+
if (value.kind === "builtin"
|
|
803
|
+
&& "builtinFunction" in value
|
|
804
|
+
&& value.builtinFunction === "TEXTMAP_EMPTY") {
|
|
805
|
+
const builtinValue = value;
|
|
806
|
+
if (builtinValue.appliedArguments.length === 0) {
|
|
807
|
+
return {};
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
if (value.kind === "ledgerValue"
|
|
811
|
+
&& "value" in value
|
|
812
|
+
&& value.value !== null
|
|
813
|
+
&& typeof value.value === "object"
|
|
814
|
+
&& !Array.isArray(value.value)) {
|
|
815
|
+
return value.value;
|
|
816
|
+
}
|
|
817
|
+
throw new ValidationError(`daml lf builtin expected a text-map-compatible value, got '${value.kind}'`);
|
|
818
|
+
}
|
|
819
|
+
readGenMap(value) {
|
|
820
|
+
if (value.kind === "builtin"
|
|
821
|
+
&& "builtinFunction" in value
|
|
822
|
+
&& value.builtinFunction === "GENMAP_EMPTY") {
|
|
823
|
+
const builtinValue = value;
|
|
824
|
+
if (builtinValue.appliedArguments.length === 0) {
|
|
825
|
+
return [];
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
if (value.kind === "ledgerValue"
|
|
829
|
+
&& "value" in value
|
|
830
|
+
&& Array.isArray(value.value)) {
|
|
831
|
+
return value.value.map((entry) => {
|
|
832
|
+
if (entry === null
|
|
833
|
+
|| typeof entry !== "object"
|
|
834
|
+
|| !("key" in entry)
|
|
835
|
+
|| !("value" in entry)) {
|
|
836
|
+
throw new ValidationError("daml lf builtin expected a gen-map entry");
|
|
837
|
+
}
|
|
838
|
+
return entry;
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
throw new ValidationError(`daml lf builtin expected a gen-map-compatible value, got '${value.kind}'`);
|
|
842
|
+
}
|
|
843
|
+
unwrapValue(value) {
|
|
844
|
+
if (value.kind === "record" && "fields" in value) {
|
|
845
|
+
const recordFields = value.fields;
|
|
846
|
+
return Object.fromEntries(Object.entries(recordFields).map(([fieldName, fieldValue]) => [
|
|
847
|
+
fieldName,
|
|
848
|
+
this.unwrapValue(fieldValue),
|
|
849
|
+
]));
|
|
850
|
+
}
|
|
851
|
+
if (value.kind === "contractId") {
|
|
852
|
+
return {
|
|
853
|
+
[DAML_LF_CONTRACT_ID_MARKER_KEY]: value.value,
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
if (value.kind === "party") {
|
|
857
|
+
return {
|
|
858
|
+
[DAML_LF_PARTY_MARKER_KEY]: value.value,
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
if (value.kind === "unit") {
|
|
862
|
+
return null;
|
|
863
|
+
}
|
|
864
|
+
if ("value" in value) {
|
|
865
|
+
return value.value;
|
|
866
|
+
}
|
|
867
|
+
return value;
|
|
868
|
+
}
|
|
869
|
+
hydrateValue(value) {
|
|
870
|
+
if (value === null || value === undefined) {
|
|
871
|
+
return {
|
|
872
|
+
kind: "unit",
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
if (typeof value === "string") {
|
|
876
|
+
return {
|
|
877
|
+
kind: "text",
|
|
878
|
+
value,
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
if (typeof value === "boolean") {
|
|
882
|
+
return {
|
|
883
|
+
kind: "boolean",
|
|
884
|
+
value,
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
if (typeof value === "number" || typeof value === "bigint") {
|
|
888
|
+
return {
|
|
889
|
+
kind: "text",
|
|
890
|
+
value: String(value),
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
if (typeof value === "object"
|
|
894
|
+
&& value !== null
|
|
895
|
+
&& DAML_LF_CONTRACT_ID_MARKER_KEY in value
|
|
896
|
+
&& typeof value[DAML_LF_CONTRACT_ID_MARKER_KEY] === "string") {
|
|
897
|
+
return {
|
|
898
|
+
kind: "contractId",
|
|
899
|
+
value: value[DAML_LF_CONTRACT_ID_MARKER_KEY],
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
if (typeof value === "object"
|
|
903
|
+
&& value !== null
|
|
904
|
+
&& DAML_LF_PARTY_MARKER_KEY in value
|
|
905
|
+
&& typeof value[DAML_LF_PARTY_MARKER_KEY] === "string") {
|
|
906
|
+
return {
|
|
907
|
+
kind: "party",
|
|
908
|
+
value: value[DAML_LF_PARTY_MARKER_KEY],
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
return {
|
|
912
|
+
kind: "ledgerValue",
|
|
913
|
+
value,
|
|
914
|
+
};
|
|
915
|
+
}
|
|
916
|
+
insertGenMapEntry(entries, key, value) {
|
|
917
|
+
const unwrappedKey = this.unwrapValue(key);
|
|
918
|
+
const nextEntry = {
|
|
919
|
+
key: unwrappedKey,
|
|
920
|
+
value: this.unwrapValue(value),
|
|
921
|
+
};
|
|
922
|
+
const retainedEntries = entries.filter((entry) => !this.areEqual(this.hydrateValue(entry.key), key));
|
|
923
|
+
return [...retainedEntries, nextEntry];
|
|
924
|
+
}
|
|
925
|
+
isNumericCompatible(value) {
|
|
926
|
+
return (value.kind === "int64"
|
|
927
|
+
|| value.kind === "numeric"
|
|
928
|
+
|| value.kind === "text"
|
|
929
|
+
|| (value.kind === "ledgerValue"
|
|
930
|
+
&& "value" in value
|
|
931
|
+
&& (typeof value.value === "string"
|
|
932
|
+
|| typeof value.value === "number"
|
|
933
|
+
|| typeof value.value === "bigint")));
|
|
934
|
+
}
|
|
2
935
|
}
|