Hi community,
Could you help me to understand if somehow it’s possible to have different strategies for example to round a value.
I leave you the example bellow to be easier to understand what I would like to do. In this example each company
can create a Product contract which applies a round “strategy” to Subscription amount, according with each company preferences.
For example in Product 1, released by company 1, they want to use floor “strategy” to round amounts,
but company 2 wants to use ceil “strategy” to round amounts.
That’s I would like to implement with roundAmount function.
Somehow pass the strategy name and grab its corresponding fn in a dynamic way.
Is it possible to have it using DAML ? For example with a Map Text FN ? Or using another ways ?
template Product
with
code: Text
round_strategy: Text
issuer: Party
where
signatory issuer
controller issuer can
nonconsuming Product_Propose_Subscription : ContractId SubscriptionProposal
with
holder: Party
amount_quote: Decimal
do
create SubscriptionProposal with
code = "some bussiness code"
product_code = code
amount = roundAmount amount_quote round_strategy
issuer
holder
template SubscriptionProposal
with
code: Text
product_code: Text
amount: Int
issuer: Party
holder: Party
where
signatory issuer
roundAmount: Decimal -> Text -> Int
roundAmount amount strategy =
let strategyFn = getRoundStrategyFn strategy
strategyFn amount