@canton-network/core-ledger-client 0.10.0 → 0.11.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/constants.d.ts +0 -3
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +8 -8
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/ledger-api-utils.d.ts +14 -2
- package/dist/ledger-api-utils.d.ts.map +1 -1
- package/dist/ledger-api-utils.js +76 -5
- package/dist/ledger-client.d.ts +35 -1
- package/dist/ledger-client.d.ts.map +1 -1
- package/dist/ledger-client.js +146 -10
- package/dist/token-standard-service.d.ts +25 -9
- package/dist/token-standard-service.d.ts.map +1 -1
- package/dist/token-standard-service.js +256 -67
- package/dist/topology-write-service.d.ts +15 -3
- package/dist/topology-write-service.d.ts.map +1 -1
- package/dist/topology-write-service.js +28 -18
- package/dist/txparse/parser.d.ts +2 -1
- package/dist/txparse/parser.d.ts.map +1 -1
- package/dist/txparse/parser.js +22 -18
- package/dist/txparse/parser.test.js +3 -3
- package/package.json +6 -8
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Copyright (c) 2025 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { TokenStandardClient, } from '@canton-network/core-token-standard';
|
|
4
|
-
import {
|
|
5
|
-
import { ensureInterfaceViewIsPresent,
|
|
3
|
+
import { TokenStandardClient, HOLDING_INTERFACE_ID, ALLOCATION_FACTORY_INTERFACE_ID, ALLOCATION_INTERFACE_ID, ALLOCATION_REQUEST_INTERFACE_ID, ALLOCATION_INSTRUCTION_INTERFACE_ID, TRANSFER_INSTRUCTION_INTERFACE_ID, TRANSFER_FACTORY_INTERFACE_ID, } from '@canton-network/core-token-standard';
|
|
4
|
+
import { TokenStandardTransactionInterfaces } from './constants.js';
|
|
5
|
+
import { ensureInterfaceViewIsPresent, TransactionFilterBySetup, EventFilterBySetup, } from './ledger-api-utils.js';
|
|
6
6
|
import { TransactionParser } from './txparse/parser.js';
|
|
7
7
|
import { renderTransaction, } from './txparse/types.js';
|
|
8
8
|
const MEMO_KEY = 'splice.lfdecentralizedtrust.org/reason';
|
|
@@ -11,11 +11,13 @@ export class TokenStandardService {
|
|
|
11
11
|
scanProxyClient;
|
|
12
12
|
logger;
|
|
13
13
|
accessToken;
|
|
14
|
-
|
|
14
|
+
isMasterUser;
|
|
15
|
+
constructor(ledgerClient, scanProxyClient, logger, accessToken, isMasterUser) {
|
|
15
16
|
this.ledgerClient = ledgerClient;
|
|
16
17
|
this.scanProxyClient = scanProxyClient;
|
|
17
18
|
this.logger = logger;
|
|
18
19
|
this.accessToken = accessToken;
|
|
20
|
+
this.isMasterUser = isMasterUser;
|
|
19
21
|
}
|
|
20
22
|
getTokenStandardClient(registryUrl) {
|
|
21
23
|
return new TokenStandardClient(registryUrl, this.logger, this.accessToken);
|
|
@@ -36,14 +38,14 @@ export class TokenStandardService {
|
|
|
36
38
|
});
|
|
37
39
|
return featured_app_right;
|
|
38
40
|
}
|
|
39
|
-
async getInstrumentById(
|
|
41
|
+
async getInstrumentById(registryUrl, instrumentId) {
|
|
40
42
|
try {
|
|
41
43
|
const params = {
|
|
42
44
|
path: {
|
|
43
45
|
instrumentId,
|
|
44
46
|
},
|
|
45
47
|
};
|
|
46
|
-
const client = this.getTokenStandardClient(
|
|
48
|
+
const client = this.getTokenStandardClient(registryUrl);
|
|
47
49
|
return client.get('/registry/metadata/v1/instruments/{instrumentId}', params);
|
|
48
50
|
}
|
|
49
51
|
catch (e) {
|
|
@@ -51,16 +53,21 @@ export class TokenStandardService {
|
|
|
51
53
|
throw new Error(`Instrument id ${instrumentId} does not exist for this instrument admin.`);
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
|
-
async
|
|
56
|
+
async getInstrumentAdmin(registryUrl) {
|
|
57
|
+
const client = this.getTokenStandardClient(registryUrl);
|
|
58
|
+
const info = await client.get('/registry/metadata/v1/info');
|
|
59
|
+
return info.adminId;
|
|
60
|
+
}
|
|
61
|
+
async createAcceptTransferInstruction(transferInstructionCid, registryUrl) {
|
|
55
62
|
try {
|
|
56
|
-
const client = this.getTokenStandardClient(
|
|
63
|
+
const client = this.getTokenStandardClient(registryUrl);
|
|
57
64
|
const choiceContext = await client.post('/registry/transfer-instruction/v1/{transferInstructionId}/choice-contexts/accept', {}, {
|
|
58
65
|
path: {
|
|
59
66
|
transferInstructionId: transferInstructionCid,
|
|
60
67
|
},
|
|
61
68
|
});
|
|
62
69
|
const exercise = {
|
|
63
|
-
templateId:
|
|
70
|
+
templateId: TRANSFER_INSTRUCTION_INTERFACE_ID,
|
|
64
71
|
contractId: transferInstructionCid,
|
|
65
72
|
choice: 'TransferInstruction_Accept',
|
|
66
73
|
choiceArgument: {
|
|
@@ -77,21 +84,16 @@ export class TokenStandardService {
|
|
|
77
84
|
throw e;
|
|
78
85
|
}
|
|
79
86
|
}
|
|
80
|
-
async
|
|
81
|
-
const client = this.getTokenStandardClient(transferFactoryRegistryUrl);
|
|
82
|
-
const info = await client.get('/registry/metadata/v1/info');
|
|
83
|
-
return info.adminId;
|
|
84
|
-
}
|
|
85
|
-
async createRejectTransferInstruction(transferInstructionCid, transferFactoryRegistryUrl) {
|
|
87
|
+
async createRejectTransferInstruction(transferInstructionCid, registryUrl) {
|
|
86
88
|
try {
|
|
87
|
-
const client = this.getTokenStandardClient(
|
|
89
|
+
const client = this.getTokenStandardClient(registryUrl);
|
|
88
90
|
const choiceContext = await client.post('/registry/transfer-instruction/v1/{transferInstructionId}/choice-contexts/reject', {}, {
|
|
89
91
|
path: {
|
|
90
92
|
transferInstructionId: transferInstructionCid,
|
|
91
93
|
},
|
|
92
94
|
});
|
|
93
95
|
const exercise = {
|
|
94
|
-
templateId:
|
|
96
|
+
templateId: TRANSFER_INSTRUCTION_INTERFACE_ID,
|
|
95
97
|
contractId: transferInstructionCid,
|
|
96
98
|
choice: 'TransferInstruction_Reject',
|
|
97
99
|
choiceArgument: {
|
|
@@ -108,16 +110,16 @@ export class TokenStandardService {
|
|
|
108
110
|
throw e;
|
|
109
111
|
}
|
|
110
112
|
}
|
|
111
|
-
async createWithdrawTransferInstruction(transferInstructionCid,
|
|
113
|
+
async createWithdrawTransferInstruction(transferInstructionCid, registryUrl) {
|
|
112
114
|
try {
|
|
113
|
-
const client = this.getTokenStandardClient(
|
|
115
|
+
const client = this.getTokenStandardClient(registryUrl);
|
|
114
116
|
const choiceContext = await client.post('/registry/transfer-instruction/v1/{transferInstructionId}/choice-contexts/withdraw', {}, {
|
|
115
117
|
path: {
|
|
116
118
|
transferInstructionId: transferInstructionCid,
|
|
117
119
|
},
|
|
118
120
|
});
|
|
119
121
|
const exercise = {
|
|
120
|
-
templateId:
|
|
122
|
+
templateId: TRANSFER_INSTRUCTION_INTERFACE_ID,
|
|
121
123
|
contractId: transferInstructionCid,
|
|
122
124
|
choice: 'TransferInstruction_Withdraw',
|
|
123
125
|
choiceArgument: {
|
|
@@ -134,15 +136,194 @@ export class TokenStandardService {
|
|
|
134
136
|
throw e;
|
|
135
137
|
}
|
|
136
138
|
}
|
|
139
|
+
async createAllocationInstruction(allocationSpecification, expectedAdmin, registryUrl, inputUtxos, requestedAt, extraContext) {
|
|
140
|
+
const allocationSpecificationNormalized = {
|
|
141
|
+
...allocationSpecification,
|
|
142
|
+
settlement: {
|
|
143
|
+
...allocationSpecification.settlement,
|
|
144
|
+
meta: allocationSpecification.settlement.meta ?? { values: {} },
|
|
145
|
+
},
|
|
146
|
+
transferLeg: {
|
|
147
|
+
...allocationSpecification.transferLeg,
|
|
148
|
+
meta: allocationSpecification.transferLeg.meta ?? {
|
|
149
|
+
values: {},
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
const inputHoldingCids = await this.getInputHoldingsCids(allocationSpecificationNormalized.transferLeg.sender, inputUtxos);
|
|
154
|
+
const choiceArgs = {
|
|
155
|
+
expectedAdmin: expectedAdmin,
|
|
156
|
+
allocation: allocationSpecificationNormalized,
|
|
157
|
+
requestedAt: requestedAt ?? new Date().toISOString(),
|
|
158
|
+
inputHoldingCids,
|
|
159
|
+
extraArgs: {
|
|
160
|
+
context: { values: { ...(extraContext ?? {}) } },
|
|
161
|
+
meta: { values: {} },
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
const allocationFactory = await this.getTokenStandardClient(registryUrl).post('/registry/allocation-instruction/v1/allocation-factory', {
|
|
165
|
+
choiceArguments: choiceArgs,
|
|
166
|
+
});
|
|
167
|
+
choiceArgs.extraArgs.context = {
|
|
168
|
+
...allocationFactory.choiceContext.choiceContextData,
|
|
169
|
+
values: allocationFactory.choiceContext.choiceContextData?.values ?? {},
|
|
170
|
+
};
|
|
171
|
+
const exercise = {
|
|
172
|
+
templateId: ALLOCATION_FACTORY_INTERFACE_ID,
|
|
173
|
+
contractId: allocationFactory.factoryId,
|
|
174
|
+
choice: 'AllocationFactory_Allocate',
|
|
175
|
+
choiceArgument: choiceArgs,
|
|
176
|
+
};
|
|
177
|
+
return [exercise, allocationFactory.choiceContext.disclosedContracts];
|
|
178
|
+
}
|
|
179
|
+
async getAllocationExecuteTransferChoiceContext(allocationId, registryUrl) {
|
|
180
|
+
return this.getTokenStandardClient(registryUrl).post('/registry/allocations/v1/{allocationId}/choice-contexts/execute-transfer', {}, {
|
|
181
|
+
path: {
|
|
182
|
+
allocationId,
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
async createExecuteTransferAllocation(allocationCid, registryUrl) {
|
|
187
|
+
try {
|
|
188
|
+
const choiceContext = await this.getAllocationExecuteTransferChoiceContext(allocationCid, registryUrl);
|
|
189
|
+
const exercise = {
|
|
190
|
+
templateId: ALLOCATION_INTERFACE_ID,
|
|
191
|
+
contractId: allocationCid,
|
|
192
|
+
choice: 'Allocation_ExecuteTransfer',
|
|
193
|
+
choiceArgument: {
|
|
194
|
+
extraArgs: {
|
|
195
|
+
context: choiceContext.choiceContextData,
|
|
196
|
+
meta: { values: {} },
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
return [exercise, choiceContext.disclosedContracts];
|
|
201
|
+
}
|
|
202
|
+
catch (e) {
|
|
203
|
+
this.logger.error('Failed to create allocation execute transfer:', e);
|
|
204
|
+
throw e;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
async createWithdrawAllocation(allocationCid, registryUrl) {
|
|
208
|
+
try {
|
|
209
|
+
const client = this.getTokenStandardClient(registryUrl);
|
|
210
|
+
const choiceContext = await client.post('/registry/allocations/v1/{allocationId}/choice-contexts/withdraw', {}, {
|
|
211
|
+
path: {
|
|
212
|
+
allocationId: allocationCid,
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
const exercise = {
|
|
216
|
+
templateId: ALLOCATION_INTERFACE_ID,
|
|
217
|
+
contractId: allocationCid,
|
|
218
|
+
choice: 'Allocation_Withdraw',
|
|
219
|
+
choiceArgument: {
|
|
220
|
+
extraArgs: {
|
|
221
|
+
context: choiceContext.choiceContextData,
|
|
222
|
+
meta: { values: {} },
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
return [exercise, choiceContext.disclosedContracts];
|
|
227
|
+
}
|
|
228
|
+
catch (e) {
|
|
229
|
+
this.logger.error('Failed to create withdraw allocation:', e);
|
|
230
|
+
throw e;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
async createCancelAllocation(allocationCid, registryUrl) {
|
|
234
|
+
try {
|
|
235
|
+
const client = this.getTokenStandardClient(registryUrl);
|
|
236
|
+
const choiceContext = await client.post('/registry/allocations/v1/{allocationId}/choice-contexts/cancel', {}, {
|
|
237
|
+
path: {
|
|
238
|
+
allocationId: allocationCid,
|
|
239
|
+
},
|
|
240
|
+
});
|
|
241
|
+
const exercise = {
|
|
242
|
+
templateId: ALLOCATION_INTERFACE_ID,
|
|
243
|
+
contractId: allocationCid,
|
|
244
|
+
choice: 'Allocation_Cancel',
|
|
245
|
+
choiceArgument: {
|
|
246
|
+
extraArgs: {
|
|
247
|
+
context: choiceContext.choiceContextData,
|
|
248
|
+
meta: { values: {} },
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
return [exercise, choiceContext.disclosedContracts];
|
|
253
|
+
}
|
|
254
|
+
catch (e) {
|
|
255
|
+
this.logger.error('Failed to create withdraw transfer instruction:', e);
|
|
256
|
+
throw e;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
async createWithdrawAllocationInstruction(registryUrl) {
|
|
260
|
+
const exercise = {
|
|
261
|
+
templateId: ALLOCATION_INSTRUCTION_INTERFACE_ID,
|
|
262
|
+
contractId: registryUrl,
|
|
263
|
+
choice: 'AllocationInstruction_Withdraw',
|
|
264
|
+
choiceArgument: {
|
|
265
|
+
extraArgs: {
|
|
266
|
+
context: { values: {} },
|
|
267
|
+
meta: { values: {} },
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
return [exercise, []];
|
|
272
|
+
}
|
|
273
|
+
async createUpdateAllocationInstruction(allocationInstructionCid, extraActors = [], extraArgsContext = {}, extraArgsMeta = {}) {
|
|
274
|
+
const exercise = {
|
|
275
|
+
templateId: ALLOCATION_INSTRUCTION_INTERFACE_ID,
|
|
276
|
+
contractId: allocationInstructionCid,
|
|
277
|
+
choice: 'AllocationInstruction_Update',
|
|
278
|
+
choiceArgument: {
|
|
279
|
+
extraActors,
|
|
280
|
+
extraArgs: {
|
|
281
|
+
context: { values: extraArgsContext },
|
|
282
|
+
meta: { values: extraArgsMeta },
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
return [exercise, []];
|
|
287
|
+
}
|
|
288
|
+
async createRejectAllocationRequest(allocationRequestCid, actor) {
|
|
289
|
+
const exercise = {
|
|
290
|
+
templateId: ALLOCATION_REQUEST_INTERFACE_ID,
|
|
291
|
+
contractId: allocationRequestCid,
|
|
292
|
+
choice: 'AllocationRequest_Reject',
|
|
293
|
+
choiceArgument: {
|
|
294
|
+
actor,
|
|
295
|
+
extraArgs: {
|
|
296
|
+
context: { values: {} },
|
|
297
|
+
meta: { values: {} },
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
};
|
|
301
|
+
return [exercise, []];
|
|
302
|
+
}
|
|
303
|
+
async createWithdrawAllocationRequest(allocationRequestCid) {
|
|
304
|
+
const exercise = {
|
|
305
|
+
templateId: ALLOCATION_REQUEST_INTERFACE_ID,
|
|
306
|
+
contractId: allocationRequestCid,
|
|
307
|
+
choice: 'AllocationRequest_Withdraw',
|
|
308
|
+
choiceArgument: {
|
|
309
|
+
extraArgs: {
|
|
310
|
+
context: { values: {} },
|
|
311
|
+
meta: { values: {} },
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
return [exercise, []];
|
|
316
|
+
}
|
|
137
317
|
// <T> is shape of viewValue related to queried interface.
|
|
138
318
|
// i.e. when querying by TransferInstruction interfaceId, <T> would be TransferInstructionView from daml codegen
|
|
139
319
|
async listContractsByInterface(interfaceId, partyId) {
|
|
140
320
|
try {
|
|
141
321
|
const ledgerEnd = await this.ledgerClient.get('/v2/state/ledger-end');
|
|
142
322
|
const acsResponses = await this.ledgerClient.post('/v2/state/active-contracts', {
|
|
143
|
-
filter: {
|
|
144
|
-
|
|
145
|
-
|
|
323
|
+
filter: TransactionFilterBySetup(interfaceId, {
|
|
324
|
+
isMasterUser: this.isMasterUser,
|
|
325
|
+
partyId: partyId,
|
|
326
|
+
}),
|
|
146
327
|
verbose: false,
|
|
147
328
|
activeAtOffset: ledgerEnd.offset,
|
|
148
329
|
});
|
|
@@ -175,10 +356,11 @@ export class TokenStandardService {
|
|
|
175
356
|
const updatesResponse = await this.ledgerClient.post('/v2/updates/flats', {
|
|
176
357
|
updateFormat: {
|
|
177
358
|
includeTransactions: {
|
|
178
|
-
eventFormat: {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
359
|
+
eventFormat: EventFilterBySetup(TokenStandardTransactionInterfaces, {
|
|
360
|
+
includeWildcard: true,
|
|
361
|
+
isMasterUser: this.isMasterUser,
|
|
362
|
+
partyId: partyId,
|
|
363
|
+
}),
|
|
182
364
|
transactionShape: 'TRANSACTION_SHAPE_LEDGER_EFFECTS',
|
|
183
365
|
},
|
|
184
366
|
},
|
|
@@ -194,12 +376,12 @@ export class TokenStandardService {
|
|
|
194
376
|
}
|
|
195
377
|
}
|
|
196
378
|
async getTransactionById(updateId, partyId) {
|
|
197
|
-
const filter = filtersByParty(partyId, TokenStandardTransactionInterfaces, true);
|
|
198
379
|
const transactionFormat = {
|
|
199
|
-
eventFormat: {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
380
|
+
eventFormat: EventFilterBySetup(TokenStandardTransactionInterfaces, {
|
|
381
|
+
includeWildcard: true,
|
|
382
|
+
isMasterUser: this.isMasterUser,
|
|
383
|
+
partyId: partyId,
|
|
384
|
+
}),
|
|
203
385
|
transactionShape: 'TRANSACTION_SHAPE_LEDGER_EFFECTS',
|
|
204
386
|
};
|
|
205
387
|
const getTransactionResponse = await this.ledgerClient.post('/v2/updates/transaction-by-id', {
|
|
@@ -208,36 +390,36 @@ export class TokenStandardService {
|
|
|
208
390
|
});
|
|
209
391
|
return this.toPrettyTransaction(getTransactionResponse, partyId, this.ledgerClient);
|
|
210
392
|
}
|
|
393
|
+
async getInputHoldingsCids(sender, inputUtxos) {
|
|
394
|
+
const now = new Date();
|
|
395
|
+
if (inputUtxos && inputUtxos.length > 0) {
|
|
396
|
+
return inputUtxos;
|
|
397
|
+
}
|
|
398
|
+
const senderHoldings = await this.listContractsByInterface(HOLDING_INTERFACE_ID, sender);
|
|
399
|
+
if (senderHoldings.length === 0) {
|
|
400
|
+
throw new Error("Sender has no holdings, so transfer can't be executed.");
|
|
401
|
+
}
|
|
402
|
+
return senderHoldings
|
|
403
|
+
.filter((utxo) => {
|
|
404
|
+
//filter out locked holdings
|
|
405
|
+
const lock = utxo.interfaceViewValue.lock;
|
|
406
|
+
if (!lock)
|
|
407
|
+
return true;
|
|
408
|
+
const expiresAt = lock.expiresAt;
|
|
409
|
+
if (!expiresAt)
|
|
410
|
+
return false;
|
|
411
|
+
const expiresAtDate = new Date(expiresAt);
|
|
412
|
+
return expiresAtDate <= now;
|
|
413
|
+
})
|
|
414
|
+
.map((h) => h.contractId);
|
|
415
|
+
/* TODO: optimize input holding selection, currently if you transfer 10 CC and have 10 inputs of 1000 CC,
|
|
416
|
+
then all 10 of those are chose as input.
|
|
417
|
+
*/
|
|
418
|
+
}
|
|
211
419
|
async createTransfer(sender, receiver, amount, instrumentAdmin, // TODO (#907): replace with registry call
|
|
212
|
-
instrumentId,
|
|
420
|
+
instrumentId, registryUrl, inputUtxos, memo, expiryDate, meta) {
|
|
213
421
|
try {
|
|
214
|
-
|
|
215
|
-
const now = new Date();
|
|
216
|
-
if (inputUtxos && inputUtxos.length > 0) {
|
|
217
|
-
inputHoldingCids = inputUtxos;
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
const senderHoldings = await this.listContractsByInterface(HoldingInterface, sender);
|
|
221
|
-
if (senderHoldings.length === 0) {
|
|
222
|
-
throw new Error("Sender has no holdings, so transfer can't be executed.");
|
|
223
|
-
}
|
|
224
|
-
inputHoldingCids = senderHoldings
|
|
225
|
-
.filter((utxo) => {
|
|
226
|
-
//filter out locked holdings
|
|
227
|
-
const lock = utxo.interfaceViewValue.lock;
|
|
228
|
-
if (!lock)
|
|
229
|
-
return true;
|
|
230
|
-
const expiresAt = lock.expiresAt;
|
|
231
|
-
if (!expiresAt)
|
|
232
|
-
return false;
|
|
233
|
-
const expiresAtDate = new Date(expiresAt);
|
|
234
|
-
return expiresAtDate <= now;
|
|
235
|
-
})
|
|
236
|
-
.map((h) => h.contractId);
|
|
237
|
-
/* TODO: optimize input holding selection, currently if you transfer 10 CC and have 10 inputs of 1000 CC,
|
|
238
|
-
then all 10 of those are chose as input.
|
|
239
|
-
*/
|
|
240
|
-
}
|
|
422
|
+
const inputHoldingCids = await this.getInputHoldingsCids(sender, inputUtxos);
|
|
241
423
|
const choiceArgs = {
|
|
242
424
|
expectedAdmin: instrumentAdmin,
|
|
243
425
|
transfer: {
|
|
@@ -246,7 +428,7 @@ export class TokenStandardService {
|
|
|
246
428
|
amount,
|
|
247
429
|
instrumentId: { admin: instrumentAdmin, id: instrumentId },
|
|
248
430
|
lock: null,
|
|
249
|
-
requestedAt: now.toISOString(),
|
|
431
|
+
requestedAt: new Date(Date.now() - 60 * 1000).toISOString(),
|
|
250
432
|
//given expiryDate or 24 hours
|
|
251
433
|
executeBefore: (expiryDate ?? new Date(Date.now() + 24 * 60 * 60 * 1000)).toISOString(),
|
|
252
434
|
inputHoldingCids,
|
|
@@ -258,7 +440,7 @@ export class TokenStandardService {
|
|
|
258
440
|
},
|
|
259
441
|
};
|
|
260
442
|
this.logger.debug('Creating transfer factory...');
|
|
261
|
-
const transferFactory = await this.getTokenStandardClient(
|
|
443
|
+
const transferFactory = await this.getTokenStandardClient(registryUrl).post('/registry/transfer-instruction/v1/transfer-factory', {
|
|
262
444
|
choiceArguments: choiceArgs,
|
|
263
445
|
});
|
|
264
446
|
this.logger.debug(transferFactory, 'Transfer factory created');
|
|
@@ -268,7 +450,7 @@ export class TokenStandardService {
|
|
|
268
450
|
{},
|
|
269
451
|
};
|
|
270
452
|
const exercise = {
|
|
271
|
-
templateId:
|
|
453
|
+
templateId: TRANSFER_FACTORY_INTERFACE_ID,
|
|
272
454
|
contractId: transferFactory.factoryId,
|
|
273
455
|
choice: 'TransferFactory_Transfer',
|
|
274
456
|
choiceArgument: choiceArgs,
|
|
@@ -281,7 +463,7 @@ export class TokenStandardService {
|
|
|
281
463
|
}
|
|
282
464
|
}
|
|
283
465
|
async createTap(receiver, amount, instrumentAdmin, // TODO (#907): replace with registry call
|
|
284
|
-
instrumentId,
|
|
466
|
+
instrumentId, registryUrl) {
|
|
285
467
|
const now = new Date();
|
|
286
468
|
const tomorrow = new Date(now);
|
|
287
469
|
tomorrow.setDate(tomorrow.getDate() + 1);
|
|
@@ -303,7 +485,7 @@ export class TokenStandardService {
|
|
|
303
485
|
meta: { values: {} },
|
|
304
486
|
},
|
|
305
487
|
};
|
|
306
|
-
const transferFactory = await this.getTokenStandardClient(
|
|
488
|
+
const transferFactory = await this.getTokenStandardClient(registryUrl).post('/registry/transfer-instruction/v1/transfer-factory', {
|
|
307
489
|
choiceArguments: choiceArgs,
|
|
308
490
|
});
|
|
309
491
|
const disclosedContracts = transferFactory.choiceContext.disclosedContracts;
|
|
@@ -360,6 +542,13 @@ export class TokenStandardService {
|
|
|
360
542
|
[disclosedContracts],
|
|
361
543
|
];
|
|
362
544
|
}
|
|
545
|
+
async toPrettyTransactionsPerParty(updates, parties, ledgerClient) {
|
|
546
|
+
const all = await Promise.all(parties.map(async (partyId) => [
|
|
547
|
+
partyId,
|
|
548
|
+
await this.toPrettyTransactions(updates, partyId, ledgerClient),
|
|
549
|
+
]));
|
|
550
|
+
return new Map(all);
|
|
551
|
+
}
|
|
363
552
|
async toPrettyTransactions(updates, partyId, ledgerClient) {
|
|
364
553
|
// Runtime filters that also let TS know which of OneOfs types to check against
|
|
365
554
|
const isOffsetCheckpointUpdate = (updateResponse) => !!updateResponse?.update?.OffsetCheckpoint;
|
|
@@ -373,7 +562,7 @@ export class TokenStandardService {
|
|
|
373
562
|
.filter(isTransactionUpdate)
|
|
374
563
|
.map(async (update) => {
|
|
375
564
|
const tx = update.update.Transaction.value;
|
|
376
|
-
const parser = new TransactionParser(tx, ledgerClient, partyId);
|
|
565
|
+
const parser = new TransactionParser(tx, ledgerClient, partyId, this.isMasterUser);
|
|
377
566
|
return await parser.parseTransaction();
|
|
378
567
|
}));
|
|
379
568
|
return {
|
|
@@ -386,7 +575,7 @@ export class TokenStandardService {
|
|
|
386
575
|
}
|
|
387
576
|
async toPrettyTransaction(getTransactionResponse, partyId, ledgerClient) {
|
|
388
577
|
const tx = getTransactionResponse.transaction;
|
|
389
|
-
const parser = new TransactionParser(tx, ledgerClient, partyId);
|
|
578
|
+
const parser = new TransactionParser(tx, ledgerClient, partyId, this.isMasterUser);
|
|
390
579
|
const parsedTx = await parser.parseTransaction();
|
|
391
580
|
return renderTransaction(parsedTx);
|
|
392
581
|
}
|
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
import { LedgerClient } from './ledger-client.js';
|
|
2
|
-
import { SigningPublicKey, Enums_ParticipantPermission, SignedTopologyTransaction, AuthorizeResponse, GenerateTransactionsResponse } from '@canton-network/core-ledger-proto';
|
|
3
2
|
import { PartyId } from '@canton-network/core-types';
|
|
3
|
+
import { SigningPublicKey, Enums_ParticipantPermission, SignedTopologyTransaction, AuthorizeResponse, GenerateTransactionsResponse } from '@canton-network/core-ledger-proto';
|
|
4
4
|
export declare class TopologyWriteService {
|
|
5
|
+
private synchronizerId;
|
|
5
6
|
private userAdminToken;
|
|
6
7
|
private topologyClient;
|
|
7
8
|
private topologyReadService;
|
|
8
9
|
private ledgerClient;
|
|
9
|
-
private
|
|
10
|
+
private storeId;
|
|
10
11
|
constructor(synchronizerId: string, userAdminUrl: string, userAdminToken: string, ledgerClient: LedgerClient);
|
|
11
12
|
static combineHashes(hashes: Buffer[]): string;
|
|
12
|
-
static createFingerprintFromKey
|
|
13
|
+
static createFingerprintFromKey(publicKey: string): string;
|
|
14
|
+
/** @deprecated using the protobuf publickey is no longer supported -- use the string parameter instead */
|
|
15
|
+
static createFingerprintFromKey(publicKey: SigningPublicKey): string;
|
|
16
|
+
/** @deprecated using the protobuf publickey is no longer supported -- use the string parameter instead */
|
|
17
|
+
static createFingerprintFromKey(publicKey: SigningPublicKey | string): string;
|
|
18
|
+
/** @deprecated only for grpc/protobuf implementation */
|
|
13
19
|
static toSignedTopologyTransaction(txHashes: Buffer<ArrayBuffer>[], serializedTransaction: Uint8Array<ArrayBufferLike>, signature: string, namespace: string): SignedTopologyTransaction;
|
|
20
|
+
/** @deprecated */
|
|
14
21
|
private generateTransactionsRequest;
|
|
22
|
+
/** @deprecated use allocateExternalParty() instead */
|
|
15
23
|
submitExternalPartyTopology(signedTopologyTxs: SignedTopologyTransaction[], partyId: PartyId): Promise<void>;
|
|
24
|
+
/** @deprecated use generateTopology() */
|
|
16
25
|
generateTransactions(publicKey: string, partyId: PartyId, confirmingThreshold?: number, hostingParticipantRights?: Map<string, Enums_ParticipantPermission>): Promise<GenerateTransactionsResponse>;
|
|
26
|
+
/** @deprecated */
|
|
17
27
|
private addTransactions;
|
|
28
|
+
/** @deprecated */
|
|
18
29
|
waitForPartyToParticipantProposal(partyId: PartyId): Promise<Uint8Array | undefined>;
|
|
30
|
+
/** @deprecated */
|
|
19
31
|
authorizePartyToParticipant(partyId: PartyId): Promise<AuthorizeResponse>;
|
|
20
32
|
}
|
|
21
33
|
//# sourceMappingURL=topology-write-service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"topology-write-service.d.ts","sourceRoot":"","sources":["../src/topology-write-service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"topology-write-service.d.ts","sourceRoot":"","sources":["../src/topology-write-service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAIH,gBAAgB,EAOhB,2BAA2B,EAM3B,yBAAyB,EAMzB,iBAAiB,EAGjB,4BAA4B,EAK/B,MAAM,mCAAmC,CAAA;AAiC1C,qBAAa,oBAAoB;IAgBzB,OAAO,CAAC,cAAc;IAEtB,OAAO,CAAC,cAAc;IAjB1B,OAAO,CAAC,cAAc,CAAmC;IACzD,OAAO,CAAC,mBAAmB,CAAkC;IAC7D,OAAO,CAAC,YAAY,CAAc;IAElC,OAAO,CAAC,OAAO,CAQT;gBAGM,cAAc,EAAE,MAAM,EAC9B,YAAY,EAAE,MAAM,EACZ,cAAc,EAAE,MAAM,EAC9B,YAAY,EAAE,YAAY;IAc9B,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM;IAgC9C,MAAM,CAAC,wBAAwB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAC1D,0GAA0G;IAC1G,MAAM,CAAC,wBAAwB,CAAC,SAAS,EAAE,gBAAgB,GAAG,MAAM;IACpE,0GAA0G;IAC1G,MAAM,CAAC,wBAAwB,CAC3B,SAAS,EAAE,gBAAgB,GAAG,MAAM,GACrC,MAAM;IAoBT,wDAAwD;IACxD,MAAM,CAAC,2BAA2B,CAC9B,QAAQ,EAAE,MAAM,CAAC,WAAW,CAAC,EAAE,EAC/B,qBAAqB,EAAE,UAAU,CAAC,eAAe,CAAC,EAClD,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAClB,yBAAyB;IAqB5B,kBAAkB;IAClB,OAAO,CAAC,2BAA2B;IAoEnC,sDAAsD;IAChD,2BAA2B,CAC7B,iBAAiB,EAAE,yBAAyB,EAAE,EAC9C,OAAO,EAAE,OAAO;IAMpB,yCAAyC;IACnC,oBAAoB,CACtB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,OAAO,EAChB,mBAAmB,GAAE,MAAU,EAC/B,wBAAwB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,2BAA2B,CAAC,GACpE,OAAO,CAAC,4BAA4B,CAAC;IAkCxC,kBAAkB;YACJ,eAAe;IAgB7B,kBAAkB;IACZ,iCAAiC,CACnC,OAAO,EAAE,OAAO,GACjB,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAiClC,kBAAkB;IACZ,2BAA2B,CAC7B,OAAO,EAAE,OAAO,GACjB,OAAO,CAAC,iBAAiB,CAAC;CAqBhC"}
|