Skip to content

Reference

PaymentStreams.utils — payment context & disclosure

Ledger helpers for factory and proposal disclosure, plus validator-backed buildPaymentContext and buildPaymentContextWithAmulets for Amulet-era submissions.

ocp.PaymentStreams.utils is where cross-domain disclosure and Amulet payment context are assembled. On OcpClient, getFactoryDisclosedContracts and getProposedPaymentStreamDisclosedContracts are bound to your ledger already—call them without passing ledgerClient.

Receiver

ocp.PaymentStreams.utils

getFactoryDisclosedContracts()

(On OcpClient, no arguments; underlying implementation takes LedgerJsonApiClient.)

Loads statically shipped factory metadata for the client’s network and returns a singleton DisclosedContract[] for the payment-stream factory.

Throws

  • OcpValidationErrorfieldPath 'network' when the network key is missing from the JSON config (OcpErrorCodes.INVALID_FORMAT).
  • OcpValidationError'network.disclosedContract' when the deployment metadata has no disclosedContract blob (OcpErrorCodes.REQUIRED_FIELD_MISSING).

getProposedPaymentStreamDisclosedContracts(proposedPaymentStreamContractId, readAs?)

Fetches created events for the proposal contract id. Uses readAs ?? [ledgerClient.getPartyId()].

Throws

  • OcpContractError — when no created event exists (OcpErrorCodes.CONTRACT_NOT_FOUND).

Returns: DisclosedContract[] with the proposal’s templateId, contractId, createdEventBlob, and synchronizerId.

buildPaymentContext(validatorClient, provider)

Queries AmuletRules, OpenMiningRound, and optionally FeaturedAppRight for provider via the validator API. Featured-app lookup failures are swallowed and yield featuredAppRight: null in the returned context.

Returns: { paymentContext: { amuletRulesCid, openMiningRoundCid, featuredAppRight }, disclosedContracts }.

Throws: Network / validator errors propagate as typical fetch failures (not always Ocp*).

buildPaymentContextWithAmulets(validatorClient, payerParty, requestedAmount, provider)

Requires validatorClient authenticated as payerParty. Selects the minimal set of payer Amulets (largest first) to cover requestedAmount (CC string).

Throws

  • OcpValidationError'payerParty.amulets' when no amulets (OcpErrorCodes.REQUIRED_FIELD_MISSING).
  • OcpValidationError'payerParty.balance' when summed effective balance is insufficient (OcpErrorCodes.OUT_OF_RANGE).

Returns: { paymentContext: { payerAmulets, amuletRulesCid, openMiningRoundCid, featuredAppRight? }, disclosedContracts } including disclosed blobs for selected amulets plus rules / round / optional featured app right.

Minimal example

const { paymentContext, disclosedContracts } = await ocp.PaymentStreams.utils.buildPaymentContext(
  canton.validator,
  PROVIDER_PARTY
);

See also

Source