The issue is that your choice defines fields with the same name as the template fields. The easiest fix is to rename one of them, e.g., suffix the fields in the choice argument
controller bidder can
MakeABid: ContractId Auction2
with
limitArg: Decimal
startArg: Time
endArg: Time
bidArg: Decimal
currencyArg: Text
do
create Auction2
with
limit = > 10.0
start = 10.30
end = 11.00
bid= 1000.00
currency = "Pound"
Once you fixed that, you’ll get another error about limit = > 10.0
. I assume that’s probably just a typo and you meant limit = 10.0
.
After fixing that there is another error at ensure limit > 0
. That is caused by the fact that 0
is of type Int
whereas limit
is of type Decimal
. You can use ensure limit > 0.0
instead to fix that.
On to the next error
daml/Main.daml:40:22: error:
• Constructor ‘Auction2’ does not have the required strict field(s): auctioneer,
bidder, object, dateAuction
You didn’t specify all fields here when calling create Action2
. The first 3 can be copied from Auction2
either by specifying them manually or by using ..
which copies the fields of the given name that are already in scope. I don’t know what you want to set dateAuction
to. In the interest of fixing the error so we can take a look at later errors, let’s set it to the current date. Note that you need to import
DA.Date` for this to work.
currentTime <- getTime
create Auction2
with
limit = 10.0
start = 10.30
end = 11.00
bid= 1000.00
currency = "Pound"
auctioneer = auctioneer
bidder = bidder
object = object
dateAuction = toDateUTC currentTime
And on to the next error:
• No instance for (IsNumeric Time) arising from the literal ‘10.30’
This comes from start = 10.30
. 10.30
is a numeric value but you need a time here. You could specify a time using the functions from DA.Time
. However, I think there might actually be another issue here: Your choice defines a number of arguments including start
or startArg
. However you are not actually using them anywhere. I’m also not sure about the relationship between the fields in the choice argument and the fields in the template. If they are always idenical you don’t need the choice argument. Let’s assume for now that they are not but make sure that we actually use the choice arguments instead of setting the fields to fixed values (however I do recommend understanding how the two relate, I wouldn’t be surprised if you can just delete them from the choice arguments):
create Auction2
with
limit = limitArg
start = startArg
end = endArg
bid= bidArg
currency = currencyArg
auctioneer = auctioneer
bidder = bidder
object = object
dateAuction = toDateUTC currentTime
And at that point we’ve resolved all compile errors!