What’s the best way to deal with this, it has to do with a swap.
Initial state, userAdmin has 0 JPY assets.
bob sends a request to swap 10 USD for Admin’s 10 JPY.
- userAdmin receives a TradeRequest contract, (we can detect this from T.registeredTemplates, @TradeRquest)
- Since userAdmin has 0 JPY, the default behavior I want is: to create a JPY contract with the requested amount each time the userAdmin receives TradeRequest. We issue new JPYs each time we get a TradeRequest so we can gaurantee we always have enough to swap with.
- the newly created JPY template needs to be used as an argument to settle the swap.
So basically
- useAdmin receives TradeRequest
- userAdmin creates JPY asset, from for example TradeRequest.requestedTicker, TradeRequest.requestedAmount
- use this new asset in TradeRequest.settle with JPY Asset.
However, what is the best way to use a new template generated from exercising a choice, within this current trigger? Do I need to use
updateState = \_ -> pure ()
From the trigger docs,
https://docs.daml.com/triggers/index.html
The updateState
function is called on new transactions and command completions and can be used to update your user-defined state based on the ACS and the transaction or completion. Since our Daml trigger does not have any interesting user-defined state, we will not go into details here.