@unicitylabs/sphere-sdk 0.14.4 → 0.14.6-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.
@@ -741,7 +741,7 @@ var CheckpointTrustbaseMismatchError = class extends SphereError {
741
741
  };
742
742
 
743
743
  // modules/payments-v2/machine/TransferMachine.ts
744
- var CERTIFY_WIDTH = 8;
744
+ var CERTIFY_WIDTH = 20;
745
745
  var KEEP_OPEN_CODES = /* @__PURE__ */ new Set([
746
746
  "CERTIFICATION_UNCONFIRMED",
747
747
  "CHECKPOINT_PERSIST_FAILED",
@@ -837,12 +837,15 @@ var TransferMachine = class {
837
837
  payload: r.payload,
838
838
  ...r.payload.memo !== void 0 ? { memo: r.payload.memo } : {}
839
839
  };
840
- const { committed, conflicts } = await this.resumeOps(ctx, engine, r);
840
+ const outcomes = await this.resumeOps(ctx, engine, r);
841
+ const { committed, cls, firstError } = summarize(outcomes);
842
+ const conflicts = this.toConflicts(engine, r, outcomes);
841
843
  if (committed.length === 0 && conflicts.length > 0) throw conflicts[0].error;
842
844
  let deliveryPending = false;
843
845
  if (committed.length > 0) {
844
846
  deliveryPending = await this.deliverSet(r.transferId, r.payload.recipient, r.payload.memo, committed);
845
847
  }
848
+ if (cls !== null && cls !== "conflict") throw firstError;
846
849
  await this.applyCommitted(engine, r.transferId, committed);
847
850
  if (conflicts.length > 0) {
848
851
  return { deliveryPending, partial: await this.settlePartial(engine, r, committed, conflicts) };
@@ -927,25 +930,28 @@ var TransferMachine = class {
927
930
  );
928
931
  return { recipientBlob: outputs[0].blob.token, changeBlob: outputs[1].blob.token };
929
932
  }
933
+ /** Raw outcomes; `summarize` alone decides what they mean — same as the send path. */
930
934
  async resumeOps(ctx, engine, r) {
931
- const committed = [];
932
- const conflicts = [];
935
+ const outcomes = [];
933
936
  for (const op of buildOps(r.payload)) {
934
937
  const journaled = op.kind === "direct" ? r.journaled.get(op.opIndex) : void 0;
935
938
  if (journaled !== void 0) {
936
- committed.push({ op, certified: true, recipientBlob: hexToBytes(journaled.blobHex) });
937
- continue;
938
- }
939
- const source = r.sources.get(op.sourceTokenId);
940
- const outcome = await this.certifyOne(ctx, engine, op, source);
941
- if (outcome.certified) {
942
- committed.push(outcome);
939
+ outcomes.push({ op, certified: true, recipientBlob: hexToBytes(journaled.blobHex) });
943
940
  continue;
944
941
  }
945
- if (classifyError(outcome.error) !== "conflict") throw outcome.error;
946
- conflicts.push({ op, error: outcome.error, amount: conflictAmount(engine, r.payload, op, source) });
942
+ outcomes.push(await this.certifyOne(ctx, engine, op, r.sources.get(op.sourceTokenId)));
943
+ const last = outcomes[outcomes.length - 1];
944
+ if (last.error !== void 0 && classifyError(last.error) !== "conflict") break;
947
945
  }
948
- return { committed, conflicts };
946
+ return outcomes;
947
+ }
948
+ /** Conflicted ops with the amount each leaves undelivered (#690 shortfall math). */
949
+ toConflicts(engine, r, outcomes) {
950
+ return outcomes.filter((o) => !o.certified && classifyError(o.error) === "conflict").map((o) => ({
951
+ op: o.op,
952
+ error: o.error,
953
+ amount: conflictAmount(engine, r.payload, o.op, r.sources.get(o.op.sourceTokenId))
954
+ }));
949
955
  }
950
956
  async deliverSet(transferId, recipientPubkey, memo, committed) {
951
957
  const journaled = committed.filter((o) => o.error === void 0 && o.recipientBlob !== void 0);