@canton-network/core-ledger-client 0.24.0 → 0.25.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/amulet-service.d.ts.map +1 -1
- package/dist/index.cjs +259 -99
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +259 -100
- package/dist/index.js.map +1 -1
- package/dist/ledger-api-utils.d.ts +14 -7
- package/dist/ledger-api-utils.d.ts.map +1 -1
- package/dist/token-standard-service.d.ts.map +1 -1
- package/dist/txparse/parser.d.ts.map +1 -1
- package/dist/web-socket-client.d.ts +44 -0
- package/dist/web-socket-client.d.ts.map +1 -0
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amulet-service.d.ts","sourceRoot":"","sources":["../src/amulet-service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAA;AAChF,OAAO,EACH,eAAe,EACf,iBAAiB,EACjB,oBAAoB,EACvB,MAAM,6BAA6B,CAAA;AAMpC;;;;;;GAMG;AACH,qBAAa,aAAa;IAElB,QAAQ,CAAC,aAAa,EAAE,oBAAoB;IAC5C,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAFlB,aAAa,EAAE,oBAAoB,EAC3B,eAAe,EAAE,eAAe,EAChC,UAAU,EAAE,UAAU,GAAG,SAAS;IAGjD,6BAA6B,CAAC,OAAO,EAAE,OAAO;kBA2JlD,wFAAsB;;;IA9IlB,sBAAsB,CAAC,OAAO,EAAE,OAAO;;;;;;;IAavC,gBAAgB,CAClB,GAAG,EAAE,OAAO,EACZ,QAAQ,EAAE,OAAO,EACjB,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,EAAE,GACtB,OAAO,CAAC,CAAC,eAAe,EAAE,iBAAiB,EAAE,CAAC,CAAC;IAkE5C,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"amulet-service.d.ts","sourceRoot":"","sources":["../src/amulet-service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAA;AAChF,OAAO,EACH,eAAe,EACf,iBAAiB,EACjB,oBAAoB,EACvB,MAAM,6BAA6B,CAAA;AAMpC;;;;;;GAMG;AACH,qBAAa,aAAa;IAElB,QAAQ,CAAC,aAAa,EAAE,oBAAoB;IAC5C,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAFlB,aAAa,EAAE,oBAAoB,EAC3B,eAAe,EAAE,eAAe,EAChC,UAAU,EAAE,UAAU,GAAG,SAAS;IAGjD,6BAA6B,CAAC,OAAO,EAAE,OAAO;kBA2JlD,wFAAsB;;;IA9IlB,sBAAsB,CAAC,OAAO,EAAE,OAAO;;;;;;;IAavC,gBAAgB,CAClB,GAAG,EAAE,OAAO,EACZ,QAAQ,EAAE,OAAO,EACjB,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,EAAE,GACtB,OAAO,CAAC,CAAC,eAAe,EAAE,iBAAiB,EAAE,CAAC,CAAC;IAkE5C,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;wBAiM+/lF,kFAAsB;;IAjL9kmF,wBAAwB,CAC1B,eAAe,EAAE,OAAO,EACxB,cAAc,EAAE,MAAM,GACvB,OAAO,CAAC,CAAC,eAAe,EAAE,iBAAiB,EAAE,CAAC,CAAC;IAsB5C,yBAAyB,CAC3B,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,OAAO,GACf,OAAO,CAAC,CAAC,eAAe,EAAE,iBAAiB,EAAE,CAAC,CAAC;IAU5C,wBAAwB,CAC1B,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,OAAO,EACjB,cAAc,EAAE,OAAO,EACvB,YAAY,CAAC,EAAE,IAAI,EACnB,UAAU,CAAC,EAAE,MAAM,EAAE,GACtB,OAAO,CAAC,CAAC,eAAe,EAAE,iBAAiB,EAAE,CAAC,CAAC;IAiE5C,SAAS,CACX,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,MAAM,EAAE,0CAA0C;IACnE,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,GACpB,OAAO,CAAC,CAAC,eAAe,EAAE,iBAAiB,EAAE,CAAC,CAAC;CA2DrD"}
|
package/dist/index.cjs
CHANGED
|
@@ -50,93 +50,131 @@ var AllKnownMetaKeys = [
|
|
|
50
50
|
ReasonMetaKey,
|
|
51
51
|
BurnedMetaKey
|
|
52
52
|
];
|
|
53
|
-
function
|
|
54
|
-
|
|
55
|
-
if (options.isMasterUser)
|
|
53
|
+
function createIdentiferFilter(type, id) {
|
|
54
|
+
if (type === "Template") {
|
|
56
55
|
return {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
identifierFilter: {
|
|
57
|
+
TemplateFilter: {
|
|
58
|
+
value: {
|
|
59
|
+
templateId: id,
|
|
60
|
+
includeCreatedEventBlob: true
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
63
64
|
};
|
|
64
|
-
else
|
|
65
|
-
throw new Error("Party must be provided for non-master users");
|
|
66
|
-
else
|
|
65
|
+
} else {
|
|
67
66
|
return {
|
|
68
|
-
filtersByParty: filtersByParty(
|
|
69
|
-
options.partyId,
|
|
70
|
-
interfaceArrayed,
|
|
71
|
-
options.includeWildcard ?? false
|
|
72
|
-
) ?? {},
|
|
73
|
-
verbose: options.verbose ?? false
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
function filtersByParty(party, interfaceNames, includeWildcard) {
|
|
77
|
-
const wildcardFilter = includeWildcard ? [
|
|
78
|
-
{
|
|
79
67
|
identifierFilter: {
|
|
80
|
-
|
|
68
|
+
InterfaceFilter: {
|
|
81
69
|
value: {
|
|
70
|
+
interfaceId: id,
|
|
71
|
+
includeInterfaceView: true,
|
|
82
72
|
includeCreatedEventBlob: true
|
|
83
73
|
}
|
|
84
74
|
}
|
|
85
75
|
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function createWildcardFilter() {
|
|
80
|
+
return {
|
|
81
|
+
identifierFilter: {
|
|
82
|
+
WildcardFilter: {
|
|
83
|
+
value: {
|
|
84
|
+
includeCreatedEventBlob: true
|
|
85
|
+
}
|
|
86
|
+
}
|
|
86
87
|
}
|
|
87
|
-
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function buildCumulativeFilters(templateIds, interfaceIds, includeWildcard) {
|
|
91
|
+
if (templateIds.length > 0) {
|
|
92
|
+
return [
|
|
93
|
+
...templateIds.map(
|
|
94
|
+
(templateId) => createIdentiferFilter("Template", templateId)
|
|
95
|
+
),
|
|
96
|
+
...includeWildcard ? [createWildcardFilter()] : []
|
|
97
|
+
];
|
|
98
|
+
} else {
|
|
99
|
+
return [
|
|
100
|
+
...interfaceIds.map(
|
|
101
|
+
(interfaceId) => createIdentiferFilter("Interface", interfaceId)
|
|
102
|
+
),
|
|
103
|
+
...includeWildcard ? [createWildcardFilter()] : []
|
|
104
|
+
];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function buildFilter(templateIds, interfaceIds, options, additionalProps) {
|
|
108
|
+
const { isMasterUser = false, partyId, includeWildcard = false } = options;
|
|
109
|
+
if (isMasterUser) {
|
|
110
|
+
return {
|
|
111
|
+
filtersByParty: {},
|
|
112
|
+
filtersForAnyParty: filtersForAnyParty(
|
|
113
|
+
templateIds,
|
|
114
|
+
interfaceIds,
|
|
115
|
+
includeWildcard
|
|
116
|
+
),
|
|
117
|
+
...additionalProps
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
if (!partyId) {
|
|
121
|
+
throw new Error("Party must be provided for non-master users");
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
filtersByParty: filtersByParty(
|
|
125
|
+
partyId,
|
|
126
|
+
templateIds,
|
|
127
|
+
interfaceIds,
|
|
128
|
+
includeWildcard
|
|
129
|
+
),
|
|
130
|
+
...additionalProps
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function TransactionFilterBySetup(options) {
|
|
134
|
+
const { templateIds, interfaceIds, ...baseOptions } = options;
|
|
135
|
+
return buildFilter(
|
|
136
|
+
normalizeToArray(templateIds || []),
|
|
137
|
+
normalizeToArray(interfaceIds || []),
|
|
138
|
+
baseOptions
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
function EventFilterBySetup(options) {
|
|
142
|
+
const {
|
|
143
|
+
templateIds,
|
|
144
|
+
interfaceIds,
|
|
145
|
+
verbose = false,
|
|
146
|
+
...baseOptions
|
|
147
|
+
} = options;
|
|
148
|
+
return buildFilter(
|
|
149
|
+
normalizeToArray(templateIds || []),
|
|
150
|
+
normalizeToArray(interfaceIds || []),
|
|
151
|
+
baseOptions,
|
|
152
|
+
{ verbose }
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
function filtersByParty(party, templateIds, interfaceIds, includeWildcard) {
|
|
88
156
|
return {
|
|
89
157
|
[party]: {
|
|
90
|
-
cumulative:
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
value: {
|
|
96
|
-
interfaceId: interfaceName,
|
|
97
|
-
includeInterfaceView: true,
|
|
98
|
-
includeCreatedEventBlob: true
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
}),
|
|
104
|
-
...wildcardFilter
|
|
105
|
-
]
|
|
158
|
+
cumulative: buildCumulativeFilters(
|
|
159
|
+
templateIds,
|
|
160
|
+
interfaceIds,
|
|
161
|
+
includeWildcard
|
|
162
|
+
)
|
|
106
163
|
}
|
|
107
164
|
};
|
|
108
165
|
}
|
|
109
|
-
function filtersForAnyParty(interfaceNames, includeWildcard) {
|
|
110
|
-
const wildcardFilter = includeWildcard ? [
|
|
111
|
-
{
|
|
112
|
-
identifierFilter: {
|
|
113
|
-
WildcardFilter: {
|
|
114
|
-
value: {
|
|
115
|
-
includeCreatedEventBlob: true
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
] : [];
|
|
166
|
+
function filtersForAnyParty(interfaceNames, templateIds, includeWildcard) {
|
|
121
167
|
return {
|
|
122
|
-
cumulative:
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
value: {
|
|
128
|
-
interfaceId: interfaceName,
|
|
129
|
-
includeInterfaceView: true,
|
|
130
|
-
includeCreatedEventBlob: true
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
}),
|
|
136
|
-
...wildcardFilter
|
|
137
|
-
]
|
|
168
|
+
cumulative: buildCumulativeFilters(
|
|
169
|
+
templateIds,
|
|
170
|
+
interfaceNames,
|
|
171
|
+
includeWildcard
|
|
172
|
+
)
|
|
138
173
|
};
|
|
139
174
|
}
|
|
175
|
+
function normalizeToArray(value) {
|
|
176
|
+
return Array.isArray(value) ? value : [value];
|
|
177
|
+
}
|
|
140
178
|
function hasInterface(interfaceId, event) {
|
|
141
179
|
return (event.implementedInterfaces || []).some(
|
|
142
180
|
(id) => matchInterfaceIds(id, interfaceId)
|
|
@@ -985,14 +1023,15 @@ var TransactionParser = class {
|
|
|
985
1023
|
}
|
|
986
1024
|
const basePayload = {
|
|
987
1025
|
contractId: archivedEvent.contractId,
|
|
988
|
-
eventFormat: EventFilterBySetup(
|
|
989
|
-
[
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
1026
|
+
eventFormat: EventFilterBySetup({
|
|
1027
|
+
interfaceIds: [
|
|
1028
|
+
coreTokenStandard.HOLDING_INTERFACE_ID,
|
|
1029
|
+
coreTokenStandard.TRANSFER_INSTRUCTION_INTERFACE_ID
|
|
1030
|
+
],
|
|
1031
|
+
isMasterUser: this.isMasterUser,
|
|
1032
|
+
partyId: this.partyId,
|
|
1033
|
+
verbose: true
|
|
1034
|
+
})
|
|
996
1035
|
};
|
|
997
1036
|
const payload = this.ledgerClient.getCurrentClientVersion() === "3.3" ? { ...basePayload, requestingParties: [] } : basePayload;
|
|
998
1037
|
const events = await this.ledgerClient.postWithRetry("/v2/events/events-by-contract-id", payload).catch((err) => {
|
|
@@ -1486,7 +1525,9 @@ var AllocationService = class {
|
|
|
1486
1525
|
async fetchExecuteTransferChoiceContext(allocationId, registryUrl) {
|
|
1487
1526
|
return this.core.getTokenStandardClient(registryUrl).post(
|
|
1488
1527
|
"/registry/allocations/v1/{allocationId}/choice-contexts/execute-transfer",
|
|
1489
|
-
{
|
|
1528
|
+
{
|
|
1529
|
+
excludeDebugFields: true
|
|
1530
|
+
},
|
|
1490
1531
|
{
|
|
1491
1532
|
path: {
|
|
1492
1533
|
allocationId
|
|
@@ -1521,7 +1562,9 @@ var AllocationService = class {
|
|
|
1521
1562
|
async fetchWithdrawAllocationChoiceContext(allocationCid, registryUrl) {
|
|
1522
1563
|
return this.core.getTokenStandardClient(registryUrl).post(
|
|
1523
1564
|
"/registry/allocations/v1/{allocationId}/choice-contexts/withdraw",
|
|
1524
|
-
{
|
|
1565
|
+
{
|
|
1566
|
+
excludeDebugFields: true
|
|
1567
|
+
},
|
|
1525
1568
|
{ path: { allocationId: allocationCid } }
|
|
1526
1569
|
);
|
|
1527
1570
|
}
|
|
@@ -1552,7 +1595,9 @@ var AllocationService = class {
|
|
|
1552
1595
|
async fetchCancelAllocationChoiceContext(allocationCid, registryUrl) {
|
|
1553
1596
|
return this.core.getTokenStandardClient(registryUrl).post(
|
|
1554
1597
|
"/registry/allocations/v1/{allocationId}/choice-contexts/cancel",
|
|
1555
|
-
{
|
|
1598
|
+
{
|
|
1599
|
+
excludeDebugFields: true
|
|
1600
|
+
},
|
|
1556
1601
|
{ path: { allocationId: allocationCid } }
|
|
1557
1602
|
);
|
|
1558
1603
|
}
|
|
@@ -1734,7 +1779,9 @@ var TransferService = class {
|
|
|
1734
1779
|
const client = this.core.getTokenStandardClient(registryUrl);
|
|
1735
1780
|
const choiceContext = await client.post(
|
|
1736
1781
|
"/registry/transfer-instruction/v1/{transferInstructionId}/choice-contexts/accept",
|
|
1737
|
-
{
|
|
1782
|
+
{
|
|
1783
|
+
excludeDebugFields: true
|
|
1784
|
+
},
|
|
1738
1785
|
{
|
|
1739
1786
|
path: {
|
|
1740
1787
|
transferInstructionId: transferInstructionCid
|
|
@@ -1867,7 +1914,9 @@ var TransferService = class {
|
|
|
1867
1914
|
const client = this.core.getTokenStandardClient(registryUrl);
|
|
1868
1915
|
const choiceContext = await client.post(
|
|
1869
1916
|
"/registry/transfer-instruction/v1/{transferInstructionId}/choice-contexts/reject",
|
|
1870
|
-
{
|
|
1917
|
+
{
|
|
1918
|
+
excludeDebugFields: true
|
|
1919
|
+
},
|
|
1871
1920
|
{
|
|
1872
1921
|
path: {
|
|
1873
1922
|
transferInstructionId: transferInstructionCid
|
|
@@ -1924,7 +1973,9 @@ var TransferService = class {
|
|
|
1924
1973
|
const client = this.core.getTokenStandardClient(registryUrl);
|
|
1925
1974
|
const choiceContext = await client.post(
|
|
1926
1975
|
"/registry/transfer-instruction/v1/{transferInstructionId}/choice-contexts/withdraw",
|
|
1927
|
-
{
|
|
1976
|
+
{
|
|
1977
|
+
excludeDebugFields: true
|
|
1978
|
+
},
|
|
1928
1979
|
{
|
|
1929
1980
|
path: {
|
|
1930
1981
|
transferInstructionId: transferInstructionCid
|
|
@@ -2074,14 +2125,12 @@ var TokenStandardService = class {
|
|
|
2074
2125
|
const updatesResponse = await this.ledgerClient.postWithRetry("/v2/updates/flats", {
|
|
2075
2126
|
updateFormat: {
|
|
2076
2127
|
includeTransactions: {
|
|
2077
|
-
eventFormat: EventFilterBySetup(
|
|
2078
|
-
TokenStandardTransactionInterfaces,
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
}
|
|
2084
|
-
),
|
|
2128
|
+
eventFormat: EventFilterBySetup({
|
|
2129
|
+
interfaceIds: TokenStandardTransactionInterfaces,
|
|
2130
|
+
isMasterUser: this.isMasterUser,
|
|
2131
|
+
partyId,
|
|
2132
|
+
includeWildcard: true
|
|
2133
|
+
}),
|
|
2085
2134
|
transactionShape: "TRANSACTION_SHAPE_LEDGER_EFFECTS"
|
|
2086
2135
|
}
|
|
2087
2136
|
},
|
|
@@ -2101,14 +2150,12 @@ var TokenStandardService = class {
|
|
|
2101
2150
|
}
|
|
2102
2151
|
async getTransactionById(updateId, partyId) {
|
|
2103
2152
|
const transactionFormat = {
|
|
2104
|
-
eventFormat: EventFilterBySetup(
|
|
2105
|
-
TokenStandardTransactionInterfaces,
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
}
|
|
2111
|
-
),
|
|
2153
|
+
eventFormat: EventFilterBySetup({
|
|
2154
|
+
interfaceIds: TokenStandardTransactionInterfaces,
|
|
2155
|
+
isMasterUser: this.isMasterUser,
|
|
2156
|
+
partyId,
|
|
2157
|
+
includeWildcard: true
|
|
2158
|
+
}),
|
|
2112
2159
|
transactionShape: "TRANSACTION_SHAPE_LEDGER_EFFECTS"
|
|
2113
2160
|
};
|
|
2114
2161
|
const getTransactionResponse = await this.ledgerClient.postWithRetry(
|
|
@@ -3453,6 +3500,118 @@ var WSSupportWithBackOffSwitch = class {
|
|
|
3453
3500
|
}
|
|
3454
3501
|
};
|
|
3455
3502
|
|
|
3503
|
+
// src/generated-clients/asyncapi-3.4.7.ts
|
|
3504
|
+
var CHANNELS = {
|
|
3505
|
+
v2_commands_completions: "/v2/commands/completions",
|
|
3506
|
+
v2_updates: "/v2/updates"};
|
|
3507
|
+
|
|
3508
|
+
// src/web-socket-client.ts
|
|
3509
|
+
var WebSocketClient = class {
|
|
3510
|
+
constructor({
|
|
3511
|
+
baseUrl,
|
|
3512
|
+
isAdmin,
|
|
3513
|
+
accessTokenProvider,
|
|
3514
|
+
logger,
|
|
3515
|
+
wsSupportBackOff
|
|
3516
|
+
}) {
|
|
3517
|
+
__publicField(this, "ws", null);
|
|
3518
|
+
__publicField(this, "baseUrl");
|
|
3519
|
+
__publicField(this, "token", "");
|
|
3520
|
+
__publicField(this, "isAdmin");
|
|
3521
|
+
__publicField(this, "protocol", []);
|
|
3522
|
+
__publicField(this, "logger");
|
|
3523
|
+
__publicField(this, "wsSupportBackOff");
|
|
3524
|
+
__publicField(this, "accessTokenProvider");
|
|
3525
|
+
this.logger = logger.child({ component: "WebSocketClient" });
|
|
3526
|
+
this.baseUrl = baseUrl;
|
|
3527
|
+
this.wsSupportBackOff = wsSupportBackOff;
|
|
3528
|
+
this.accessTokenProvider = accessTokenProvider;
|
|
3529
|
+
this.isAdmin = isAdmin ?? false;
|
|
3530
|
+
}
|
|
3531
|
+
async init() {
|
|
3532
|
+
this.token = this.isAdmin ? await this.accessTokenProvider.getAdminAccessToken() : await this.accessTokenProvider.getUserAccessToken();
|
|
3533
|
+
this.protocol = [`jwt.token.${this.token}`, "daml.ws.auth"];
|
|
3534
|
+
this.logger.info(
|
|
3535
|
+
`initializing websocket client with ${this.protocol.length} protocols`
|
|
3536
|
+
);
|
|
3537
|
+
}
|
|
3538
|
+
generate(wsUrl, request) {
|
|
3539
|
+
const messageQueue = [];
|
|
3540
|
+
let resolveNext = null;
|
|
3541
|
+
let isClosed = false;
|
|
3542
|
+
let streamError = null;
|
|
3543
|
+
const generator = async function* () {
|
|
3544
|
+
await this.init();
|
|
3545
|
+
this.logger.debug(request);
|
|
3546
|
+
const ws = new WebSocket(wsUrl, this.protocol);
|
|
3547
|
+
ws.onopen = () => {
|
|
3548
|
+
ws.send(JSON.stringify(request));
|
|
3549
|
+
};
|
|
3550
|
+
ws.onmessage = (event) => {
|
|
3551
|
+
messageQueue.push(JSON.parse(event.data));
|
|
3552
|
+
this.logger.debug(event.data, `Received event`);
|
|
3553
|
+
resolveNext?.();
|
|
3554
|
+
};
|
|
3555
|
+
ws.onerror = () => {
|
|
3556
|
+
streamError = new Error("WebSocket Handshake/Connection failed");
|
|
3557
|
+
this.logger.error(`Encountered ws.onError`);
|
|
3558
|
+
isClosed = true;
|
|
3559
|
+
resolveNext?.();
|
|
3560
|
+
};
|
|
3561
|
+
ws.onclose = (event) => {
|
|
3562
|
+
this.logger.debug(
|
|
3563
|
+
`CLOSING WEBSOCKET CONNECTION code: ${event.code}, reason: ${event.reason}`
|
|
3564
|
+
);
|
|
3565
|
+
isClosed = true;
|
|
3566
|
+
resolveNext?.();
|
|
3567
|
+
};
|
|
3568
|
+
try {
|
|
3569
|
+
while (true) {
|
|
3570
|
+
if (messageQueue.length === 0) {
|
|
3571
|
+
if (isClosed) break;
|
|
3572
|
+
await new Promise((r) => resolveNext = r);
|
|
3573
|
+
}
|
|
3574
|
+
if (streamError) throw streamError;
|
|
3575
|
+
while (messageQueue.length > 0) {
|
|
3576
|
+
yield messageQueue.shift();
|
|
3577
|
+
}
|
|
3578
|
+
if (isClosed && messageQueue.length === 0) break;
|
|
3579
|
+
}
|
|
3580
|
+
} finally {
|
|
3581
|
+
if (ws.readyState === WebSocket.OPEN) ws.close();
|
|
3582
|
+
this.logger.info("Generator cleanup: WebSocket closed.");
|
|
3583
|
+
}
|
|
3584
|
+
};
|
|
3585
|
+
return generator.call(this);
|
|
3586
|
+
}
|
|
3587
|
+
streamUpdates(options) {
|
|
3588
|
+
const wsUpdatesUrl = `${this.baseUrl}${CHANNELS.v2_updates}`;
|
|
3589
|
+
const filter = options.templateIds ? TransactionFilterBySetup({
|
|
3590
|
+
templateIds: options.templateIds,
|
|
3591
|
+
partyId: options.partyId
|
|
3592
|
+
}) : TransactionFilterBySetup({
|
|
3593
|
+
interfaceIds: options.interfaceIds,
|
|
3594
|
+
partyId: options.partyId
|
|
3595
|
+
});
|
|
3596
|
+
const request = {
|
|
3597
|
+
beginExclusive: options.beginExclusive,
|
|
3598
|
+
endInclusive: options.endInclusive,
|
|
3599
|
+
verbose: options.verbose ?? true,
|
|
3600
|
+
filter
|
|
3601
|
+
};
|
|
3602
|
+
return this.generate(wsUpdatesUrl, request);
|
|
3603
|
+
}
|
|
3604
|
+
streamCompletions(options) {
|
|
3605
|
+
const wsCompletionsUrl = `${this.baseUrl}${CHANNELS.v2_commands_completions}`;
|
|
3606
|
+
const request = {
|
|
3607
|
+
beginExclusive: options.beginExclusive,
|
|
3608
|
+
userId: options.userId,
|
|
3609
|
+
parties: options.parties
|
|
3610
|
+
};
|
|
3611
|
+
return this.generate(wsCompletionsUrl, request);
|
|
3612
|
+
}
|
|
3613
|
+
};
|
|
3614
|
+
|
|
3456
3615
|
exports.ACSContainer = ACSContainer;
|
|
3457
3616
|
exports.ACS_UPDATE_CONFIG = ACS_UPDATE_CONFIG;
|
|
3458
3617
|
exports.AmuletService = AmuletService;
|
|
@@ -3462,6 +3621,7 @@ exports.TokenStandardService = TokenStandardService;
|
|
|
3462
3621
|
exports.TokenStandardTransactionInterfaces = TokenStandardTransactionInterfaces;
|
|
3463
3622
|
exports.TransactionParser = TransactionParser;
|
|
3464
3623
|
exports.WSSupportWithBackOffSwitch = WSSupportWithBackOffSwitch;
|
|
3624
|
+
exports.WebSocketClient = WebSocketClient;
|
|
3465
3625
|
exports.asJsCantonError = asJsCantonError;
|
|
3466
3626
|
exports.awaitCompletion = awaitCompletion;
|
|
3467
3627
|
exports.defaultRetryableOptions = defaultRetryableOptions;
|