contractpendev / contractpen-work-client

NodeJS Client for ContractPen
https://contractpen.com/
Apache License 2.0
2 stars 1 forks source link

Able to execute a stateful contract from Javascript API #3

Open contractpendev opened 6 years ago

contractpendev commented 6 years ago

Hi ! Please read and understand what this file does before starting any task https://github.com/contractpendev/contractpen_node_client/blob/master/src/services/SetupClient.coffee and also better to read and understand the existing code base. Refer to Accord Project https://www.accordproject.org/ Ergo API https://docs.accordproject.org/docs/ergo-api.html Cicero API https://docs.accordproject.org/docs/cicero-api.html


There is an example called HelloWorldState https://github.com/accordproject/cicero-template-library/tree/master/src/helloworldstate

If this is cloned

git clone https://github.com/accordproject/cicero-template-library
cd cicero-template-library
cd src
cd helloworldstate
npm install

Then execute

cicero execute

It should correctly output the following

11:07:21 AM - info: Using current directory as template folder
11:07:21 AM - info: Loading a default sample.txt file.
11:07:21 AM - info: Loading a single default request.json file.
11:07:21 AM - info: Loading a default state.json file.
11:07:23 AM - info: Compiling Ergo logic
11:07:24 AM - info:
{
  "clause": "helloworldstate@0.7.0-83f34ba2ec15e05b88625caa4a8f300fbc903ec59c7098328e267bbbbd7b35d4",
  "request": {
    "$class": "org.accordproject.helloworldstate.MyRequest",
    "input": "Accord Project"
  },
  "response": {
    "$class": "org.accordproject.helloworldstate.MyResponse",
    "output": "Hello Fred Blogs Accord Project(1.0)",
    "transactionId": "743481ce-990f-423e-a095-4472baabea2f",
    "timestamp": "2018-09-14T03:07:24.078Z"
  },
  "state": {
    "$class": "org.accordproject.helloworldstate.HelloWorldState",
    "counter": 1,
    "stateId": "org.accordproject.helloworldstate.HelloWorldState#0.0"
  },
  "emit": []
}

If you are on Windows and running from DOS (cmd) then you may get a slash r error so then change template.tem to be one line only

Name of the person to greet: [{name}].

Also change sample.txt to be one line only.

Name of the person to greet: "Fred Blogs".

Then it will run on windows, must be some small bug for running on windows.


The task here is achieve the same from Coffeescript by adding a new command to the contractpen_node_client project so that it will use Coffeescript to do the "execute" action.

I believe the right API method to use is here, execute on the Ergo Javascript API.

https://docs.accordproject.org/docs/ergo-api.html#Commands.execute

For reference here are the Javascript APIs.

https://docs.accordproject.org/docs/cicero-api.html

https://docs.accordproject.org/docs/ergo-api.html

So when a user runs the contractpen_node_client they should be able to pass two parameter, the first is execute and the second is the path of the project nodejs to execute.

eg.

run execute mycicerofolder

This is similar to the command in the previous issue https://github.com/contractpendev/contractpen_node_client/issues/1

Check that the following are true.

contractpendev commented 6 years ago

Done but not async await correct