> ## Documentation Index
> Fetch the complete documentation index at: https://docs.canton.network/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> If you are building a Canton Network application, start from https://docs.canton.network/appdev/quickstart.md. To run only a local network for your own Daml code, without building the QuickStart demo, see https://docs.canton.network/sdks-tools/development-tools/localnet.md.

# Splice.Util

> Documentation for Splice.Util

Utility functions shared across all splice apps.

## Typeclasses

**class** ([Show](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-ghc-show-show-65360) t, [Eq](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-ghc-classes-eq-22713) cgid, [Show](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-ghc-show-show-65360) 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.
>
> contractGroupId
> : t -> cgid

**class** Patchable a **where**

> A type class for patching values. Used in particular for changing only a subset of fields in a config value.
>
> 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](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-decimal-18135)
>
> **instance** Patchable [Int](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-int-37261)
>
> **instance** Patchable [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952)
>
> **instance** ([Ord](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-ghc-classes-ord-6395) k, Patchable v) => Patchable ([Map](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-map-90052) k v)
>
> **instance** Patchable [Party](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-party-57932)
>
> **instance** Patchable [Time](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-time-63886)
>
> **instance** Patchable a => Patchable ([Optional](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-prelude-optional-37153) a)
>
> **instance** (Patchable a, [Ord](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-ghc-classes-ord-6395) a) => Patchable (Set a)
>
> **instance** Patchable [RelTime](https://docs.canton.network/appdev/reference/daml-standard-library/da-time.md#type-da-time-types-reltime-23082)

## Functions

requireMatchingContract
: ([Eq](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-ghc-classes-eq-22713) t, [Show](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-ghc-show-show-65360) t, [HasFetch](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-da-internal-template-functions-hasfetch-52387) t) => [ContractId](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-contractid-95282) t -> t -> [Update](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-update-68072) ()

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

require
: [CanAssert](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-da-internal-assert-canassert-67323) m => [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) -> [Bool](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-bool-66265) -> 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.

fetchChecked
: ([HasFetch](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-da-internal-template-functions-hasfetch-52387) t, HasCheckedFetch t cgid) => cgid -> [ContractId](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-contractid-95282) t -> [Update](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-update-68072) 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.

fetchCheckedInterface
: ([HasFetch](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-da-internal-template-functions-hasfetch-52387) i, [HasInterfaceView](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-da-internal-interface-hasinterfaceview-4492) i v, HasCheckedFetch v cgid) => cgid -> [ContractId](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-contractid-95282) i -> [Update](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-update-68072) 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.

fetchAndArchive
: ([HasFetch](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-da-internal-template-functions-hasfetch-52387) t, HasCheckedFetch t cgid, [HasArchive](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-da-internal-template-functions-hasarchive-7071) t) => cgid -> [ContractId](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-contractid-95282) t -> [Update](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-update-68072) 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
: ([HasFetch](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-da-internal-template-functions-hasfetch-52387) t, HasCheckedFetch t cgid) => cgid -> [ContractId](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-contractid-95282) t -> [Update](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-update-68072) 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
: ([HasFetch](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-da-internal-template-functions-hasfetch-52387) t, HasCheckedFetch t cgid) => cgid -> [ContractId](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-contractid-95282) t -> [Update](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-update-68072) 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](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-da-internal-template-functions-hasexercise-70422) t ch t) => cgid -> [ContractId](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-contractid-95282) t -> ch -> [Update](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-update-68072) t

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

fetchUncheckedAndArchive
: ([HasFetch](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-da-internal-template-functions-hasfetch-52387) b, [HasArchive](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-da-internal-template-functions-hasarchive-7071) b) => [ContractId](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-contractid-95282) b -> [Update](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-update-68072) 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](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-da-internal-template-functions-hasfetch-52387) t => [ContractId](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-contractid-95282) t -> [Update](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-update-68072) 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](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-da-internal-template-functions-hasfetch-52387) t => [ContractId](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-contractid-95282) t -> [Update](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-update-68072) 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](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-da-internal-template-functions-hasarchive-7071) t => [ContractId](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-contractid-95282) t -> [Update](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-update-68072) ()

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.

patchScalar
: [Eq](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-ghc-classes-eq-22713) a => a -> a -> a -> a

patchListAsScalar
: [Eq](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-ghc-classes-eq-22713) a => \[a] -> \[a] -> \[a] -> \[a]

patchListAsSet
: (Patchable a, [Ord](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#class-ghc-classes-ord-6395) a) => \[a] -> \[a] -> \[a] -> \[a]

deprecatedChoice
: [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) -> [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) -> [Text](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-ghc-types-text-51952) -> [Update](https://docs.canton.network/appdev/reference/daml-standard-library/prelude.md#type-da-internal-lf-update-68072) a
