How to change user from Guest Party to Subscription Party

Hi team,
I am working on subscription management, so wanted to confirm, if user had completed subscription, how can we modify his party.

template MediaManagement 
  with 
    editor : Party 
    admin : Party 
    subscribers : [Party]
    guestUsers : [Party] -- observers (access for trailers)

template Subscription 
  with 
    guest : Party 
    owner : Party 
    
template SubscriptionValidation 
  with 
    owner : Party 
    admin : Party 
    subscriber : Party

Here guest user is observer, with limited access, but if he purchase, we want him to be updated as subscriber.

Do I understand correctly that what you’re looking for is to give guest user an opportunity to purchase the subscription, which when exercised will result in the user party being moved from the list in guestUsers field to the list in the subscribers field in the MediaManagement contract? If this is the case, I would suggest using Set datatype for both guestUsers and subscribers fields instead of a List type. And then you can add a PurchaseSubscription choice to the MediaManagement template, which among other things would archive the existing MediaManagement contract and create an updated one in its stead.

template MediaManagement 
  with 
    editor : Party 
    admin : Party 
    subscribers : Set Party
    guestUsers : Set Party
  where
    signatory admin, editor
    observer subscribers, guestUsers

    ensure intersection subscribers guestUsers == empty 

    choice PurchaseSubscription: ContractId MediaManagement
        with
          purchaser: Party
      controller purchaser 
      do
        assertMsg "Purchaser already has subscription" $ purchaser `notMember` subscribers
        create this with
          subscribers = insert purchaser subscribers
          guestUsers = delete purchaser guestUsers

Note that

  • You can add other actions to the body of the PurchaseSubscription choice, e.g. create a Subscription contract or whatever else your model requires.
  • I added the ensure clause to the MediaManagement template to ensure that there can be no overlap between subscribers and guestUsers
  • This model will not allow your application to scale, since every subscription purchase requires archiving and recreating the MediaManagement contract. This single MediaManagement contract becomes a bottleneck that won’t allow the application to process lots of subscription purchases in parallel. Unless you’re sure your application will never ever need to process more than a few subscription purchases a minute, I would encourage you to consider alternative design that does not rely on storing the list of subscribers in a contract.
1 Like

Thanks, it is helpful. Yes, you are understanding correctly.

Can you please provide some guidelines on how could we scale it. I am learning Daml and these contracts are new to me. We were working with AWS IAM for user authentication and entitlements, but I am struggling right now for making similar approach in blockchain.

I also wanted to know, if we are doing payment from mobile application using Google Pay/Apple Pay, how could we ensure the purchase of subscription in ledger?

Smart contract applications in general have their own specific scaling and performance challenges, not found in other types of applications, and their own techniques for dealing with these challenges. For production smart contracts applications non functional requirements must always be fully accounted for at the design stage. They cannot be an afterthought.
The topic of designing smart contract applications for performance is quite complicated. It’s not something that can be explained in a few sentences. Our training materials available at Daml Training and Certification address the topics of design and architecture of Daml applications, designing and coding Daml models and ledger client applications for performance etc. I suggest you start there. Beyond this we recommend engaging Digital Asset Professional Services that can guide you through the full cycle of solution design and development to ensure that the resulting product meets your expectations.

I’m afraid I don’t quite understand the question. Would you care to elaborate on the scenario you describe?

1 Like