Parsing error on writing two seperate choices in one file

Not sure why the parsing error on line 42(trade_create_usBank parties = do)

-- Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0


module TestScript where

import Daml.Script
import Iou
import IouTrade()

data Parties = Parties with
  alice : Party
  bob : Party
  usBank : Party
  eurBank : Party

trade_create_eurBank : Parties ->Script (ContractId Iou)
trade_create_eurBank parties = do

  submit parties.eurBank do
    createCmd Iou with
          issuer = parties.eurBank
          owner = parties.eurBank
          currency = "EUR"
          amount = 100.0
          observers = []          
 
trade_exercise_iouTransfer_eurBank : ContractId Iou -> Script ()
trade_exercise_iouTransfer_eurBank cid_iou = do
  
let Some alice = partyFromText "Alice"
let Some bob = partyFromText "Bob"
let Some usBank = partyFromText "USD_Bank" 
let Some eurBank = partyFromText "EUR_Bank"

iouTransferAliceCid <- submit eurBank do
        exerciseCmd cid_iou Iou_Transfer with newOwner = alice

pure ()

trade_create_usBank : Parties ->Script (ContractId Iou)
trade_create_usBank parties = do

  submit parties.usBank do
    createCmd Iou with
          issuer = parties.usBank
          owner = parties.usBank
          currency = "USD"
          amount = 110.0
          observers = []

trade_exercise_iouTransfer_usBank : ContractId Iou -> Script ()
trade_exercise_iouTransfer_usBank cid_iou_us = do
  
let Some alice = partyFromText "Alice"
let Some bob = partyFromText "Bob"
let Some usBank = partyFromText "USD_Bank" 
let Some eurBank = partyFromText "EUR_Bank"

iouTransferBobCid <- submit usBank do
        exerciseCmd cid_iou_us Iou_Transfer with newOwner = bob

pure ()
1 Like

If you start a do block you need to indent the following lines. 2 spaces are common but you can also use 4, the important thing is that all lines in the do block are indented by the same amount. Here is the fixed version:


module TestScript where

import Daml.Script
import Iou
import IouTrade()

data Parties = Parties with
  alice : Party
  bob : Party
  usBank : Party
  eurBank : Party

trade_create_eurBank : Parties ->Script (ContractId Iou)
trade_create_eurBank parties = do

  submit parties.eurBank do
    createCmd Iou with
          issuer = parties.eurBank
          owner = parties.eurBank
          currency = "EUR"
          amount = 100.0
          observers = []

trade_exercise_iouTransfer_eurBank : ContractId Iou -> Script ()
trade_exercise_iouTransfer_eurBank cid_iou = do
  let Some alice = partyFromText "Alice"
  let Some bob = partyFromText "Bob"
  let Some usBank = partyFromText "USD_Bank"
  let Some eurBank = partyFromText "EUR_Bank"

  iouTransferAliceCid <- submit eurBank do
          exerciseCmd cid_iou Iou_Transfer with newOwner = alice

  pure ()

trade_create_usBank : Parties ->Script (ContractId Iou)
trade_create_usBank parties = do

  submit parties.usBank do
    createCmd Iou with
          issuer = parties.usBank
          owner = parties.usBank
          currency = "USD"
          amount = 110.0
          observers = []

trade_exercise_iouTransfer_usBank : ContractId Iou -> Script ()
trade_exercise_iouTransfer_usBank cid_iou_us = do

  let Some alice = partyFromText "Alice"
  let Some bob = partyFromText "Bob"
  let Some usBank = partyFromText "USD_Bank"
  let Some eurBank = partyFromText "EUR_Bank"

  iouTransferBobCid <- submit usBank do
          exerciseCmd cid_iou_us Iou_Transfer with newOwner = bob

  pure ()
1 Like