accordproject / template-archive

Smart Legal Contracts & Templating System
https://accordproject.org/projects/cicero/
Apache License 2.0
281 stars 119 forks source link

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

Closed jeromesimeon closed 3 years ago

jeromesimeon commented 3 years ago

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

Closes #604

Changes

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": []
}