Hello,
We have an use case where we would like to enrich the daml-finance Batch
with an aging feature. The logic is simple: if the settler tries to settle the Batch
and any of the instructions have not been allocated/approved, we don’t want to fail. Instead, we want to increment an Int field age
.
Our initial idea was to create a new interface AgedBatch
with a extra field age
in the view, and a new Settle'
choice with the signature below. So in case something is wrong, a new AgedBatch
with age
incremented is created.
choice Settle' : Either (ContractId AgedBatch) [ContractId Holding.I]
Regarding the implementation, we basically would copy/paste from daml-finance codebase.
This would work, but we are considering a second approach.
The idea is to have a template which wraps a daml-finance Batch contract like that:
template AgedBatch
with
settler : Party
age : Int
batchCid : ContractId Batch.I
where
signatory settler
choice Settle' : Either (ContractId AgedBatch) [ContractId Holding.I]
controller settler
do
try
Right <$> exercise batchCid Batch.Settle with
actors = singleton settler
catch
GeneralError _msg -> Left <$> create this with counter = this.counter + 1
-- add more exceptions here
But the downside in the above model is that we cannot prevent the settler to settle using the wrapped batchCid instead of the choice Settle'
in the enriched Batch.
Any ideas?
Thanks!
Jose Velasco