@unicitylabs/sphere-sdk 0.14.6 → 0.14.8-dev.1

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.
@@ -778,6 +778,9 @@ function classifyError(e) {
778
778
  }
779
779
  return "other";
780
780
  }
781
+ function firstNonConflictError(outcomes) {
782
+ return outcomes.find((o) => o.error !== void 0 && classifyError(o.error) !== "conflict");
783
+ }
781
784
  function summarize(outcomes) {
782
785
  const committed = outcomes.filter((o) => o.certified);
783
786
  const rank = { "keep-open": 3, conflict: 2, other: 1 };
@@ -838,14 +841,15 @@ var TransferMachine = class {
838
841
  ...r.payload.memo !== void 0 ? { memo: r.payload.memo } : {}
839
842
  };
840
843
  const outcomes = await this.resumeOps(ctx, engine, r);
841
- const { committed, cls, firstError } = summarize(outcomes);
844
+ const { committed } = summarize(outcomes);
842
845
  const conflicts = this.toConflicts(engine, r, outcomes);
843
846
  if (committed.length === 0 && conflicts.length > 0) throw conflicts[0].error;
844
847
  let deliveryPending = false;
845
848
  if (committed.length > 0) {
846
849
  deliveryPending = await this.deliverSet(r.transferId, r.payload.recipient, r.payload.memo, committed);
847
850
  }
848
- if (cls !== null && cls !== "conflict") throw firstError;
851
+ const blocking = firstNonConflictError(outcomes);
852
+ if (blocking !== void 0) throw blocking.error;
849
853
  await this.applyCommitted(engine, r.transferId, committed);
850
854
  if (conflicts.length > 0) {
851
855
  return { deliveryPending, partial: await this.settlePartial(engine, r, committed, conflicts) };
@@ -871,16 +875,37 @@ var TransferMachine = class {
871
875
  ...plan.memo !== void 0 ? { memo: plan.memo } : {}
872
876
  };
873
877
  const outcomes = [];
878
+ const certified = [];
874
879
  for (let at = 0; at < plan.ops.length; at += CERTIFY_WIDTH) {
875
880
  const batch = plan.ops.slice(at, at + CERTIFY_WIDTH);
876
881
  const settled = await Promise.all(
877
- batch.map((op) => this.certifyOne(ctx, engine, op, plan.sources.get(op.sourceTokenId)))
882
+ batch.map(
883
+ (op) => this.certifyOne(ctx, engine, op, plan.sources.get(op.sourceTokenId)).then((o) => {
884
+ if (o.certified) {
885
+ certified.push(o);
886
+ this.emitProgress(plan, certified);
887
+ }
888
+ return o;
889
+ })
890
+ )
878
891
  );
879
892
  outcomes.push(...settled);
880
893
  if (settled.some((o) => o.error !== void 0 && !o.certified)) break;
881
894
  }
882
895
  return outcomes;
883
896
  }
897
+ /** In-flight snapshot: `tokenTransfers` holds the legs certified SO FAR. */
898
+ emitProgress(plan, certified) {
899
+ this.deps.emit("transfer:updated", {
900
+ id: plan.transferId,
901
+ status: "submitted",
902
+ tokens: [],
903
+ tokenTransfers: certified.map((o) => ({
904
+ sourceTokenId: o.op.sourceTokenId,
905
+ method: o.op.kind
906
+ }))
907
+ });
908
+ }
884
909
  async certifyOne(ctx, engine, op, source) {
885
910
  if (source === void 0) {
886
911
  return {