Splice.Util

Utility functions shared across all splice apps.

Typeclasses

class (HasFetch t, Show t, Eq cgid, Show cgid) => HasCheckedFetch t cgid where

Contracts typically come in groups. For example, all contracts managed by a specific DSO party.

We aim to always fetch with a specific contract group identifier to ensure that we do not mixup contracts from different groups.

contractGroupId

: t -> cgid

Functions

requireMatchingContract

: (Eq t, Show t, HasFetch t) => ContractId t -> t -> Update ()

Require that a contract-id refers to a specific contract.

require

: CanAssert m => Text -> Bool -> m ()

Check whether a required condition is true. If it’s not, abort the transaction with a message saying that the requirement was not met.

fetchAndArchive

: (HasCheckedFetch t cgid, HasArchive t) => cgid -> ContractId t -> Update t

Fetch and archive a contract in one go.

Use this when implementing choices that mutate another contract by fetching, archiving, and then creating the updated contract.

fetchReferenceData

: HasCheckedFetch t cgid => cgid -> ContractId t -> Update t

Fetch a contract that serves as reference data.

Use this whenever you need to fetch a contract that you do not intend to mutate.

fetchButArchiveLater

: HasCheckedFetch t cgid => cgid -> ContractId t -> Update t

Fetch a contract that is not reference data, and should be archived later in some cases.

Prefer fetchAndArchive over this function, as it avoids forgetting to archive the contract.

fetchPublicReferenceData

: (HasCheckedFetch t cgid, HasExercise t ch t) => cgid -> ContractId t -> ch -> Update t

Fetch a contract that offers a choice anybody to be read as reference data.

fetchUncheckedAndArchive

: (HasFetch b, HasArchive b) => ContractId b -> Update b

Fetch and archive a contract in one go.

Use this when implementing choices that mutate another contract by fetching, archiving, and then creating the updated contract.

fetchUncheckedReferenceData

: HasFetch t => ContractId t -> Update t

Fetch a contract that serves as reference data.

Use this whenever you need to fetch a contract that you do not intend to mutate.

fetchUncheckedButArchiveLater

: HasFetch t => ContractId t -> Update t

Fetch a contract that is not reference data, and should be archived later in some cases.

Prefer fetchAndArchive over this function, as it avoids forgetting to archive the contract.

potentiallyUnsafeArchive

: HasArchive t => ContractId t -> Update ()

A more appropriately named version of archive.

Please justify all its uses, and where possible prefer fetchAndArchive so that the contract group identifier is surely performed.