@unicitylabs/sphere-sdk 0.14.5 → 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.
@@ -786,7 +786,7 @@ var CheckpointTrustbaseMismatchError = class extends SphereError {
786
786
  };
787
787
 
788
788
  // modules/payments-v2/machine/TransferMachine.ts
789
- var CERTIFY_WIDTH = 8;
789
+ var CERTIFY_WIDTH = 20;
790
790
  var KEEP_OPEN_CODES = /* @__PURE__ */ new Set([
791
791
  "CERTIFICATION_UNCONFIRMED",
792
792
  "CHECKPOINT_PERSIST_FAILED",
@@ -882,12 +882,15 @@ var TransferMachine = class {
882
882
  payload: r.payload,
883
883
  ...r.payload.memo !== void 0 ? { memo: r.payload.memo } : {}
884
884
  };
885
- const { committed, conflicts } = await this.resumeOps(ctx, engine, r);
885
+ const outcomes = await this.resumeOps(ctx, engine, r);
886
+ const { committed, cls, firstError } = summarize(outcomes);
887
+ const conflicts = this.toConflicts(engine, r, outcomes);
886
888
  if (committed.length === 0 && conflicts.length > 0) throw conflicts[0].error;
887
889
  let deliveryPending = false;
888
890
  if (committed.length > 0) {
889
891
  deliveryPending = await this.deliverSet(r.transferId, r.payload.recipient, r.payload.memo, committed);
890
892
  }
893
+ if (cls !== null && cls !== "conflict") throw firstError;
891
894
  await this.applyCommitted(engine, r.transferId, committed);
892
895
  if (conflicts.length > 0) {
893
896
  return { deliveryPending, partial: await this.settlePartial(engine, r, committed, conflicts) };
@@ -972,25 +975,28 @@ var TransferMachine = class {
972
975
  );
973
976
  return { recipientBlob: outputs[0].blob.token, changeBlob: outputs[1].blob.token };
974
977
  }
978
+ /** Raw outcomes; `summarize` alone decides what they mean — same as the send path. */
975
979
  async resumeOps(ctx, engine, r) {
976
- const committed = [];
977
- const conflicts = [];
980
+ const outcomes = [];
978
981
  for (const op of buildOps(r.payload)) {
979
982
  const journaled = op.kind === "direct" ? r.journaled.get(op.opIndex) : void 0;
980
983
  if (journaled !== void 0) {
981
- committed.push({ op, certified: true, recipientBlob: hexToBytes(journaled.blobHex) });
982
- continue;
983
- }
984
- const source = r.sources.get(op.sourceTokenId);
985
- const outcome = await this.certifyOne(ctx, engine, op, source);
986
- if (outcome.certified) {
987
- committed.push(outcome);
984
+ outcomes.push({ op, certified: true, recipientBlob: hexToBytes(journaled.blobHex) });
988
985
  continue;
989
986
  }
990
- if (classifyError(outcome.error) !== "conflict") throw outcome.error;
991
- conflicts.push({ op, error: outcome.error, amount: conflictAmount(engine, r.payload, op, source) });
987
+ outcomes.push(await this.certifyOne(ctx, engine, op, r.sources.get(op.sourceTokenId)));
988
+ const last = outcomes[outcomes.length - 1];
989
+ if (last.error !== void 0 && classifyError(last.error) !== "conflict") break;
992
990
  }
993
- return { committed, conflicts };
991
+ return outcomes;
992
+ }
993
+ /** Conflicted ops with the amount each leaves undelivered (#690 shortfall math). */
994
+ toConflicts(engine, r, outcomes) {
995
+ return outcomes.filter((o) => !o.certified && classifyError(o.error) === "conflict").map((o) => ({
996
+ op: o.op,
997
+ error: o.error,
998
+ amount: conflictAmount(engine, r.payload, o.op, r.sources.get(o.op.sourceTokenId))
999
+ }));
994
1000
  }
995
1001
  async deliverSet(transferId, recipientPubkey, memo, committed) {
996
1002
  const journaled = committed.filter((o) => o.error === void 0 && o.recipientBlob !== void 0);