Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(engine) Now supports init clause with parameters #620

Merged
merged 1 commit into from
Mar 15, 2021

Conversation

jeromesimeon
Copy link
Member

@jeromesimeon jeromesimeon commented Mar 15, 2021

Signed-off-by: Jerome Simeon jeromesimeon@me.com

Closes #604

Changes

  • The Ergo engine always supported parameters passed during initialisation, but this wasn't exposed in the Cicero engine API (See Expose the request to cicero-engine.init() #604 )
  • This PR adds proper support for initialisation a clause based on input parameters
  • This defaults to no parameters (i.e., params = {}) so should be backward compatible
  • Also adds corresponding --params option to the Cicero CLI for cicero initialize

Screenshots or Video

From the command line:

zsh-5.8$ cat logic/logic.ergo 
namespace org.accordproject.helloworldstate

import org.accordproject.cicero.runtime.*

contract HelloWorldState over HelloWorldClause state HelloWorldState {
  clause init(startsAt : Double) : Response {
    set state HelloWorldState{
      stateId: "org.accordproject.helloworldstate.HelloWorldState#0.0",
      counter: startsAt
    };
    return Response{}
  }
//...
}
zsh-5.8$ more params.json 
{ "startsAt": 2.0 }
zsh-5.8$ ../../../../cicero-cli/index.js initialize --params params.json
1:47:21 PM - info: Using current directory as template folder
1:47:21 PM - info: Loading a default text/sample.md file.
1:47:23 PM - info:
{
  "clause": "helloworldstate@0.14.0-ea7f05bd482853ac1b4f72626bcb1c09ac69572796fa27e499205371bfac57ec",
  "params": {
    "startsAt": 2
  },
  "response": {
    "$class": "org.accordproject.cicero.runtime.Response",
    "transactionId": "4c620340-9d5f-4283-8a33-63fc2c38d8f0",
    "timestamp": "2021-03-15T17:47:23.945Z"
  },
  "state": {
    "$class": "org.accordproject.helloworldstate.HelloWorldState",
    "counter": 2,
    "stateId": "org.accordproject.helloworldstate.HelloWorldState#0.0"
  },
  "emit": []
}

Copy link
Sponsor Contributor

@dselman dselman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Thanks!

Signed-off-by: Jerome Simeon <jeromesimeon@me.com>
@jeromesimeon jeromesimeon merged commit 5b36eca into master Mar 15, 2021
@jeromesimeon jeromesimeon deleted the js-feature-604 branch April 8, 2021 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose the request to cicero-engine.init()
2 participants