Skip to content
CCPEDIAby Unity Nodes
App Development

Init-script in canton

3 posts280 viewsLast activity Jan 2023

  1. nagendraOP

    Hello,

    I am trying to translate the below init-script we have into init.canton and have hard time doing so. Appreciate any help i could get!

    daml 1.2
    module Setup where
    
    import Daml.Script
    
    import Role.Operator
    
    data Parties = Parties with
      operator  : Party
    
    setup : Script ()
    setup = do
      operator <-  allocatePartyWithHint "Operator"  $ PartyIdHint with partyIdHint = "Operator"
      opRole <- submit operator $ createCmd OperatorRole with operator
    
      pure ()
    

    I have gotten this far

    import better.files._
    
    
    val operator = participant1.parties.enable("Operator")
    val operatorAssignment = Set(operator -> participant1)
    
    // upload dar file to participants
    val darPath = Option(System.getProperty("dar-path")).getOrElse("/.daml/dist/participant-${DAR_VERSION}.dar")
    darPath.exists || sys.error(s"cannot find the dar file ${darPath}")
    participants.all.dars.upload(darPath)
    

    Is there a way we can ask canton to pick it like we do in daml.yaml, for example: init-script:Setup:setup

  2. stefanobaghino-da

    Does this help?

  3. nagendra

    Hi @stefanobaghino-da ,

    Thanks for your response. This works in a sandbox environment, i’m afraid it’s bit too much for production/prod replica environments as we’ll end up running the daml script command manually. I was able to figure out some stuff in the bootstrap script and it is working, but i’m not sure if it is right or not. Below is the script.

    import better.files._
    
    
    val operator = participant1.parties.enable("Operator")
    val operatorAssignment = Set(operator -> participant1)
    
    // upload dar file to participants
    val darPath = Option(System.getProperty("dar-path")).getOrElse("/.daml/dist/participant-${DAR_VERSION}.dar")
    darPath.exists || sys.error(s"cannot find the dar file ${darPath}")
    participants.all.dars.upload(darPath)
    
    participant1.domains.connect_local(mydomain)
    val operatorRolePackageId = participant1.packages.find("Role.Operator").head.packageId
    val createRoleCommand = ledger_api_utils.create(operatorRolePackageId, "Role.Operator", "OperatorRole", Map("operator" -> participant1.parties.find("Operator")))
    participant1.ledger_api.commands.submit(Seq(participant1.parties.find("Operator")), Seq(createRoleCommand))