@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.
@@ -823,6 +823,9 @@ function classifyError(e) {
823
823
  }
824
824
  return "other";
825
825
  }
826
+ function firstNonConflictError(outcomes) {
827
+ return outcomes.find((o) => o.error !== void 0 && classifyError(o.error) !== "conflict");
828
+ }
826
829
  function summarize(outcomes) {
827
830
  const committed = outcomes.filter((o) => o.certified);
828
831
  const rank = { "keep-open": 3, conflict: 2, other: 1 };
@@ -883,14 +886,15 @@ var TransferMachine = class {
883
886
  ...r.payload.memo !== void 0 ? { memo: r.payload.memo } : {}
884
887
  };
885
888
  const outcomes = await this.resumeOps(ctx, engine, r);
886
- const { committed, cls, firstError } = summarize(outcomes);
889
+ const { committed } = summarize(outcomes);
887
890
  const conflicts = this.toConflicts(engine, r, outcomes);
888
891
  if (committed.length === 0 && conflicts.length > 0) throw conflicts[0].error;
889
892
  let deliveryPending = false;
890
893
  if (committed.length > 0) {
891
894
  deliveryPending = await this.deliverSet(r.transferId, r.payload.recipient, r.payload.memo, committed);
892
895
  }
893
- if (cls !== null && cls !== "conflict") throw firstError;
896
+ const blocking = firstNonConflictError(outcomes);
897
+ if (blocking !== void 0) throw blocking.error;
894
898
  await this.applyCommitted(engine, r.transferId, committed);
895
899
  if (conflicts.length > 0) {
896
900
  return { deliveryPending, partial: await this.settlePartial(engine, r, committed, conflicts) };
@@ -916,16 +920,37 @@ var TransferMachine = class {
916
920
  ...plan.memo !== void 0 ? { memo: plan.memo } : {}
917
921
  };
918
922
  const outcomes = [];
923
+ const certified = [];
919
924
  for (let at = 0; at < plan.ops.length; at += CERTIFY_WIDTH) {
920
925
  const batch = plan.ops.slice(at, at + CERTIFY_WIDTH);
921
926
  const settled = await Promise.all(
922
- batch.map((op) => this.certifyOne(ctx, engine, op, plan.sources.get(op.sourceTokenId)))
927
+ batch.map(
928
+ (op) => this.certifyOne(ctx, engine, op, plan.sources.get(op.sourceTokenId)).then((o) => {
929
+ if (o.certified) {
930
+ certified.push(o);
931
+ this.emitProgress(plan, certified);
932
+ }
933
+ return o;
934
+ })
935
+ )
923
936
  );
924
937
  outcomes.push(...settled);
925
938
  if (settled.some((o) => o.error !== void 0 && !o.certified)) break;
926
939
  }
927
940
  return outcomes;
928
941
  }
942
+ /** In-flight snapshot: `tokenTransfers` holds the legs certified SO FAR. */
943
+ emitProgress(plan, certified) {
944
+ this.deps.emit("transfer:updated", {
945
+ id: plan.transferId,
946
+ status: "submitted",
947
+ tokens: [],
948
+ tokenTransfers: certified.map((o) => ({
949
+ sourceTokenId: o.op.sourceTokenId,
950
+ method: o.op.kind
951
+ }))
952
+ });
953
+ }
929
954
  async certifyOne(ctx, engine, op, source) {
930
955
  if (source === void 0) {
931
956
  return {