Hi in line 47 , I wanna get data from third party database like mongoDB ... can you help me how to get that data

module Database where

import Daml.Script


template User with
    username: Party
    med_det: Address
    age:  Int
  where
    signatory username

    key username: Party  
    maintainer key

    nonconsuming choice NewDataRequest: ContractId DataRequest with
        acceptor: Party
      controller username
      do
        create $ DataRequest with requester = username, ..

    nonconsuming choice AcceptDataRequest: ContractId DataTransfer with
        dataRequest: (Party, Party)
      controller username
      do
        exerciseByKey @DataRequest dataRequest Accept


template DataRequest
  with
    requester: Party
    acceptor: Party

  where
    signatory requester
    observer acceptor

    key (requester, acceptor): (Party, Party)
    maintainer key._1

    nonconsuming choice Accept: ContractId DataTransfer

      controller acceptor
      do


        create $ DataTransfer with req = requester, acc = acceptor, meddetails =  {get data from third party database}
    nonconsuming choice CancelacceptorRequest: ()
      controller requester
      do
        archive self


template Message
  with
    sender: Party
    receiver: Party
    content: Address
  where
    signatory sender, receiver



template DataTransfer
  with
    req: Party
    acc: Party
    meddetails: Address
  where
    signatory req, acc
    key (req, acc): (Party, Party)
    maintainer [key._1, key._2]

    nonconsuming choice SendMessage1: ContractId Message
      with
        content: Address
      controller req
      do
        create $ Message with sender=req, receiver=acc, ..



    nonconsuming choice SendMessage2: ContractId Message
      with
        content: Address
      controller acc
      do
        create $ Message with sender=acc, receiver=req, ..

    nonconsuming choice CancelDataTransfer1: ()
      controller req
      do
        archive self

    nonconsuming choice CancelDataTransfer2: ()
      controller acc
      do
        archive self


data Address = Address {
  history: Text,
  cured: Text,
  medication: Text
} deriving (Eq, Show)





test = script do
  nikhil <- allocateParty "nikhil"
  -- jeevan <- allocateParty "jeevan"
  chandan <- allocateParty "chandan"

  
  usercid <- submit chandan $ createCmd $ User  {username= chandan, med_det = Address {history = "AIDS", cured = "NO", medication = "Nothing"}, age = 21}
  usercid <- submit nikhil $ createCmd $ User  {username=nikhil, med_det = Address {history = "Throat Infection", cured = "yes", medication = "Azitromycin"}, age = 21}

  -- submit jeevan $ createCmd $ User with username=jeevan
  submit nikhil $ exerciseByKeyCmd @User nikhil $ NewDataRequest with acceptor=chandan
  submit chandan $ exerciseByKeyCmd @DataRequest (nikhil,chandan) Accept


1 Like

I think the best way is to make the medetails an argument to the Accept choice. The acceptor could then query the external database and feed the data in when executing the choice.

1 Like