.. _module-splice-util-50740: Splice.Util =========== Utility functions shared across all splice apps\. Typeclasses ----------- .. _class-splice-util-hascheckedfetch-36555: **class** (`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\. Note that we are not requiring ``HasFetch`` here, so that we can use this typeclass also for contract groups that are not templates, e\.g\., interface views\. .. _function-splice-util-contractgroupid-63283: `contractGroupId `_ \: t \-\> cgid .. _class-splice-util-patchable-41062: **class** `Patchable `_ a **where** A type class for patching values\. Used in particular for changing only a subset of fields in a config value\. .. _function-splice-util-patch-72775: `patch `_ \: a \-\> a \-\> a \-\> a For records, ``patch new base current`` should set all fields in ``current`` to their value in ``new`` iff their value was changed in ``new`` compared to ``base``\. For other kinds of values that have field\-like values (e\.g\. Maps with keys) the implementation should match the one for records by analogy\. **instance** `Patchable `_ `Decimal `_ **instance** `Patchable `_ `Int `_ **instance** `Patchable `_ `Text `_ **instance** (`Ord `_ k, `Patchable `_ v) \=\> `Patchable `_ (`Map `_ k v) **instance** `Patchable `_ `Time `_ **instance** `Patchable `_ a \=\> `Patchable `_ (`Optional `_ a) **instance** (`Patchable `_ a, `Ord `_ a) \=\> `Patchable `_ (`Set `_ a) **instance** `Patchable `_ `RelTime `_ Functions --------- .. _function-splice-util-requirematchingcontract-54053: `requireMatchingContract `_ \: (`Eq `_ t, `Show `_ t, `HasFetch `_ t) \=\> `ContractId `_ t \-\> t \-\> `Update `_ () Require that a contract\-id refers to a specific contract\. .. _function-splice-util-require-11486: `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\. .. _function-splice-util-fetchchecked-58913: `fetchChecked `_ \: (`HasFetch `_ t, `HasCheckedFetch `_ t cgid) \=\> cgid \-\> `ContractId `_ t \-\> `Update `_ t Fetch a contract that is part of a specific contract group\. The group is typically chosen by the caller to match its own group, or a more specific group\. .. _function-splice-util-fetchcheckedinterface-8937: `fetchCheckedInterface `_ \: (`HasFetch `_ i, `HasInterfaceView `_ i v, `HasCheckedFetch `_ v cgid) \=\> cgid \-\> `ContractId `_ i \-\> `Update `_ i Fetch a contract that is part of a specific contract group defined by its interface view\. The group is typically chosen by the caller to match its own group, or a more specific group\. .. _function-splice-util-fetchandarchive-96960: `fetchAndArchive `_ \: (`HasFetch `_ t, `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\. .. _function-splice-util-fetchreferencedata-72475: `fetchReferenceData `_ \: (`HasFetch `_ t, `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\. .. _function-splice-util-fetchbutarchivelater-86159: `fetchButArchiveLater `_ \: (`HasFetch `_ t, `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\. .. _function-splice-util-fetchpublicreferencedata-76996: `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\. .. _function-splice-util-fetchuncheckedandarchive-65397: `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\. .. _function-splice-util-fetchuncheckedreferencedata-5520: `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\. .. _function-splice-util-fetchuncheckedbutarchivelater-82900: `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\. .. _function-splice-util-potentiallyunsafearchive-47027: `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\. .. _function-splice-util-patchscalar-11117: `patchScalar `_ \: `Eq `_ a \=\> a \-\> a \-\> a \-\> a .. _function-splice-util-patchlistasscalar-47719: `patchListAsScalar `_ \: `Eq `_ a \=\> \[a\] \-\> \[a\] \-\> \[a\] \-\> \[a\] .. _function-splice-util-patchlistasset-9274: `patchListAsSet `_ \: (`Patchable `_ a, `Ord `_ a) \=\> \[a\] \-\> \[a\] \-\> \[a\] \-\> \[a\]