Skip to main content
runClose is a pure, dependency-injected runner. It fetches each round, verifies every transaction before signing, signs, and submits only once the signing weight is enough, repeating until the close is done. The LumenWipe web app drives its own closes the same way.

Dependencies

verify is where the security of your integration lives. runClose guarantees it runs before every signature, but only your implementation decides what it accepts. Two signing guards of the LumenWipe web app are not part of runClose, so your sign and submit need their own: never attach a hash(x) preimage to a transaction that does not remove that same signer, and never submit a transaction that removes signers without an account_merge unless the master key has signed it and the same transaction lowers every threshold to 1 or below. See Verification. runClose resolves with { mergeConfirmed }. Without reconcile it is always false: returning then says only that the API asked for no more calls, and a transaction’s covers is API metadata. Do not tell a user the account is closed until you have established the merge yourself, from the envelope you signed and a confirmed lookup of its hash.

Progress events

onProgressEvent is told where the close is. Before each round is fetched it gets { phase: "preparing", round }. For each transaction of the round it then gets, in order: Every transaction event carries: A resumed transaction (see Multisig and partial signing) starts at awaiting-signature, since it is not verified again, and keeps the round and position it had. A pinned resume whose weight is already met starts at submitting and emits the same events as a signed round from there on. A transaction short of signing weight stops at awaiting-signature; a failed verify stops at verifying. Settling a left-over unresolved submission reports no event: onResolved covers it. The callback is an observer. Each event is a fresh object, nothing it returns is awaited, and anything it throws or rejects with is ignored, so it cannot stop or change the close. onProgress keeps its messages, and both callbacks can be used together.

Unknown outcomes

Without reconcile, a failed submit is thrown as it is. Pass reconcile and runClose settles an unknown outcome by hash instead:
hashOf must run on your side, on the exact final envelope, with your own network passphrase. The SDK has no Stellar dependency, so it never computes a hash, and it never takes one from the API: an answer naming any other hash leaves the outcome unknown. Everything but a 4xx from submit counts as unknown. runClose then sends the same bytes again, at most SUBMIT_RESEND_ATTEMPTS (2) times, SUBMIT_RESEND_DELAY_MS (5 seconds) apart. prepare runs once per transaction, so a resend never repeats a co-signature or a sponsorship. If that settles nothing it looks the hash up, then throws CloseOutcomeUnknownError with a submission to pass back as unresolved, or CloseTransactionFailedError if the transaction failed on the ledger. An unresolved submission is looked up, never sent. With reconcile, onConfirmed receives covers naming a merge only when closesAccount parsed one, and mergeConfirmed is true only for such a merge confirmed under your own hash. A confirmed merge ends the close, and account_not_found alone never does: it counts only when the merge’s own hash is confirmed. not_found stays unknown until validUntil plus SUBMISSION_GIVE_UP_MARGIN_SECONDS (120) has passed by both your clock and the ledger close time in the lookup, and then the close returns to a fresh round. Persist only what UnresolvedSubmission holds, never the signed envelope.

Multisig and partial signing

A round can change the account’s signers and thresholds: signer normalization removes extra signers and lowers the thresholds. Judge requiredWeight and sign against the response’s sourceAccount, the read the round was built from, with each confirmed SetOptions applied on top as its transaction lands. Against an earlier read, a later transaction asks for weight the account no longer needs, or for a signature from a key it no longer has, which the network refuses. If sign returns a weight below requiredWeight, runClose throws InsufficientSignatureWeightError. Its pending property holds everything needed to continue with a different signer on the same envelope. Pass it back as the second argument to resume without re-fetching, which would discard collected signatures:

Pinning the approved hash

Pass transactionHash and runClose pins the hash of each transaction once verify passes. The pin is stored as pending.approvedHash:
Hash the envelope’s own transaction, on your side, with your own network passphrase, and never take the hash from the API. Do not unwrap a fee-bump envelope: a resumed fee bump must fail the check. The function must not throw for a valid plain envelope. If it throws, runClose rethrows that error and submits nothing. With a pin, runClose refuses with ApprovedHashMismatchError and submits nothing when the envelope sign returns, or a resumed pending.xdr, hashes to anything else. A pinned round resumed without transactionHash is refused the same way, with actualHash set to null. The hash covers the transaction and not its signatures, so signatures collected elsewhere can be added to pending.xdr. Set accumulatedWeight to the weight of the verified signatures it then carries, and keep approvedHash. When that weight already meets requiredWeight, the resume goes to prepare without calling sign. The check runs on the envelope handed to prepare, so a prepare that co-signs or fee-bumps must keep that transaction. Without a pin, a resume always calls sign. If the API refuses a round as state_changed (the account changed between its read and its build), runClose asks for that round again, at most STATE_CHANGED_REFETCHES (2) times and each time after waiting STATE_CHANGED_REFETCH_DELAY_MS (3 seconds, about one ledger close), because each call re-reads the account and a read provider can lag a transaction that just confirmed by a ledger or two. If the round is still refused, or it was refused against the reviewed planHash (the plan itself is stale, so it is not asked for again), it throws CloseStateChangedError. Nothing was submitted for that round: plan the close again, have the user review the new plan, and run the close from it. If a close does not finish within the round bound, or the API says another call is needed but returns no transactions, runClose throws CloseDidNotConvergeError. Its rounds, bound and reason (round_limit or empty_batch) say why, and its message is plain language. Nothing is lost: run the close again and it picks up where it stopped.