@canton-network/core-token-standard-service 2.3.0 → 2.4.0
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-service.d.ts +0 -1
- package/dist/core-service.d.ts.map +1 -1
- package/dist/index.cjs +15 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +16 -17
- package/dist/index.js.map +1 -1
- package/dist/v2/allocation-service.d.ts +2 -0
- package/dist/v2/allocation-service.d.ts.map +1 -1
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ALLOCATION_FACTORY_INTERFACE_ID, ALLOCATION_INSTRUCTION_INTERFACE_ID, A
|
|
|
2
2
|
import { EventFilterBySetup } from "@canton-network/core-ledger-client-types";
|
|
3
3
|
import { TokenStandardTransactionInterfaces, TransactionParser, ensureInterfaceViewIsPresent, renderTransaction } from "@canton-network/core-tx-parser";
|
|
4
4
|
import Decimal$1, { Decimal } from "decimal.js";
|
|
5
|
-
import { ALLOCATION_FACTORY_INTERFACE_ID_V2, ALLOCATION_INSTRUCTION_INTERFACE_ID_V2, ALLOCATION_INTERFACE_ID_V2, ALLOCATION_REQUEST_INTERFACE_ID_V2, AllocationInstruction, HOLDING_INTERFACE_ID_V2, TRANSFER_FACTORY_INTERFACE_ID_V2, TRANSFER_INSTRUCTION_INTERFACE_ID_V2, TokenStandardClient as TokenStandardClient$1, TransferInstruction as TransferInstruction$1 } from "@canton-network/core-token-standard-v2";
|
|
5
|
+
import { ALLOCATION_FACTORY_INTERFACE_ID_V2, ALLOCATION_INSTRUCTION_INTERFACE_ID_V2, ALLOCATION_INTERFACE_ID_V2, ALLOCATION_REQUEST_INTERFACE_ID_V2, AllocationInstruction, HOLDING_INTERFACE_ID_V2, TRANSFER_FACTORY_INTERFACE_ID_V2, TRANSFER_INSTRUCTION_INTERFACE_ID_V2, TokenStandardClient as TokenStandardClient$1, TransferInstruction as TransferInstruction$1, isSameAccount } from "@canton-network/core-token-standard-v2";
|
|
6
6
|
import { getLogger } from "@logtape/logtape";
|
|
7
7
|
import { ACSReader } from "@canton-network/core-acs-reader";
|
|
8
8
|
// src/types.ts
|
|
@@ -16,7 +16,7 @@ const KEY_MAPPING = {
|
|
|
16
16
|
"allocation-instruction": "allocationInstruction",
|
|
17
17
|
"allocation-request": "allocationRequest"
|
|
18
18
|
};
|
|
19
|
-
// \0@oxc-project+runtime@0.
|
|
19
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
20
20
|
function _typeof(o) {
|
|
21
21
|
"@babel/helpers - typeof";
|
|
22
22
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -25,23 +25,23 @@ function _typeof(o) {
|
|
|
25
25
|
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
26
26
|
}, _typeof(o);
|
|
27
27
|
}
|
|
28
|
-
// \0@oxc-project+runtime@0.
|
|
29
|
-
function toPrimitive(t,
|
|
28
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
29
|
+
function toPrimitive(t, e) {
|
|
30
30
|
if ("object" != _typeof(t) || !t) return t;
|
|
31
|
-
var
|
|
32
|
-
if (void 0 !==
|
|
33
|
-
var i =
|
|
31
|
+
var r;
|
|
32
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
33
|
+
var i = r.call(t, e || "default");
|
|
34
34
|
if ("object" != _typeof(i)) return i;
|
|
35
35
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
36
36
|
}
|
|
37
|
-
return ("string" ===
|
|
37
|
+
return ("string" === e ? String : Number)(t);
|
|
38
38
|
}
|
|
39
|
-
// \0@oxc-project+runtime@0.
|
|
39
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
40
40
|
function toPropertyKey(t) {
|
|
41
41
|
var i = toPrimitive(t, "string");
|
|
42
42
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
43
43
|
}
|
|
44
|
-
// \0@oxc-project+runtime@0.
|
|
44
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
45
45
|
function _defineProperty(e, r, t) {
|
|
46
46
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
47
47
|
value: t,
|
|
@@ -568,15 +568,12 @@ var CoreService = class CoreService {
|
|
|
568
568
|
id: ""
|
|
569
569
|
};
|
|
570
570
|
}
|
|
571
|
-
isSameAccount(a, b) {
|
|
572
|
-
return a.id === b.id && a.owner === b.owner && a.provider === b.provider;
|
|
573
|
-
}
|
|
574
571
|
async getInputHoldingCidsForAccount(opts) {
|
|
575
572
|
if (opts.inputUtxos?.length) return opts.inputUtxos;
|
|
576
573
|
const party = opts.partyId ?? opts.account.owner;
|
|
577
574
|
if (!party) throw new Error("No party to query as");
|
|
578
575
|
const now = /* @__PURE__ */ new Date();
|
|
579
|
-
const holdings = (await this.listContractsByInterface(HOLDING_INTERFACE_ID_V2, party, opts.limit, opts.offset, opts.continueUntilCompletion ??
|
|
576
|
+
const holdings = (await this.listContractsByInterface(HOLDING_INTERFACE_ID_V2, party, opts.limit, opts.offset, opts.continueUntilCompletion ?? false)).filter((h) => h.interfaceViewValue.instrumentId.admin === opts.instrumentAdmin && h.interfaceViewValue.instrumentId.id === opts.instrumentId && isSameAccount(opts.account, h.interfaceViewValue.account) && !TokenStandardService.isHoldingLocked(h, now) && !opts.excludeCids?.has(h.contractId));
|
|
580
577
|
return opts.amount ? CoreService.getInputHoldingsCidsForAmount(opts.amount, holdings) : holdings.map((h) => h.contractId);
|
|
581
578
|
}
|
|
582
579
|
async getInputHoldingsCids(options) {
|
|
@@ -908,21 +905,23 @@ var AllocationService = class AllocationService {
|
|
|
908
905
|
* or `null` if no registry serves that admin.
|
|
909
906
|
* @param opts.partyId - The party accepting the request. Only allocations
|
|
910
907
|
* this party owns are created, and it acts on every command.
|
|
908
|
+
* @params opts.skipSpec Specs to leave out (e.g. already allocated by an earlier attempt).
|
|
911
909
|
* @returns The allocate commands with their disclosed contracts, the accept
|
|
912
910
|
* command with its disclosed contracts (or `null` if any allocation was
|
|
913
911
|
* skipped), and the admins whose allocations were skipped.
|
|
914
912
|
* @throws If the request contains no allocations owned by `partyId`.
|
|
915
913
|
*/
|
|
916
914
|
async createAllocationsForRequestForLoggedInParty(opts) {
|
|
917
|
-
const
|
|
918
|
-
if (
|
|
915
|
+
const ownSpecs = opts.request.allocations.filter((p) => p.authorizer.owner === opts.partyId);
|
|
916
|
+
if (ownSpecs.length === 0) throw new Error(`Request ${opts.requestCid} has no allocation for account ${opts.partyId}`);
|
|
917
|
+
const specs = opts.skipSpec ? ownSpecs.filter((spec) => !opts.skipSpec(spec)) : ownSpecs;
|
|
919
918
|
const used = /* @__PURE__ */ new Set();
|
|
920
919
|
const allocate = [];
|
|
921
920
|
const skipped = [];
|
|
922
921
|
for (const spec of specs) {
|
|
923
922
|
const registryUrl = await opts.registry(spec.admin);
|
|
924
923
|
if (!registryUrl) {
|
|
925
|
-
skipped.push(spec.admin);
|
|
924
|
+
if (!skipped.includes(spec.admin)) skipped.push(spec.admin);
|
|
926
925
|
continue;
|
|
927
926
|
}
|
|
928
927
|
const [cmd, dcs] = await this.createAllocation({
|