@canton-network/core-tx-parser 1.8.0 → 1.9.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/index.cjs +823 -950
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +799 -945
- package/dist/index.js.map +1 -1
- package/dist/parser.d.ts +10 -0
- package/dist/parser.d.ts.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +16 -16
package/dist/index.cjs
CHANGED
|
@@ -1,1008 +1,880 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var coreLedgerClientTypes = require('@canton-network/core-ledger-client-types');
|
|
5
|
-
var BigNumber = require('bignumber.js');
|
|
6
|
-
|
|
7
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
-
|
|
9
|
-
var BigNumber__default = /*#__PURE__*/_interopDefault(BigNumber);
|
|
10
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
11
4
|
var __defProp = Object.defineProperty;
|
|
12
|
-
var
|
|
13
|
-
var
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let _canton_network_core_token_standard = require("@canton-network/core-token-standard");
|
|
25
|
+
let _canton_network_core_ledger_client_types = require("@canton-network/core-ledger-client-types");
|
|
26
|
+
let bignumber_js = require("bignumber.js");
|
|
27
|
+
bignumber_js = __toESM(bignumber_js, 1);
|
|
28
|
+
//#region src/constants.ts
|
|
14
29
|
function splitInterfaceId(interfaceId) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
30
|
+
const match = /^#?([^:]+):([^:]+):([^:]+)$/.exec(interfaceId);
|
|
31
|
+
if (!match) return null;
|
|
32
|
+
const [, packageName, moduleName, entityName] = match;
|
|
33
|
+
return {
|
|
34
|
+
packageName,
|
|
35
|
+
moduleName,
|
|
36
|
+
entityName
|
|
37
|
+
};
|
|
24
38
|
}
|
|
25
39
|
function matchInterfaceIds(a, b) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
40
|
+
const aParts = splitInterfaceId(a);
|
|
41
|
+
const bParts = splitInterfaceId(b);
|
|
42
|
+
return aParts !== null && bParts !== null && aParts.moduleName === bParts.moduleName && aParts.entityName === bParts.entityName;
|
|
29
43
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
44
|
+
const TokenStandardTransactionInterfaces = [
|
|
45
|
+
_canton_network_core_token_standard.HOLDING_INTERFACE_ID,
|
|
46
|
+
_canton_network_core_token_standard.TRANSFER_FACTORY_INTERFACE_ID,
|
|
47
|
+
_canton_network_core_token_standard.TRANSFER_INSTRUCTION_INTERFACE_ID,
|
|
48
|
+
_canton_network_core_token_standard.ALLOCATION_FACTORY_INTERFACE_ID,
|
|
49
|
+
_canton_network_core_token_standard.ALLOCATION_INSTRUCTION_INTERFACE_ID,
|
|
50
|
+
_canton_network_core_token_standard.ALLOCATION_INTERFACE_ID,
|
|
51
|
+
_canton_network_core_token_standard.ALLOCATION_REQUEST_INTERFACE_ID
|
|
38
52
|
];
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
const SpliceMetaKeyPrefix = "splice.lfdecentralizedtrust.org/";
|
|
54
|
+
const TxKindMetaKey = `${SpliceMetaKeyPrefix}tx-kind`;
|
|
55
|
+
const SenderMetaKey = `${SpliceMetaKeyPrefix}sender`;
|
|
56
|
+
const ReasonMetaKey = `${SpliceMetaKeyPrefix}reason`;
|
|
57
|
+
const BurnedMetaKey = `${SpliceMetaKeyPrefix}burned`;
|
|
58
|
+
const AllKnownMetaKeys = [
|
|
59
|
+
TxKindMetaKey,
|
|
60
|
+
SenderMetaKey,
|
|
61
|
+
ReasonMetaKey,
|
|
62
|
+
BurnedMetaKey
|
|
49
63
|
];
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/utils.ts
|
|
50
66
|
function hasInterface(interfaceId, event) {
|
|
51
|
-
|
|
52
|
-
(id) => matchInterfaceIds(id, interfaceId)
|
|
53
|
-
);
|
|
67
|
+
return (event.implementedInterfaces || []).some((id) => matchInterfaceIds(id, interfaceId));
|
|
54
68
|
}
|
|
55
69
|
function getInterfaceView(createdEvent) {
|
|
56
|
-
|
|
57
|
-
|
|
70
|
+
const interfaceViews = createdEvent.interfaceViews || null;
|
|
71
|
+
return interfaceViews && interfaceViews[0] || null;
|
|
58
72
|
}
|
|
59
73
|
function getKnownInterfaceView(createdEvent) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
)) {
|
|
72
|
-
return {
|
|
73
|
-
type: "TransferInstruction",
|
|
74
|
-
viewValue: interfaceView.viewValue
|
|
75
|
-
};
|
|
76
|
-
} else {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
74
|
+
const interfaceView = getInterfaceView(createdEvent);
|
|
75
|
+
if (!interfaceView || !interfaceView.interfaceId) return null;
|
|
76
|
+
else if (matchInterfaceIds(_canton_network_core_token_standard.HOLDING_INTERFACE_ID, interfaceView.interfaceId)) return {
|
|
77
|
+
type: "Holding",
|
|
78
|
+
viewValue: interfaceView.viewValue
|
|
79
|
+
};
|
|
80
|
+
else if (matchInterfaceIds(_canton_network_core_token_standard.TRANSFER_INSTRUCTION_INTERFACE_ID, interfaceView.interfaceId)) return {
|
|
81
|
+
type: "TransferInstruction",
|
|
82
|
+
viewValue: interfaceView.viewValue
|
|
83
|
+
};
|
|
84
|
+
else return null;
|
|
79
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Use this when `createdEvent` is guaranteed to have an interface view because the ledger api filters
|
|
88
|
+
* include it, and thus is guaranteed to be returned by the API.
|
|
89
|
+
*/
|
|
80
90
|
function ensureInterfaceViewIsPresent(createdEvent, interfaceId) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
createdEvent
|
|
86
|
-
)}`
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
if (!interfaceView.interfaceId || !matchInterfaceIds(interfaceId, interfaceView.interfaceId)) {
|
|
90
|
-
throw new Error(
|
|
91
|
-
`Not a ${interfaceId} but a ${interfaceView.interfaceId}: ${JSON.stringify(createdEvent)}`
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
return interfaceView;
|
|
91
|
+
const interfaceView = getInterfaceView(createdEvent);
|
|
92
|
+
if (!interfaceView) throw new Error(`Expected to have interface views, but didn't: ${JSON.stringify(createdEvent)}`);
|
|
93
|
+
if (!interfaceView.interfaceId || !matchInterfaceIds(interfaceId, interfaceView.interfaceId)) throw new Error(`Not a ${interfaceId} but a ${interfaceView.interfaceId}: ${JSON.stringify(createdEvent)}`);
|
|
94
|
+
return interfaceView;
|
|
95
95
|
}
|
|
96
96
|
function mergeMetas(event, extra) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
} else {
|
|
115
|
-
return { values: result };
|
|
116
|
-
}
|
|
97
|
+
const choiceArgument = event.choiceArgument;
|
|
98
|
+
const lastWriteWins = [
|
|
99
|
+
choiceArgument?.transfer?.meta,
|
|
100
|
+
choiceArgument?.extraArgs?.meta,
|
|
101
|
+
choiceArgument?.meta,
|
|
102
|
+
extra,
|
|
103
|
+
event.exerciseResult?.meta
|
|
104
|
+
];
|
|
105
|
+
const result = {};
|
|
106
|
+
lastWriteWins.forEach((meta) => {
|
|
107
|
+
const values = meta?.values || {};
|
|
108
|
+
Object.entries(values).forEach(([k, v]) => {
|
|
109
|
+
result[k] = v;
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
if (Object.keys(result).length === 0) return;
|
|
113
|
+
else return { values: result };
|
|
117
114
|
}
|
|
118
115
|
function getMetaKeyValue(key, meta) {
|
|
119
|
-
|
|
116
|
+
return (meta?.values || {})[key] || null;
|
|
120
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* From the view of making it easy to build the display for the wallet,
|
|
120
|
+
* we remove all metadata fields that were fully parsed, and whose content is reflected in the TypeScript structure.
|
|
121
|
+
* Otherwise, the display code has to do so, overloading the user with superfluous metadata entries.
|
|
122
|
+
*/
|
|
121
123
|
function removeParsedMetaKeys(meta) {
|
|
122
|
-
|
|
123
|
-
values: Object.fromEntries(
|
|
124
|
-
Object.entries(meta?.values || {}).filter(
|
|
125
|
-
([k]) => !AllKnownMetaKeys.includes(k)
|
|
126
|
-
)
|
|
127
|
-
)
|
|
128
|
-
};
|
|
124
|
+
return { values: Object.fromEntries(Object.entries(meta?.values || {}).filter(([k]) => !AllKnownMetaKeys.includes(k))) };
|
|
129
125
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/types.ts
|
|
128
|
+
const renderTransaction = (t) => {
|
|
129
|
+
return {
|
|
130
|
+
...t,
|
|
131
|
+
events: t.events.map(renderTransactionEvent)
|
|
132
|
+
};
|
|
134
133
|
};
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
e.lockedHoldingsChangeSummary
|
|
150
|
-
),
|
|
151
|
-
unlockedHoldingsChangeSummaries,
|
|
152
|
-
// Deprecated
|
|
153
|
-
unlockedHoldingsChangeSummary: renderHoldingsChangeSummary(
|
|
154
|
-
e.unlockedHoldingsChangeSummary
|
|
155
|
-
)
|
|
156
|
-
};
|
|
134
|
+
const renderTransactionEvent = (e) => {
|
|
135
|
+
const lockedHoldingsChangeSummaries = e.lockedHoldingsChangeSummaries.map(renderHoldingsChangeSummary).filter((s) => s !== null);
|
|
136
|
+
const unlockedHoldingsChangeSummaries = e.unlockedHoldingsChangeSummaries.map(renderHoldingsChangeSummary).filter((s) => s !== null);
|
|
137
|
+
const lockedHoldingsChange = renderHoldingsChange(e.lockedHoldingsChange);
|
|
138
|
+
const unlockedHoldingsChange = renderHoldingsChange(e.unlockedHoldingsChange);
|
|
139
|
+
return {
|
|
140
|
+
...e,
|
|
141
|
+
lockedHoldingsChange,
|
|
142
|
+
unlockedHoldingsChange,
|
|
143
|
+
lockedHoldingsChangeSummaries,
|
|
144
|
+
lockedHoldingsChangeSummary: renderHoldingsChangeSummary(e.lockedHoldingsChangeSummary),
|
|
145
|
+
unlockedHoldingsChangeSummaries,
|
|
146
|
+
unlockedHoldingsChangeSummary: renderHoldingsChangeSummary(e.unlockedHoldingsChangeSummary)
|
|
147
|
+
};
|
|
157
148
|
};
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
...s.numOutputs !== 0 && { numOutputs: s.numOutputs },
|
|
169
|
-
...s.outputAmount !== "0" && { outputAmount: s.outputAmount },
|
|
170
|
-
...s.amountChange !== "0" && { amountChange: s.amountChange }
|
|
171
|
-
};
|
|
149
|
+
const renderHoldingsChangeSummary = (s) => {
|
|
150
|
+
if (s.numInputs === 0 && s.numOutputs === 0 && s.inputAmount === "0" && s.outputAmount === "0" && s.amountChange === "0") return null;
|
|
151
|
+
return {
|
|
152
|
+
...(s.instrumentId.admin !== "" || s.instrumentId.id !== "") && { instrumentId: s.instrumentId },
|
|
153
|
+
...s.numInputs !== 0 && { numInputs: s.numInputs },
|
|
154
|
+
...s.inputAmount !== "0" && { inputAmount: s.inputAmount },
|
|
155
|
+
...s.numOutputs !== 0 && { numOutputs: s.numOutputs },
|
|
156
|
+
...s.outputAmount !== "0" && { outputAmount: s.outputAmount },
|
|
157
|
+
...s.amountChange !== "0" && { amountChange: s.amountChange }
|
|
158
|
+
};
|
|
172
159
|
};
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
...c.archives.length !== 0 && { archives: c.archives }
|
|
180
|
-
};
|
|
160
|
+
const renderHoldingsChange = (c) => {
|
|
161
|
+
if (c.creates.length === 0 && c.archives.length === 0) return null;
|
|
162
|
+
return {
|
|
163
|
+
...c.creates.length !== 0 && { creates: c.creates },
|
|
164
|
+
...c.archives.length !== 0 && { archives: c.archives }
|
|
165
|
+
};
|
|
181
166
|
};
|
|
182
|
-
|
|
183
|
-
|
|
167
|
+
//#endregion
|
|
168
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/typeof.js
|
|
169
|
+
function _typeof(o) {
|
|
170
|
+
"@babel/helpers - typeof";
|
|
171
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
172
|
+
return typeof o;
|
|
173
|
+
} : function(o) {
|
|
174
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
175
|
+
}, _typeof(o);
|
|
176
|
+
}
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/toPrimitive.js
|
|
179
|
+
function toPrimitive(t, r) {
|
|
180
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
181
|
+
var e = t[Symbol.toPrimitive];
|
|
182
|
+
if (void 0 !== e) {
|
|
183
|
+
var i = e.call(t, r || "default");
|
|
184
|
+
if ("object" != _typeof(i)) return i;
|
|
185
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
186
|
+
}
|
|
187
|
+
return ("string" === r ? String : Number)(t);
|
|
188
|
+
}
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/toPropertyKey.js
|
|
191
|
+
function toPropertyKey(t) {
|
|
192
|
+
var i = toPrimitive(t, "string");
|
|
193
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
194
|
+
}
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/defineProperty.js
|
|
197
|
+
function _defineProperty(e, r, t) {
|
|
198
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
199
|
+
value: t,
|
|
200
|
+
enumerable: !0,
|
|
201
|
+
configurable: !0,
|
|
202
|
+
writable: !0
|
|
203
|
+
}) : e[r] = t, e;
|
|
204
|
+
}
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region src/instrumentmap.ts
|
|
207
|
+
/** InstrumentMap is a helper for when you want to group values by instrument. */
|
|
184
208
|
var InstrumentMap = class {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
209
|
+
encodeKey(instrumentId) {
|
|
210
|
+
return JSON.stringify([instrumentId.admin, instrumentId.id]);
|
|
211
|
+
}
|
|
212
|
+
decodeKey(key) {
|
|
213
|
+
const [admin, id] = JSON.parse(key);
|
|
214
|
+
return {
|
|
215
|
+
admin,
|
|
216
|
+
id
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
constructor() {
|
|
220
|
+
_defineProperty(this, "map", void 0);
|
|
221
|
+
this.map = /* @__PURE__ */ new Map();
|
|
222
|
+
}
|
|
223
|
+
set(key, value) {
|
|
224
|
+
this.map.set(this.encodeKey(key), value);
|
|
225
|
+
}
|
|
226
|
+
get(key) {
|
|
227
|
+
return this.map.get(this.encodeKey(key));
|
|
228
|
+
}
|
|
229
|
+
has(key) {
|
|
230
|
+
return this.map.has(this.encodeKey(key));
|
|
231
|
+
}
|
|
232
|
+
delete(key) {
|
|
233
|
+
return this.map.delete(this.encodeKey(key));
|
|
234
|
+
}
|
|
235
|
+
*entries() {
|
|
236
|
+
for (const [key, value] of this.map.entries()) yield [this.decodeKey(key), value];
|
|
237
|
+
}
|
|
213
238
|
};
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/parser.ts
|
|
214
241
|
function currentStatusFromChoiceOrResult(choice, resultTag) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
return "Pending";
|
|
225
|
-
default:
|
|
226
|
-
return "Pending";
|
|
227
|
-
}
|
|
242
|
+
if (resultTag === "TransferInstructionResult_Failed") return "Failed";
|
|
243
|
+
if (resultTag === "TransferInstructionResult_Completed") return "Completed";
|
|
244
|
+
switch (choice) {
|
|
245
|
+
case "TransferInstruction_Reject": return "Rejected";
|
|
246
|
+
case "TransferInstruction_Withdraw": return "Withdrawn";
|
|
247
|
+
case "TransferInstruction_Accept":
|
|
248
|
+
case "TransferInstruction_Update": return "Pending";
|
|
249
|
+
default: return "Pending";
|
|
250
|
+
}
|
|
228
251
|
}
|
|
229
252
|
function getCorrelationIdFromTransferInstruction(currentInstructionCid, originalInstructionCid) {
|
|
230
|
-
|
|
253
|
+
return originalInstructionCid ?? currentInstructionCid;
|
|
231
254
|
}
|
|
232
255
|
function getPendingTransferInstructionCid(exercisedEvent) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
return cid ?? void 0;
|
|
256
|
+
const output = exercisedEvent.exerciseResult?.output;
|
|
257
|
+
if (output?.tag !== "TransferInstructionResult_Pending") return void 0;
|
|
258
|
+
return output.value?.transferInstructionCid ?? void 0;
|
|
237
259
|
}
|
|
238
260
|
function isTransferObject(value) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
261
|
+
if (!value || typeof value !== "object") return false;
|
|
262
|
+
const v = value;
|
|
263
|
+
const instrumentId = v.instrumentId;
|
|
264
|
+
const meta = v.meta;
|
|
265
|
+
return typeof v.sender === "string" && typeof v.receiver === "string" && typeof v.amount === "string" && typeof v.requestedAt === "string" && typeof v.executeBefore === "string" && Array.isArray(v.inputHoldingCids) && v.inputHoldingCids.every((cid) => typeof cid === "string") && !!instrumentId && typeof instrumentId.admin === "string" && typeof instrumentId.id === "string" && !!meta && typeof meta.values === "object" && meta.values !== null;
|
|
244
266
|
}
|
|
245
267
|
var TransactionParser = class {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
children,
|
|
752
|
-
transferInstruction: null
|
|
753
|
-
};
|
|
754
|
-
}
|
|
755
|
-
async getChildren(exercisedEvent) {
|
|
756
|
-
const mutatingResult = { creates: [], archives: [] };
|
|
757
|
-
const childrenEventsSlice = (this.transaction.events || []).map(getNodeIdAndEvent).filter(
|
|
758
|
-
({ nodeId }) => nodeId > exercisedEvent.nodeId && nodeId <= exercisedEvent.lastDescendantNodeId
|
|
759
|
-
);
|
|
760
|
-
if (exercisedEvent.consuming && hasInterface(coreTokenStandard.HOLDING_INTERFACE_ID, exercisedEvent)) {
|
|
761
|
-
const selfEvent = await this.getEventsForArchive(exercisedEvent);
|
|
762
|
-
if (selfEvent) {
|
|
763
|
-
const holdingView = ensureInterfaceViewIsPresent(
|
|
764
|
-
selfEvent.created.createdEvent,
|
|
765
|
-
coreTokenStandard.HOLDING_INTERFACE_ID
|
|
766
|
-
).viewValue;
|
|
767
|
-
mutatingResult.archives.push({
|
|
768
|
-
amount: holdingView.amount,
|
|
769
|
-
instrumentId: holdingView.instrumentId,
|
|
770
|
-
contractId: exercisedEvent.contractId,
|
|
771
|
-
owner: holdingView.owner,
|
|
772
|
-
meta: holdingView.meta,
|
|
773
|
-
lock: holdingView.lock
|
|
774
|
-
});
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
for (const {
|
|
778
|
-
createdEvent,
|
|
779
|
-
archivedEvent,
|
|
780
|
-
exercisedEvent: exercisedEvent2
|
|
781
|
-
} of childrenEventsSlice) {
|
|
782
|
-
if (createdEvent) {
|
|
783
|
-
const interfaceView = getInterfaceView(createdEvent);
|
|
784
|
-
if (interfaceView && interfaceView.interfaceId && matchInterfaceIds(
|
|
785
|
-
coreTokenStandard.HOLDING_INTERFACE_ID,
|
|
786
|
-
interfaceView.interfaceId
|
|
787
|
-
)) {
|
|
788
|
-
const holdingView = interfaceView.viewValue;
|
|
789
|
-
mutatingResult.creates.push({
|
|
790
|
-
amount: holdingView.amount,
|
|
791
|
-
instrumentId: holdingView.instrumentId,
|
|
792
|
-
contractId: createdEvent.contractId,
|
|
793
|
-
owner: holdingView.owner,
|
|
794
|
-
meta: holdingView.meta,
|
|
795
|
-
lock: holdingView.lock
|
|
796
|
-
});
|
|
797
|
-
}
|
|
798
|
-
} else if (archivedEvent && hasInterface(coreTokenStandard.HOLDING_INTERFACE_ID, archivedEvent) || exercisedEvent2 && exercisedEvent2.consuming && hasInterface(coreTokenStandard.HOLDING_INTERFACE_ID, exercisedEvent2)) {
|
|
799
|
-
const contractEvents = await this.getEventsForArchive(
|
|
800
|
-
archivedEvent || exercisedEvent2
|
|
801
|
-
);
|
|
802
|
-
if (contractEvents) {
|
|
803
|
-
const holdingView = ensureInterfaceViewIsPresent(
|
|
804
|
-
contractEvents.created?.createdEvent,
|
|
805
|
-
coreTokenStandard.HOLDING_INTERFACE_ID
|
|
806
|
-
).viewValue;
|
|
807
|
-
mutatingResult.archives.push({
|
|
808
|
-
amount: holdingView.amount,
|
|
809
|
-
instrumentId: holdingView.instrumentId,
|
|
810
|
-
contractId: archivedEvent?.contractId || exercisedEvent2.contractId,
|
|
811
|
-
owner: holdingView.owner,
|
|
812
|
-
meta: holdingView.meta,
|
|
813
|
-
lock: holdingView.lock
|
|
814
|
-
});
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
return {
|
|
819
|
-
// remove transient contracts
|
|
820
|
-
creates: mutatingResult.creates.filter(
|
|
821
|
-
(create) => !mutatingResult.archives.some(
|
|
822
|
-
(archive) => create.contractId === archive.contractId
|
|
823
|
-
)
|
|
824
|
-
),
|
|
825
|
-
archives: mutatingResult.archives.filter(
|
|
826
|
-
(archive) => !mutatingResult.creates.some(
|
|
827
|
-
(create) => create.contractId === archive.contractId
|
|
828
|
-
)
|
|
829
|
-
)
|
|
830
|
-
};
|
|
831
|
-
}
|
|
832
|
-
async getEventsForArchive(archivedEvent) {
|
|
833
|
-
if (!(archivedEvent.witnessParties || []).includes(this.partyId)) {
|
|
834
|
-
return null;
|
|
835
|
-
}
|
|
836
|
-
const basePayload = {
|
|
837
|
-
contractId: archivedEvent.contractId,
|
|
838
|
-
eventFormat: coreLedgerClientTypes.EventFilterBySetup({
|
|
839
|
-
interfaceIds: [
|
|
840
|
-
coreTokenStandard.HOLDING_INTERFACE_ID,
|
|
841
|
-
coreTokenStandard.TRANSFER_INSTRUCTION_INTERFACE_ID
|
|
842
|
-
],
|
|
843
|
-
isMasterUser: this.isMasterUser,
|
|
844
|
-
partyId: this.partyId,
|
|
845
|
-
verbose: true
|
|
846
|
-
})
|
|
847
|
-
};
|
|
848
|
-
const events = await this.ledgerProvider.request({
|
|
849
|
-
method: "ledgerApi",
|
|
850
|
-
params: {
|
|
851
|
-
resource: "/v2/events/events-by-contract-id",
|
|
852
|
-
requestMethod: "post",
|
|
853
|
-
body: basePayload
|
|
854
|
-
}
|
|
855
|
-
}).catch((err) => {
|
|
856
|
-
if (err.code === "CONTRACT_EVENTS_NOT_FOUND") {
|
|
857
|
-
return null;
|
|
858
|
-
} else {
|
|
859
|
-
throw err;
|
|
860
|
-
}
|
|
861
|
-
});
|
|
862
|
-
if (!events) {
|
|
863
|
-
return null;
|
|
864
|
-
}
|
|
865
|
-
const created = events.created;
|
|
866
|
-
const archived = events.archived;
|
|
867
|
-
if (!created || !archived) {
|
|
868
|
-
throw new Error(
|
|
869
|
-
`Archival of ${archivedEvent.contractId} does not have a corresponding create/archive event: ${JSON.stringify(
|
|
870
|
-
events
|
|
871
|
-
)}`
|
|
872
|
-
);
|
|
873
|
-
}
|
|
874
|
-
return { created, archived };
|
|
875
|
-
}
|
|
268
|
+
constructor(ledgerProvider, transaction, partyId, isMasterUser) {
|
|
269
|
+
_defineProperty(this, "ledgerProvider", void 0);
|
|
270
|
+
_defineProperty(this, "partyId", void 0);
|
|
271
|
+
_defineProperty(this, "transaction", void 0);
|
|
272
|
+
_defineProperty(this, "isMasterUser", void 0);
|
|
273
|
+
this.ledgerProvider = ledgerProvider;
|
|
274
|
+
this.partyId = partyId;
|
|
275
|
+
this.transaction = transaction;
|
|
276
|
+
this.isMasterUser = isMasterUser;
|
|
277
|
+
}
|
|
278
|
+
async parseTransaction() {
|
|
279
|
+
const tx = this.transaction;
|
|
280
|
+
const events = await this.parseEvents([...tx.events || []].reverse());
|
|
281
|
+
return {
|
|
282
|
+
updateId: tx.updateId,
|
|
283
|
+
offset: tx.offset,
|
|
284
|
+
recordTime: tx.recordTime,
|
|
285
|
+
synchronizerId: tx.synchronizerId,
|
|
286
|
+
events
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
async parseTransferObjects() {
|
|
290
|
+
const eventsStack = [...this.transaction.events || []].reverse();
|
|
291
|
+
return await this.fetchTransferObjectChoice(eventsStack);
|
|
292
|
+
}
|
|
293
|
+
async fetchTransferObjectChoice(eventsStack) {
|
|
294
|
+
const result = [];
|
|
295
|
+
while (eventsStack.length > 0) {
|
|
296
|
+
const { exercisedEvent } = getNodeIdAndEvent(eventsStack.pop());
|
|
297
|
+
if (exercisedEvent && (exercisedEvent.choice === "TransferFactory_Transfer" || exercisedEvent.choice === "TransferRule_Transfer")) {
|
|
298
|
+
const { choiceArgument } = exercisedEvent;
|
|
299
|
+
if (choiceArgument && typeof choiceArgument === "object" && "transfer" in choiceArgument) {
|
|
300
|
+
const transfer = choiceArgument.transfer;
|
|
301
|
+
if (isTransferObject(transfer)) result.push(transfer);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return result;
|
|
306
|
+
}
|
|
307
|
+
async parseEvents(eventsStack) {
|
|
308
|
+
let callStack = [];
|
|
309
|
+
let continueAfterNodeId = -1;
|
|
310
|
+
const result = [];
|
|
311
|
+
while (eventsStack.length > 0) {
|
|
312
|
+
const currentEvent = eventsStack.pop();
|
|
313
|
+
const { nodeId, createdEvent, archivedEvent, exercisedEvent } = getNodeIdAndEvent(currentEvent);
|
|
314
|
+
callStack = callStack.filter((s) => s.untilNodeId <= nodeId);
|
|
315
|
+
const parentChoice = callStack[callStack.length - 1] && callStack[callStack.length - 1].parentChoiceName || "none (root node)";
|
|
316
|
+
let parsed;
|
|
317
|
+
if (nodeId <= continueAfterNodeId) parsed = null;
|
|
318
|
+
else if (createdEvent) parsed = this.parseRawCreate(createdEvent, parentChoice);
|
|
319
|
+
else if (archivedEvent) parsed = await this.parseRawArchive(archivedEvent, parentChoice);
|
|
320
|
+
else if (exercisedEvent) parsed = await this.parseExercise(exercisedEvent);
|
|
321
|
+
else throw new Error(`Impossible event: ${JSON.stringify(currentEvent)}`);
|
|
322
|
+
if (parsed && isLeafEventNode(parsed)) {
|
|
323
|
+
if (holdingChangesNonEmpty(parsed.event) || parsed.event.transferInstruction?.transfer != null) result.push({
|
|
324
|
+
...parsed.event,
|
|
325
|
+
label: {
|
|
326
|
+
...parsed.event.label,
|
|
327
|
+
meta: removeParsedMetaKeys(parsed.event.label.meta)
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
continueAfterNodeId = parsed.continueAfterNodeId;
|
|
331
|
+
} else if (parsed) callStack.push({
|
|
332
|
+
parentChoiceName: parsed.parentChoiceName,
|
|
333
|
+
untilNodeId: parsed.lastDescendantNodeId
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
return result;
|
|
337
|
+
}
|
|
338
|
+
parseRawCreate(create, parentChoice) {
|
|
339
|
+
return this.buildRawEvent(create, create.nodeId, (result) => {
|
|
340
|
+
return {
|
|
341
|
+
type: Number(result.lockedHoldingsChangeSummaries[0]?.amountChange) > 0 ? "Lock" : "Create",
|
|
342
|
+
parentChoice,
|
|
343
|
+
contractId: create.contractId,
|
|
344
|
+
offset: create.offset,
|
|
345
|
+
templateId: create.templateId,
|
|
346
|
+
payload: result.payload,
|
|
347
|
+
packageName: create.packageName,
|
|
348
|
+
meta: void 0
|
|
349
|
+
};
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
async parseRawArchive(archive, parentChoice) {
|
|
353
|
+
const events = await this.getEventsForArchive(archive);
|
|
354
|
+
if (!events) return null;
|
|
355
|
+
return this.buildRawEvent(events.created.createdEvent, archive.nodeId, (result) => {
|
|
356
|
+
return {
|
|
357
|
+
type: "Archive",
|
|
358
|
+
parentChoice,
|
|
359
|
+
contractId: archive.contractId,
|
|
360
|
+
offset: archive.offset,
|
|
361
|
+
templateId: archive.templateId ?? "",
|
|
362
|
+
packageName: archive.packageName,
|
|
363
|
+
actingParties: archive.actingParties || [],
|
|
364
|
+
payload: result.payload,
|
|
365
|
+
meta: void 0
|
|
366
|
+
};
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
buildRawEvent(originalCreate, nodeId, buildLabel) {
|
|
370
|
+
const view = getKnownInterfaceView(originalCreate);
|
|
371
|
+
let result;
|
|
372
|
+
switch (view?.type) {
|
|
373
|
+
case "Holding": {
|
|
374
|
+
const holdingView = view.viewValue;
|
|
375
|
+
if (this.partyId !== holdingView.owner) result = null;
|
|
376
|
+
else {
|
|
377
|
+
const isLocked = !!holdingView.lock;
|
|
378
|
+
const summary = {
|
|
379
|
+
instrumentId: holdingView.instrumentId,
|
|
380
|
+
amountChange: holdingView.amount,
|
|
381
|
+
numInputs: 0,
|
|
382
|
+
inputAmount: "0",
|
|
383
|
+
numOutputs: 1,
|
|
384
|
+
outputAmount: holdingView.amount
|
|
385
|
+
};
|
|
386
|
+
const lockedHoldingsChangeSummaries = isLocked ? [summary] : [];
|
|
387
|
+
const unlockedHoldingsChangeSummaries = isLocked ? [] : [summary];
|
|
388
|
+
result = {
|
|
389
|
+
payload: holdingView,
|
|
390
|
+
unlockedHoldingsChange: {
|
|
391
|
+
creates: isLocked ? [] : [holdingView],
|
|
392
|
+
archives: []
|
|
393
|
+
},
|
|
394
|
+
lockedHoldingsChange: {
|
|
395
|
+
creates: isLocked ? [holdingView] : [],
|
|
396
|
+
archives: []
|
|
397
|
+
},
|
|
398
|
+
lockedHoldingsChangeSummaries,
|
|
399
|
+
lockedHoldingsChangeSummary: lockedHoldingsChangeSummaries[0] ?? emptyHoldingsChangeSummary,
|
|
400
|
+
unlockedHoldingsChangeSummaries,
|
|
401
|
+
unlockedHoldingsChangeSummary: unlockedHoldingsChangeSummaries[0] ?? emptyHoldingsChangeSummary,
|
|
402
|
+
transferInstruction: null
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
case "TransferInstruction": {
|
|
408
|
+
const transferInstructionView = view.viewValue;
|
|
409
|
+
if (![transferInstructionView.transfer.sender, transferInstructionView.transfer.receiver].some((stakeholder) => stakeholder === this.partyId)) result = null;
|
|
410
|
+
else {
|
|
411
|
+
const multiStepCorrelationId = getCorrelationIdFromTransferInstruction(originalCreate.contractId, transferInstructionView.originalInstructionCid ?? null);
|
|
412
|
+
result = {
|
|
413
|
+
payload: transferInstructionView,
|
|
414
|
+
transferInstruction: {
|
|
415
|
+
originalInstructionCid: transferInstructionView.originalInstructionCid,
|
|
416
|
+
transfer: transferInstructionView.transfer,
|
|
417
|
+
meta: transferInstructionView.meta,
|
|
418
|
+
status: {
|
|
419
|
+
before: transferInstructionView.status,
|
|
420
|
+
current: {
|
|
421
|
+
tag: "Pending",
|
|
422
|
+
value: {}
|
|
423
|
+
}
|
|
424
|
+
},
|
|
425
|
+
multiStepCorrelationId
|
|
426
|
+
},
|
|
427
|
+
unlockedHoldingsChange: {
|
|
428
|
+
creates: [],
|
|
429
|
+
archives: []
|
|
430
|
+
},
|
|
431
|
+
lockedHoldingsChange: {
|
|
432
|
+
creates: [],
|
|
433
|
+
archives: []
|
|
434
|
+
},
|
|
435
|
+
unlockedHoldingsChangeSummaries: [],
|
|
436
|
+
unlockedHoldingsChangeSummary: emptyHoldingsChangeSummary,
|
|
437
|
+
lockedHoldingsChangeSummaries: [],
|
|
438
|
+
lockedHoldingsChangeSummary: emptyHoldingsChangeSummary
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
443
|
+
default: result = null;
|
|
444
|
+
}
|
|
445
|
+
return result && {
|
|
446
|
+
continueAfterNodeId: nodeId,
|
|
447
|
+
event: {
|
|
448
|
+
label: buildLabel(result),
|
|
449
|
+
unlockedHoldingsChange: result.unlockedHoldingsChange,
|
|
450
|
+
lockedHoldingsChange: result.lockedHoldingsChange,
|
|
451
|
+
lockedHoldingsChangeSummaries: result.lockedHoldingsChangeSummaries,
|
|
452
|
+
lockedHoldingsChangeSummary: result.lockedHoldingsChangeSummary,
|
|
453
|
+
unlockedHoldingsChangeSummaries: result.unlockedHoldingsChangeSummaries,
|
|
454
|
+
unlockedHoldingsChangeSummary: result.unlockedHoldingsChangeSummary,
|
|
455
|
+
transferInstruction: result.transferInstruction
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
async parseExercise(exercise) {
|
|
460
|
+
let result = null;
|
|
461
|
+
const tokenStandardChoice = {
|
|
462
|
+
name: exercise.choice,
|
|
463
|
+
choiceArgument: exercise.choiceArgument,
|
|
464
|
+
exerciseResult: exercise.exerciseResult
|
|
465
|
+
};
|
|
466
|
+
switch (exercise.choice) {
|
|
467
|
+
case "TransferRule_Transfer":
|
|
468
|
+
case "TransferFactory_Transfer":
|
|
469
|
+
case "AllocationFactory_Allocate":
|
|
470
|
+
case "Allocation_ExecuteTransfer":
|
|
471
|
+
result = await this.buildTransfer(exercise, tokenStandardChoice);
|
|
472
|
+
break;
|
|
473
|
+
case "Allocation_Withdraw":
|
|
474
|
+
case "Allocation_Cancel":
|
|
475
|
+
result = await this.buildBasic(exercise, "Unlock", tokenStandardChoice);
|
|
476
|
+
break;
|
|
477
|
+
case "TransferInstruction_Accept":
|
|
478
|
+
case "TransferInstruction_Reject":
|
|
479
|
+
case "TransferInstruction_Withdraw":
|
|
480
|
+
case "TransferInstruction_Update":
|
|
481
|
+
result = await this.buildFromTransferInstructionExercise(exercise, tokenStandardChoice);
|
|
482
|
+
break;
|
|
483
|
+
case "BurnMintFactory_BurnMint":
|
|
484
|
+
result = await this.buildMergeSplit(exercise, tokenStandardChoice);
|
|
485
|
+
break;
|
|
486
|
+
default: {
|
|
487
|
+
const meta = mergeMetas(exercise);
|
|
488
|
+
const txKind = getMetaKeyValue(TxKindMetaKey, meta);
|
|
489
|
+
if (txKind) result = await this.parseViaTxKind(exercise, txKind);
|
|
490
|
+
break;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
if (!result) return {
|
|
494
|
+
lastDescendantNodeId: exercise.lastDescendantNodeId,
|
|
495
|
+
parentChoiceName: exercise.choice
|
|
496
|
+
};
|
|
497
|
+
else {
|
|
498
|
+
const lockedHoldingsChange = {
|
|
499
|
+
creates: result.children.creates.filter((h) => !!h.lock && h.owner === this.partyId),
|
|
500
|
+
archives: result.children.archives.filter((h) => !!h.lock && h.owner === this.partyId)
|
|
501
|
+
};
|
|
502
|
+
const unlockedHoldingsChange = {
|
|
503
|
+
creates: result.children.creates.filter((h) => !h.lock && h.owner === this.partyId),
|
|
504
|
+
archives: result.children.archives.filter((h) => !h.lock && h.owner === this.partyId)
|
|
505
|
+
};
|
|
506
|
+
const lockedHoldingsChangeSummaries = computeSummaries(lockedHoldingsChange, this.partyId);
|
|
507
|
+
const unlockedHoldingsChangeSummaries = computeSummaries(unlockedHoldingsChange, this.partyId);
|
|
508
|
+
return {
|
|
509
|
+
event: {
|
|
510
|
+
label: result.label,
|
|
511
|
+
lockedHoldingsChange,
|
|
512
|
+
lockedHoldingsChangeSummaries,
|
|
513
|
+
lockedHoldingsChangeSummary: lockedHoldingsChangeSummaries[0] ?? emptyHoldingsChangeSummary,
|
|
514
|
+
unlockedHoldingsChange,
|
|
515
|
+
unlockedHoldingsChangeSummaries,
|
|
516
|
+
unlockedHoldingsChangeSummary: unlockedHoldingsChangeSummaries[0] ?? emptyHoldingsChangeSummary,
|
|
517
|
+
transferInstruction: result.transferInstruction
|
|
518
|
+
},
|
|
519
|
+
continueAfterNodeId: exercise.lastDescendantNodeId
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
async parseViaTxKind(exercisedEvent, txKind) {
|
|
524
|
+
switch (txKind) {
|
|
525
|
+
case "transfer": return await this.buildTransfer(exercisedEvent, null);
|
|
526
|
+
case "merge-split":
|
|
527
|
+
case "burn":
|
|
528
|
+
case "mint": return await this.buildMergeSplit(exercisedEvent, null);
|
|
529
|
+
case "unlock": return await this.buildBasic(exercisedEvent, "Unlock", null);
|
|
530
|
+
case "expire-dust": return await this.buildBasic(exercisedEvent, "ExpireDust", null);
|
|
531
|
+
default: throw new Error(`Unknown tx-kind '${txKind}' in ${JSON.stringify(exercisedEvent)}`);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
async buildTransfer(exercisedEvent, tokenStandardChoice, transferInstructions) {
|
|
535
|
+
const meta = mergeMetas(exercisedEvent, transferInstructions?.transfer?.meta);
|
|
536
|
+
const reason = getMetaKeyValue(ReasonMetaKey, meta);
|
|
537
|
+
const rawTransferArg = exercisedEvent.choiceArgument.transfer;
|
|
538
|
+
const choiceArgumentTransfer = rawTransferArg?.receiver != null && rawTransferArg?.amount != null ? rawTransferArg : void 0;
|
|
539
|
+
const sender = transferInstructions?.transfer?.sender || getMetaKeyValue(SenderMetaKey, meta) || rawTransferArg?.sender;
|
|
540
|
+
if (!sender) {
|
|
541
|
+
console.error(`Malformed transfer didn't contain sender. Will instead attempt to parse the children.
|
|
542
|
+
Transfer: ${JSON.stringify(exercisedEvent)}`);
|
|
543
|
+
return null;
|
|
544
|
+
}
|
|
545
|
+
const resultTag = exercisedEvent.exerciseResult?.output?.tag || void 0;
|
|
546
|
+
const pendingCid = getPendingTransferInstructionCid(exercisedEvent);
|
|
547
|
+
const currentTag = currentStatusFromChoiceOrResult(exercisedEvent.choice, resultTag);
|
|
548
|
+
const children = await this.getChildren(exercisedEvent);
|
|
549
|
+
const receiverAmounts = /* @__PURE__ */ new Map();
|
|
550
|
+
children.creates.filter((h) => h.owner !== sender).forEach((holding) => receiverAmounts.set(holding.owner, (receiverAmounts.get(holding.owner) || (0, bignumber_js.default)("0")).plus((0, bignumber_js.default)(holding.amount))));
|
|
551
|
+
const amountChanges = computeAmountChanges(children, meta, this.partyId);
|
|
552
|
+
let label;
|
|
553
|
+
if (receiverAmounts.size === 0) label = {
|
|
554
|
+
...amountChanges,
|
|
555
|
+
type: "MergeSplit",
|
|
556
|
+
tokenStandardChoice,
|
|
557
|
+
reason,
|
|
558
|
+
meta
|
|
559
|
+
};
|
|
560
|
+
else if (sender === this.partyId) label = {
|
|
561
|
+
...amountChanges,
|
|
562
|
+
type: "TransferOut",
|
|
563
|
+
receiverAmounts: [...receiverAmounts].map(([k, v]) => {
|
|
564
|
+
return {
|
|
565
|
+
receiver: k,
|
|
566
|
+
amount: v.toString()
|
|
567
|
+
};
|
|
568
|
+
}),
|
|
569
|
+
tokenStandardChoice,
|
|
570
|
+
reason,
|
|
571
|
+
meta
|
|
572
|
+
};
|
|
573
|
+
else label = {
|
|
574
|
+
type: "TransferIn",
|
|
575
|
+
burnAmount: "0",
|
|
576
|
+
mintAmount: "0",
|
|
577
|
+
sender,
|
|
578
|
+
tokenStandardChoice,
|
|
579
|
+
reason,
|
|
580
|
+
meta
|
|
581
|
+
};
|
|
582
|
+
if (transferInstructions) {
|
|
583
|
+
transferInstructions.status.current = transferInstructions.status.current || {
|
|
584
|
+
tag: currentTag,
|
|
585
|
+
value: {}
|
|
586
|
+
};
|
|
587
|
+
return {
|
|
588
|
+
label,
|
|
589
|
+
children,
|
|
590
|
+
transferInstruction: transferInstructions
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
const transferInstruction = {
|
|
594
|
+
originalInstructionCid: null,
|
|
595
|
+
...choiceArgumentTransfer !== void 0 && { transfer: choiceArgumentTransfer },
|
|
596
|
+
status: {
|
|
597
|
+
before: null,
|
|
598
|
+
current: {
|
|
599
|
+
tag: currentTag,
|
|
600
|
+
value: {}
|
|
601
|
+
}
|
|
602
|
+
},
|
|
603
|
+
meta: null,
|
|
604
|
+
...pendingCid ? { multiStepCorrelationId: pendingCid } : {}
|
|
605
|
+
};
|
|
606
|
+
return {
|
|
607
|
+
label,
|
|
608
|
+
children,
|
|
609
|
+
transferInstruction
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
async buildMergeSplit(exercisedEvent, tokenStandardChoice) {
|
|
613
|
+
let type;
|
|
614
|
+
const meta = mergeMetas(exercisedEvent);
|
|
615
|
+
switch (getMetaKeyValue(TxKindMetaKey, meta)) {
|
|
616
|
+
case "burn":
|
|
617
|
+
type = "Burn";
|
|
618
|
+
break;
|
|
619
|
+
case "mint":
|
|
620
|
+
type = "Mint";
|
|
621
|
+
break;
|
|
622
|
+
default: type = "MergeSplit";
|
|
623
|
+
}
|
|
624
|
+
const reason = getMetaKeyValue(ReasonMetaKey, meta);
|
|
625
|
+
const children = await this.getChildren(exercisedEvent);
|
|
626
|
+
return {
|
|
627
|
+
label: {
|
|
628
|
+
...computeAmountChanges(children, meta, this.partyId),
|
|
629
|
+
type,
|
|
630
|
+
tokenStandardChoice,
|
|
631
|
+
reason,
|
|
632
|
+
meta
|
|
633
|
+
},
|
|
634
|
+
children,
|
|
635
|
+
transferInstruction: null
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
async buildFromTransferInstructionExercise(exercisedEvent, tokenStandardChoice) {
|
|
639
|
+
const instructionCid = exercisedEvent.contractId;
|
|
640
|
+
const transferInstructionEvents = await this.getEventsForArchive(exercisedEvent);
|
|
641
|
+
if (!transferInstructionEvents) return null;
|
|
642
|
+
const transferInstructionView = ensureInterfaceViewIsPresent(transferInstructionEvents.created.createdEvent, _canton_network_core_token_standard.TRANSFER_INSTRUCTION_INTERFACE_ID).viewValue;
|
|
643
|
+
const multiStepCorrelationId = getCorrelationIdFromTransferInstruction(instructionCid, transferInstructionView.originalInstructionCid ?? null);
|
|
644
|
+
const resultTag = exercisedEvent.exerciseResult?.output?.tag || void 0;
|
|
645
|
+
const currentTag = currentStatusFromChoiceOrResult(exercisedEvent.choice, resultTag);
|
|
646
|
+
const transferInstruction = {
|
|
647
|
+
originalInstructionCid: transferInstructionView.originalInstructionCid,
|
|
648
|
+
multiStepCorrelationId,
|
|
649
|
+
transfer: transferInstructionView.transfer,
|
|
650
|
+
meta: transferInstructionView.meta,
|
|
651
|
+
status: {
|
|
652
|
+
before: transferInstructionView.status,
|
|
653
|
+
current: {
|
|
654
|
+
tag: currentTag,
|
|
655
|
+
value: {}
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
const exerciseResultOutputTag = resultTag;
|
|
660
|
+
const result = await (async () => {
|
|
661
|
+
switch (exerciseResultOutputTag) {
|
|
662
|
+
case "TransferInstructionResult_Failed":
|
|
663
|
+
case "TransferInstructionResult_Pending": return this.buildMergeSplit(exercisedEvent, tokenStandardChoice);
|
|
664
|
+
case "TransferInstructionResult_Completed": return this.buildTransfer(exercisedEvent, tokenStandardChoice, transferInstruction);
|
|
665
|
+
default: throw new Error(`Unknown TransferInstructionResult: ${exerciseResultOutputTag}`);
|
|
666
|
+
}
|
|
667
|
+
})();
|
|
668
|
+
return result && {
|
|
669
|
+
...result,
|
|
670
|
+
transferInstruction
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
async buildBasic(exercisedEvent, type, tokenStandardChoice) {
|
|
674
|
+
const children = await this.getChildren(exercisedEvent);
|
|
675
|
+
const meta = mergeMetas(exercisedEvent);
|
|
676
|
+
const amountChanges = computeAmountChanges(children, meta, this.partyId);
|
|
677
|
+
const reason = getMetaKeyValue(ReasonMetaKey, meta);
|
|
678
|
+
return {
|
|
679
|
+
label: {
|
|
680
|
+
...amountChanges,
|
|
681
|
+
type,
|
|
682
|
+
tokenStandardChoice,
|
|
683
|
+
reason,
|
|
684
|
+
meta
|
|
685
|
+
},
|
|
686
|
+
children,
|
|
687
|
+
transferInstruction: null
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
async getChildren(exercisedEvent) {
|
|
691
|
+
const mutatingResult = {
|
|
692
|
+
creates: [],
|
|
693
|
+
archives: []
|
|
694
|
+
};
|
|
695
|
+
const childrenEventsSlice = (this.transaction.events || []).map(getNodeIdAndEvent).filter(({ nodeId }) => nodeId > exercisedEvent.nodeId && nodeId <= exercisedEvent.lastDescendantNodeId);
|
|
696
|
+
if (exercisedEvent.consuming && hasInterface(_canton_network_core_token_standard.HOLDING_INTERFACE_ID, exercisedEvent)) {
|
|
697
|
+
const selfEvent = await this.getEventsForArchive(exercisedEvent);
|
|
698
|
+
if (selfEvent) {
|
|
699
|
+
const holdingView = ensureInterfaceViewIsPresent(selfEvent.created.createdEvent, _canton_network_core_token_standard.HOLDING_INTERFACE_ID).viewValue;
|
|
700
|
+
mutatingResult.archives.push({
|
|
701
|
+
amount: holdingView.amount,
|
|
702
|
+
instrumentId: holdingView.instrumentId,
|
|
703
|
+
contractId: exercisedEvent.contractId,
|
|
704
|
+
owner: holdingView.owner,
|
|
705
|
+
meta: holdingView.meta,
|
|
706
|
+
lock: holdingView.lock
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
for (const { createdEvent, archivedEvent, exercisedEvent } of childrenEventsSlice) if (createdEvent) {
|
|
711
|
+
const interfaceView = getInterfaceView(createdEvent);
|
|
712
|
+
if (interfaceView && interfaceView.interfaceId && matchInterfaceIds(_canton_network_core_token_standard.HOLDING_INTERFACE_ID, interfaceView.interfaceId)) {
|
|
713
|
+
const holdingView = interfaceView.viewValue;
|
|
714
|
+
mutatingResult.creates.push({
|
|
715
|
+
amount: holdingView.amount,
|
|
716
|
+
instrumentId: holdingView.instrumentId,
|
|
717
|
+
contractId: createdEvent.contractId,
|
|
718
|
+
owner: holdingView.owner,
|
|
719
|
+
meta: holdingView.meta,
|
|
720
|
+
lock: holdingView.lock
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
} else if (archivedEvent && hasInterface(_canton_network_core_token_standard.HOLDING_INTERFACE_ID, archivedEvent) || exercisedEvent && exercisedEvent.consuming && hasInterface(_canton_network_core_token_standard.HOLDING_INTERFACE_ID, exercisedEvent)) {
|
|
724
|
+
const contractEvents = await this.getEventsForArchive(archivedEvent || exercisedEvent);
|
|
725
|
+
if (contractEvents) {
|
|
726
|
+
const holdingView = ensureInterfaceViewIsPresent(contractEvents.created?.createdEvent, _canton_network_core_token_standard.HOLDING_INTERFACE_ID).viewValue;
|
|
727
|
+
mutatingResult.archives.push({
|
|
728
|
+
amount: holdingView.amount,
|
|
729
|
+
instrumentId: holdingView.instrumentId,
|
|
730
|
+
contractId: archivedEvent?.contractId || exercisedEvent.contractId,
|
|
731
|
+
owner: holdingView.owner,
|
|
732
|
+
meta: holdingView.meta,
|
|
733
|
+
lock: holdingView.lock
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
return {
|
|
738
|
+
creates: mutatingResult.creates.filter((create) => !mutatingResult.archives.some((archive) => create.contractId === archive.contractId)),
|
|
739
|
+
archives: mutatingResult.archives.filter((archive) => !mutatingResult.creates.some((create) => create.contractId === archive.contractId))
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
async getEventsForArchive(archivedEvent) {
|
|
743
|
+
if (!(archivedEvent.witnessParties || []).includes(this.partyId)) return null;
|
|
744
|
+
const basePayload = {
|
|
745
|
+
contractId: archivedEvent.contractId,
|
|
746
|
+
eventFormat: (0, _canton_network_core_ledger_client_types.EventFilterBySetup)({
|
|
747
|
+
interfaceIds: [_canton_network_core_token_standard.HOLDING_INTERFACE_ID, _canton_network_core_token_standard.TRANSFER_INSTRUCTION_INTERFACE_ID],
|
|
748
|
+
isMasterUser: this.isMasterUser,
|
|
749
|
+
partyId: this.partyId,
|
|
750
|
+
verbose: true
|
|
751
|
+
})
|
|
752
|
+
};
|
|
753
|
+
const events = await this.ledgerProvider.request({
|
|
754
|
+
method: "ledgerApi",
|
|
755
|
+
params: {
|
|
756
|
+
resource: "/v2/events/events-by-contract-id",
|
|
757
|
+
requestMethod: "post",
|
|
758
|
+
body: basePayload
|
|
759
|
+
}
|
|
760
|
+
}).catch((err) => {
|
|
761
|
+
if (isContractEventsNotFoundError(err)) return null;
|
|
762
|
+
else throw err;
|
|
763
|
+
});
|
|
764
|
+
if (!events) return null;
|
|
765
|
+
const created = events.created;
|
|
766
|
+
const archived = events.archived;
|
|
767
|
+
if (!created || !archived) throw new Error(`Archival of ${archivedEvent.contractId} does not have a corresponding create/archive event: ${JSON.stringify(events)}`);
|
|
768
|
+
return {
|
|
769
|
+
created,
|
|
770
|
+
archived
|
|
771
|
+
};
|
|
772
|
+
}
|
|
876
773
|
};
|
|
877
774
|
function isLeafEventNode(result) {
|
|
878
|
-
|
|
775
|
+
return !!result.event;
|
|
879
776
|
}
|
|
880
777
|
function getNodeIdAndEvent(event) {
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
} else if ("ArchivedEvent" in event) {
|
|
899
|
-
return {
|
|
900
|
-
nodeId: event.ArchivedEvent.nodeId,
|
|
901
|
-
archivedEvent: event.ArchivedEvent
|
|
902
|
-
};
|
|
903
|
-
} else {
|
|
904
|
-
throw new Error(`Impossible event type: ${event}`);
|
|
905
|
-
}
|
|
778
|
+
if ("ExercisedEvent" in event) if (event.ExercisedEvent.choice === "Archive") return {
|
|
779
|
+
nodeId: event.ExercisedEvent.nodeId,
|
|
780
|
+
archivedEvent: event.ExercisedEvent
|
|
781
|
+
};
|
|
782
|
+
else return {
|
|
783
|
+
nodeId: event.ExercisedEvent.nodeId,
|
|
784
|
+
exercisedEvent: event.ExercisedEvent
|
|
785
|
+
};
|
|
786
|
+
else if ("CreatedEvent" in event) return {
|
|
787
|
+
nodeId: event.CreatedEvent.nodeId,
|
|
788
|
+
createdEvent: event.CreatedEvent
|
|
789
|
+
};
|
|
790
|
+
else if ("ArchivedEvent" in event) return {
|
|
791
|
+
nodeId: event.ArchivedEvent.nodeId,
|
|
792
|
+
archivedEvent: event.ArchivedEvent
|
|
793
|
+
};
|
|
794
|
+
else throw new Error(`Impossible event type: ${event}`);
|
|
906
795
|
}
|
|
796
|
+
/** sumHoldingsChange sums all the changes over a number of holdings.
|
|
797
|
+
* Note that this function currently assumes all holdings use the same
|
|
798
|
+
* instrument. */
|
|
907
799
|
function sumHoldingsChange(change, filter) {
|
|
908
|
-
|
|
909
|
-
change.creates.filter((create) => filter(create.owner, create.lock))
|
|
910
|
-
).minus(
|
|
911
|
-
sumHoldings(
|
|
912
|
-
change.archives.filter(
|
|
913
|
-
(archive) => filter(archive.owner, archive.lock)
|
|
914
|
-
)
|
|
915
|
-
)
|
|
916
|
-
);
|
|
800
|
+
return sumHoldings(change.creates.filter((create) => filter(create.owner, create.lock))).minus(sumHoldings(change.archives.filter((archive) => filter(archive.owner, archive.lock))));
|
|
917
801
|
}
|
|
918
802
|
function sumHoldings(holdings) {
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
`Attempted to call sumHoldings on heterogeneous instruments: ${JSON.stringify(instrumentId)} != ${JSON.stringify(holding.instrumentId)}`
|
|
925
|
-
);
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
return BigNumber__default.default.sum(
|
|
930
|
-
...holdings.map((h) => h.amount).concat(["0"])
|
|
931
|
-
// avoid NaN
|
|
932
|
-
);
|
|
803
|
+
if (holdings.length > 0) {
|
|
804
|
+
const instrumentId = holdings[0].instrumentId;
|
|
805
|
+
for (const holding of holdings) if (holding.instrumentId.admin !== instrumentId.admin || holding.instrumentId.id !== instrumentId.id) throw new Error(`Attempted to call sumHoldings on heterogeneous instruments: ${JSON.stringify(instrumentId)} != ${JSON.stringify(holding.instrumentId)}`);
|
|
806
|
+
}
|
|
807
|
+
return bignumber_js.default.sum(...holdings.map((h) => h.amount).concat(["0"]));
|
|
933
808
|
}
|
|
934
809
|
function computeAmountChanges(children, meta, partyId) {
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
);
|
|
944
|
-
const mintAmount = partyHoldingAmountChange.plus(burnAmount).plus(otherPartiesHoldingAmountChange);
|
|
945
|
-
return {
|
|
946
|
-
burnAmount: burnAmount.toString(),
|
|
947
|
-
mintAmount: mintAmount.toString()
|
|
948
|
-
};
|
|
810
|
+
const burnAmount = (0, bignumber_js.default)(getMetaKeyValue(BurnedMetaKey, meta) || "0");
|
|
811
|
+
const partyHoldingAmountChange = sumHoldingsChange(children, (owner) => owner === partyId);
|
|
812
|
+
const otherPartiesHoldingAmountChange = sumHoldingsChange(children, (owner) => owner !== partyId);
|
|
813
|
+
const mintAmount = partyHoldingAmountChange.plus(burnAmount).plus(otherPartiesHoldingAmountChange);
|
|
814
|
+
return {
|
|
815
|
+
burnAmount: burnAmount.toString(),
|
|
816
|
+
mintAmount: mintAmount.toString()
|
|
817
|
+
};
|
|
949
818
|
}
|
|
950
819
|
function computeSummary(instrumentId, changes, partyId) {
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
numInputs: changes.archives.length,
|
|
963
|
-
inputAmount: inputAmount.toString()
|
|
964
|
-
};
|
|
820
|
+
const amountChange = sumHoldingsChange(changes, (owner) => owner === partyId);
|
|
821
|
+
const outputAmount = sumHoldings(changes.creates);
|
|
822
|
+
const inputAmount = sumHoldings(changes.archives);
|
|
823
|
+
return {
|
|
824
|
+
instrumentId,
|
|
825
|
+
amountChange: amountChange.toString(),
|
|
826
|
+
numOutputs: changes.creates.length,
|
|
827
|
+
outputAmount: outputAmount.toString(),
|
|
828
|
+
numInputs: changes.archives.length,
|
|
829
|
+
inputAmount: inputAmount.toString()
|
|
830
|
+
};
|
|
965
831
|
}
|
|
966
832
|
function holdingsChangeByInstrument(changes) {
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
map.set(archive.instrumentId, { creates: [], archives: [archive] });
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
return map;
|
|
833
|
+
const map = new InstrumentMap();
|
|
834
|
+
for (const create of changes.creates) if (map.has(create.instrumentId)) map.get(create.instrumentId).creates.push(create);
|
|
835
|
+
else map.set(create.instrumentId, {
|
|
836
|
+
creates: [create],
|
|
837
|
+
archives: []
|
|
838
|
+
});
|
|
839
|
+
for (const archive of changes.archives) if (map.has(archive.instrumentId)) map.get(archive.instrumentId).archives.push(archive);
|
|
840
|
+
else map.set(archive.instrumentId, {
|
|
841
|
+
creates: [],
|
|
842
|
+
archives: [archive]
|
|
843
|
+
});
|
|
844
|
+
return map;
|
|
983
845
|
}
|
|
984
846
|
function computeSummaries(changes, partyId) {
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
847
|
+
return [...holdingsChangeByInstrument(changes).entries()].map(([instrumentId, change]) => computeSummary(instrumentId, change, partyId));
|
|
848
|
+
}
|
|
849
|
+
const CONTRACT_EVENTS_NOT_FOUND = "CONTRACT_EVENTS_NOT_FOUND";
|
|
850
|
+
/** Detects the ledger API CONTRACT_EVENTS_NOT_FOUND error across the
|
|
851
|
+
* different error shapes thrown by the various provider/transport stacks:
|
|
852
|
+
* - JsCantonError from a direct ledger client:
|
|
853
|
+
* `{ code: 'CONTRACT_EVENTS_NOT_FOUND', cause, ... }`
|
|
854
|
+
* - JSON-RPC error response (e.g. wallet gateway over HTTP):
|
|
855
|
+
* `{ error: { code, message, data: JsCantonError } }`
|
|
856
|
+
* - JSON-RPC error object (e.g. extension window transport):
|
|
857
|
+
* `{ code, message, data: JsCantonError }`
|
|
858
|
+
* - As a last resort, a stringified error body containing the code. */
|
|
859
|
+
function isContractEventsNotFoundError(err) {
|
|
860
|
+
const e = err;
|
|
861
|
+
return e?.code === CONTRACT_EVENTS_NOT_FOUND || e?.data?.code === CONTRACT_EVENTS_NOT_FOUND || e?.error?.data?.code === CONTRACT_EVENTS_NOT_FOUND || typeof e?.error?.data === "string" && e.error.data.includes(CONTRACT_EVENTS_NOT_FOUND);
|
|
989
862
|
}
|
|
990
863
|
function holdingChangesNonEmpty(event) {
|
|
991
|
-
|
|
864
|
+
return event.unlockedHoldingsChange.creates.length > 0 || event.unlockedHoldingsChange.archives.length > 0 || event.lockedHoldingsChange.creates.length > 0 || event.lockedHoldingsChange.archives.length > 0;
|
|
992
865
|
}
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
amountChange: "0"
|
|
866
|
+
const emptyHoldingsChangeSummary = {
|
|
867
|
+
instrumentId: {
|
|
868
|
+
admin: "",
|
|
869
|
+
id: ""
|
|
870
|
+
},
|
|
871
|
+
numInputs: 0,
|
|
872
|
+
numOutputs: 0,
|
|
873
|
+
inputAmount: "0",
|
|
874
|
+
outputAmount: "0",
|
|
875
|
+
amountChange: "0"
|
|
1004
876
|
};
|
|
1005
|
-
|
|
877
|
+
//#endregion
|
|
1006
878
|
exports.AllKnownMetaKeys = AllKnownMetaKeys;
|
|
1007
879
|
exports.BurnedMetaKey = BurnedMetaKey;
|
|
1008
880
|
exports.ReasonMetaKey = ReasonMetaKey;
|
|
@@ -1015,10 +887,11 @@ exports.getInterfaceView = getInterfaceView;
|
|
|
1015
887
|
exports.getKnownInterfaceView = getKnownInterfaceView;
|
|
1016
888
|
exports.getMetaKeyValue = getMetaKeyValue;
|
|
1017
889
|
exports.hasInterface = hasInterface;
|
|
890
|
+
exports.isContractEventsNotFoundError = isContractEventsNotFoundError;
|
|
1018
891
|
exports.matchInterfaceIds = matchInterfaceIds;
|
|
1019
892
|
exports.mergeMetas = mergeMetas;
|
|
1020
893
|
exports.removeParsedMetaKeys = removeParsedMetaKeys;
|
|
1021
894
|
exports.renderTransaction = renderTransaction;
|
|
1022
895
|
exports.splitInterfaceId = splitInterfaceId;
|
|
1023
|
-
|
|
896
|
+
|
|
1024
897
|
//# sourceMappingURL=index.cjs.map
|