I have an app deployed on Daml hub, trying to find out how to deploy triggers to daml hub. Most documentation deals with triggers being activated locally against the sandbox ledger, and to have a trigger run as a certain party.
What would I need to do if I were to deploy onto Daml hub?
What I’m trying to do:
Assume I am the admin, currently my ledger ID is
ledger-party-68815041-ad16-4d9a-8177-9f9b20d8fb3f
,
As an admin, I would like to issue an ExampleToken
to each new user
(but there is a propose and accept workflow required, which I’d like to abstract away using triggers.)
The intention is that when they login, they already have some ‘play assets’ issued by me.
First I create an AssetHoldingAccount
template, with a ticker / symbol called ExampleToken
. This is the account that I want each new user by default to have.
On this template, I have a choice which creates a proposal which the receiver needs to accept.
nonconsuming choice Invite_New_Asset_Holder : ContractId AssetHoldingAccountProposal
with
recipient : Party
controller if resharable then owner else assetType.issuer
do
create AssetHoldingAccountProposal with
account = this
recipient
How can I achieve the following workflow:
-
For every new party that signs in, the admin party should automatically exercise the
Invite_new_asset_holder
choice for the new user. -
For the non-admin party, upon receiving the invitation, the trigger should automatically accept for them.
Question 1 of 2
Regarding the first point, the trigger needs to react to the creation of a new contract right?
So upon login of a new user, I can create a user
contract, but I can also, for example create an assetHoldingAccountRequest
which is specifically used to trigger the trigger.
To tackle the automatic creation of the user
template or assetHoldingAccountRequest
template, the frontend React code can do the following, (and this is taken from the create-daml-app template)
const login = useCallback(async (credentials: Credentials) => {
console.log('login Called')
try {
const ledger = new Ledger({ token: credentials.token, httpBaseUrl });
// THIS PORTION BELOW COMES WITH CREAT-DAML-APP
let userContract = await ledger.fetchByKey(User.User, credentials.party);
if (userContract === null) {
const user = { username: credentials.party, following: [] };
// anyone can create this contract
userContract = await ledger.create(User.User, user);
// THIS IS MY 'AUTOMATION' for a new user to create an assetHoldingAccountRequest
await ledger.create(Account.AssetHoldingAccountRequest, {recipient: credentials.party, owner: 'a'})
console.log('created')
}
onLogin(credentials);
} catch (error) {
setError(true)
}
}, [onLogin]);
Upon the creation of AssetHoldingAccountRequest
below
template AssetHoldingAccountRequest with
recipient: Party
owner: Party
where
signatory recipient
choice Accept: ()
controller owner
do
return ()
from the non-admin party, to the admin, I (admin) would like to automatically exercise the Invite_New_asset_Holder choice, with this new party’s ledger ID.
Once this user receives the invitation in the ledger, the trigger should automatically accept it on his behalf.
Question 2 of 2
Do I need triggers specific to the party? and hence I would need to hardcode the ledger ID?
as an example,
autoSendRequest, do if p === hardcodedAdminLedgerID
and
autoAcceptRequest: do if p !== hardCodedAdminLedgerID