Skip to content
This repository was archived by the owner on Sep 7, 2023. It is now read-only.
This repository was archived by the owner on Sep 7, 2023. It is now read-only.

Can't emit an array of obligations formed from an array of values #838

@frbrkoala

Description

@frbrkoala

Bug Report 🐛

I need to emit multiple events based on the list of vendors, specified in my contract.

Here is how I envision that:

My grammar.tem.md:

[...]
{{#ulist vendors}}
{{businessName}}
{{/ulist}}
[...]

My model.cto:

event VendorNotification {
        o String code
        o String description
        o Vendor vendor
}

transaction NotifyVendorsReq extends Request {
  o String detectionCode
  o String description
}

transaction NotifyVendorsRes extends Response {
  o String output
}

participant Vendor identified by businessName {
  o String businessName
}
asset MyContract extends Contract {
  o Vendor[] vendors
}

And logic.ergo:

contract MyContractLogic over MyContract state State {
  
  //Iterate through an array of vendors and emit an event for each of them
  clause notifyVendors(request : NotifyVendorsReq) : NotifyVendorsRes emits VendorNotification[] {

    emit foreach vendor in contract.vendors
    return VendorNotification {
        code: request.notificationCode,
        description: request.description,
        vendor: vendor
     };
    
    return NotifyVendorsRes{ output: "Received " ++ request.notificationCode ++ " " ++ request.description ++ " and sent notification to vendors " ++ toString(contract.vendors) }
  }
}

cicero trigger throws “ERROR: Cannot read property ‘$coll’ of undefined”

Expected Behavior

The contract should emit an array of events

Current Behavior

Throws an error: “ERROR: Cannot read property ‘$coll’ of undefined”

Possible Solution

Would be good to make emit function compatible with an array of events.

Steps to Reproduce

Please see the bug report section.

Context (Environment)

Desktop

  • OS: macOS
  • Browser: NodeJS v10.18.1
  • Version: "cicero": "^0.22.1"

Detailed Description

The emit function can receive an array of events and emit them one-by-one to address the situation when multiple events need to be emitted in one go.

Possible Implementation

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions