Would it be a good idea to put a `submitUser` example into the Skeleton template?

Currently, the Skeleton template (used for project creation when no template is specified to the daml new <project name> command) contains an example of user creation, but the created users are not utilised for contract creation. The contract instances are created in the pre-user-management way, using party ids:

setup : Script AssetId
setup = script do
-- user_setup_begin
  alice <- allocatePartyWithHint "Alice" (PartyIdHint "Alice")
  bob <- allocatePartyWithHint "Bob" (PartyIdHint "Bob")
  aliceId <- validateUserId "alice"
  bobId <- validateUserId "bob"
  createUser (User aliceId (Some alice)) [CanActAs alice]
  createUser (User bobId (Some bob)) [CanActAs bob]
-- user_setup_end

  aliceTV <- submit alice do
    createCmd Asset with
      issuer = alice
      owner = alice
      name = "TV"

  bobTV <- submit alice do
    exerciseCmd aliceTV Give with newOwner = bob

  submit bob do
    exerciseCmd bobTV Give with newOwner = alice

In this way, it’s not really clear why we bother creating users.

An alternative example, actually using the submitUser and the grantUserRights command could better illuminate the rationale behind user management.

setup : Script AssetId
setup = script do
-- user_setup_begin
  alice <- allocatePartyWithHint "Alice" (PartyIdHint "Alice")
  bob <- allocatePartyWithHint "Bob" (PartyIdHint "Bob")
  public <- allocatePartyWithHint "Public" (PartyIdHint "Public")
  
  aliceId <- validateUserId "alice"
  bobId <- validateUserId "bob"
  createUser (User aliceId (Some alice)) [CanActAs alice]
  createUser (User bobId (Some bob)) [CanActAs bob]
-- user_setup_end

  aliceTV <- submitUser aliceId do
    createCmd Asset with
      issuer = alice
      owner = alice
      name = "TV"

  bobTV <- submitUser aliceId do
    exerciseCmd aliceTV Give with newOwner = bob

  aliceTVagain <- submitUser bobId do
    exerciseCmd bobTV Give with newOwner = alice 

  -- | We grant the right to act as alice to the user of Bob,
  -- so he can take back the asset.

  grantUserRights bobId [CanActAs alice] 

  submitUser bobId do
    exerciseCmd aliceTVagain Give with newOwner = bob
3 Likes

This is a very good suggestion. Thanks.

1 Like