@pushchain/core 6.0.2 → 6.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushchain/core",
3
- "version": "6.0.2",
3
+ "version": "6.0.3",
4
4
  "homepage": "https://push.org",
5
5
  "keywords": [
6
6
  "pushchain",
@@ -98,10 +98,10 @@ function reconstructProgressEvents(universalTxResponse, universalTxData) {
98
98
  // omitted from reconstruction because R1 doesn't register a UniversalTx
99
99
  // on Push Chain, so `universalTxData` is usually undefined here and we
100
100
  // have no reliable signal to tell the three paths apart. Callers who want
101
- // the full live sequence should either register `progressHook` at
102
- // `initialize()` time (client-level) or call `tx.progressHook(cb)` after
103
- // sendTransaction — both deliver the full stream from the execute-phase
104
- // event buffer.
101
+ // the full live sequence should register a progress hook at initialize
102
+ // time, pass `sendTransaction(params, { progressHook })`, or call
103
+ // `tx.progressHook(cb)` after sendTransaction — all deliver the full stream
104
+ // from the execute-phase event buffer.
105
105
  const events = [];
106
106
  const originParts = universalTxResponse.origin.split(':');
107
107
  const chainNamespace = originParts.length >= 2 ? `${originParts[0]}:${originParts[1]}` : originParts[0];
@@ -131,10 +131,33 @@ class Orchestrator {
131
131
  */
132
132
  execute(params, options) {
133
133
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
134
- var _a, _b, _c, _d;
134
+ var _a, _b, _c, _d, _e;
135
135
  if (options) {
136
136
  params = Object.assign(Object.assign({}, params), { options: Object.assign(Object.assign({}, params.options), options) });
137
137
  }
138
+ const perCallHook = (_a = params.options) === null || _a === void 0 ? void 0 : _a.progressHook;
139
+ const originalExecuteHook = this.progressHook;
140
+ const currentHook = this.progressHook;
141
+ const shouldWrapPerCallHook = !!perCallHook &&
142
+ perCallHook !== currentHook &&
143
+ (currentHook === null || currentHook === void 0 ? void 0 : currentHook.__pushPerCallHook) !== perCallHook;
144
+ const attachPerCallHookForWait = (response) => {
145
+ if (perCallHook && response._setProgressHookNoReplay) {
146
+ response._setProgressHookNoReplay(perCallHook);
147
+ }
148
+ return response;
149
+ };
150
+ if (shouldWrapPerCallHook) {
151
+ const baseHook = this.progressHook;
152
+ const wrappedHook = ((event) => {
153
+ if (baseHook && baseHook !== perCallHook) {
154
+ baseHook(event);
155
+ }
156
+ perCallHook(event);
157
+ });
158
+ wrappedHook.__pushPerCallHook = perCallHook;
159
+ this.progressHook = wrappedHook;
160
+ }
138
161
  // Snapshot the caller's active route — `executeMultiChain` recurses into
139
162
  // this same method for R2/R3's inner Push-side execution, and without
140
163
  // snapshot/restore the recursive `detectRoute(params)` would clobber the
@@ -146,7 +169,7 @@ class Orchestrator {
146
169
  try {
147
170
  detectedRoute = (0, route_detector_1.detectRoute)(params);
148
171
  }
149
- catch (_e) {
172
+ catch (_f) {
150
173
  detectedRoute = route_detector_1.TransactionRoute.UOA_TO_PUSH;
151
174
  }
152
175
  // Don't downgrade an outer R2/R3/R4 route when the recursive inner call
@@ -164,14 +187,14 @@ class Orchestrator {
164
187
  // Lazy UEA upgrade check
165
188
  try {
166
189
  if (!this.accountStatusCache || !this.accountStatusCache.uea.loaded) {
167
- yield ((_a = this.accountStatusReadyPromise) !== null && _a !== void 0 ? _a : this.getAccountStatus());
190
+ yield ((_b = this.accountStatusReadyPromise) !== null && _b !== void 0 ? _b : this.getAccountStatus());
168
191
  }
169
192
  // If background resolved but cache still empty (timeout/error), fetch fresh
170
193
  if (!this.accountStatusCache || !this.accountStatusCache.uea.loaded) {
171
194
  yield this.getAccountStatus();
172
195
  }
173
- if (((_b = this.accountStatusCache) === null || _b === void 0 ? void 0 : _b.uea.deployed) &&
174
- ((_c = this.accountStatusCache) === null || _c === void 0 ? void 0 : _c.uea.requiresUpgrade)) {
196
+ if (((_c = this.accountStatusCache) === null || _c === void 0 ? void 0 : _c.uea.deployed) &&
197
+ ((_d = this.accountStatusCache) === null || _d === void 0 ? void 0 : _d.uea.requiresUpgrade)) {
175
198
  yield this.upgradeAccount({ progressHook: this.progressHook });
176
199
  }
177
200
  }
@@ -179,10 +202,10 @@ class Orchestrator {
179
202
  (0, internals_1.printLog)(this.ctx, `Lazy UEA upgrade check failed: ${err instanceof Error ? err.message : String(err)}. Proceeding with transaction.`);
180
203
  }
181
204
  // Check if this is a multi-chain request (has ChainTarget or from.chain)
182
- const isMultiChain = (0, route_detector_1.isChainTarget)(params.to) || ('from' in params && ((_d = params.from) === null || _d === void 0 ? void 0 : _d.chain));
205
+ const isMultiChain = (0, route_detector_1.isChainTarget)(params.to) || ('from' in params && ((_e = params.from) === null || _e === void 0 ? void 0 : _e.chain));
183
206
  if (isMultiChain) {
184
207
  try {
185
- return yield (0, internals_1.executeMultiChain)(this.ctx, params, this.execute.bind(this));
208
+ return attachPerCallHookForWait(yield (0, internals_1.executeMultiChain)(this.ctx, params, this.execute.bind(this)));
186
209
  }
187
210
  catch (err) {
188
211
  // R2/R3/R4 outer catch — fires the route-correct terminal failure
@@ -230,11 +253,11 @@ class Orchestrator {
230
253
  try {
231
254
  const rcb = () => this._getResponseCallbacks();
232
255
  if (execute.funds) {
233
- return !hasData
256
+ return attachPerCallHookForWait(!hasData
234
257
  ? yield (0, internals_1.executeFundsOnly)(this.ctx, execute, eventBuffer, rcb)
235
- : yield (0, internals_1.executeFundsWithPayload)(this.ctx, execute, eventBuffer, rcb);
258
+ : yield (0, internals_1.executeFundsWithPayload)(this.ctx, execute, eventBuffer, rcb));
236
259
  }
237
- return yield (0, internals_1.executeStandardPayload)(this.ctx, execute, eventBuffer, rcb);
260
+ return attachPerCallHookForWait(yield (0, internals_1.executeStandardPayload)(this.ctx, execute, eventBuffer, rcb));
238
261
  }
239
262
  catch (err) {
240
263
  const errMessage = err instanceof Error
@@ -277,6 +300,9 @@ class Orchestrator {
277
300
  }
278
301
  }
279
302
  finally {
303
+ if (shouldWrapPerCallHook) {
304
+ this.progressHook = originalExecuteHook;
305
+ }
280
306
  // Restore the caller's route so a recursive inner R1 execute doesn't
281
307
  // leak its UOA_TO_PUSH route back to the outer R2/R3 frame.
282
308
  this.currentRoute = previousRoute;
@@ -38,6 +38,15 @@ export interface TransactionExecutionOptions {
38
38
  * - true: emit the failure hook, throw InsufficientUEABalanceError, and stop
39
39
  */
40
40
  enforceGasCheck?: boolean;
41
+ /**
42
+ * Optional per-call progress callback for sendTransaction().
43
+ * Additive with the init-time `progressHook` passed to `PushChain.initialize`:
44
+ * both hooks receive every `ProgressEvent` emitted during this call. The
45
+ * callback is also registered on the returned response for wait-phase
46
+ * progress without replaying already-fired events. Dedups by reference if it
47
+ * matches the init-time hook.
48
+ */
49
+ progressHook?: (event: import('../progress-hook/progress-hook.types').ProgressEvent) => void;
41
50
  }
42
51
  export type ExecuteParams = {
43
52
  /**
@@ -184,10 +193,11 @@ export interface UniversalTxResponse {
184
193
  progressHook: (callback: (event: import('../progress-hook/progress-hook.types').ProgressEvent) => void) => void;
185
194
  /**
186
195
  * @internal Register a wait-phase progressHook without replaying buffered
187
- * events. Used by `trackTransaction()` to auto-attach the caller's per-call
188
- * progressHook so `tracked.wait()` can deliver wait-phase events (209-xx /
189
- * 299-xx / 399-xx) to the same callback — without re-emitting the
190
- * reconstructed execute-phase stream that trackTransaction already fired.
196
+ * events. Used by `sendTransaction(..., { progressHook })` and
197
+ * `trackTransaction()` to auto-attach the caller's per-call progressHook so
198
+ * `.wait()` can deliver wait-phase events (209-xx / 299-xx / 399-xx) to the
199
+ * same callback — without re-emitting the execute/reconstructed stream that
200
+ * already fired.
191
201
  */
192
202
  _setProgressHookNoReplay?: (callback: (event: import('../progress-hook/progress-hook.types').ProgressEvent) => void) => void;
193
203
  type: string;
@@ -71,6 +71,12 @@ export declare class PushChain {
71
71
  * @param options.enforceGasCheck - Defaults to false. When true, the
72
72
  * SDK stops on pre-flight gas/balance shortfall instead of warning
73
73
  * and proceeding.
74
+ * @param options.progressHook - Optional per-call progress callback.
75
+ * Additive with the init-time `progressHook` passed to `initialize`:
76
+ * both hooks receive every `ProgressEvent` emitted during this call.
77
+ * The callback is also registered on the returned response for wait()
78
+ * progress without replaying already-fired events. Dedups by reference
79
+ * if it matches the init-time hook.
74
80
  */
75
81
  sendTransaction: Orchestrator['execute'];
76
82
  /**