accordproject / template-archive

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

Clarify / make more uniform handling for templates without logic #597

Open jeromesimeon opened 4 years ago

jeromesimeon commented 4 years ago

Is your feature request related to a problem? Please describe. Currently:

This can be a bit surprising, especially cicero initialize sometimes works when there is no logic (e.g., when a formula is in the template grammar).

Also this means testing logicless templates is somewhat cumbersome / different from other templates.

This can also mean some API calls will throw lower-level exceptions for logicless templates in some cases.

Describe the solution you'd like More uniform handling of templates with or without logic. For instance:

Additional context Example with the signature block template from https://templates.accordproject.org/signature-block-title-name-date@0.19.0.html

bash-3.2$ cicero --version
0.21.9
bash-3.2$ cicero parse 
2:49:18 PM - info: Using current directory as template folder
2:49:18 PM - info: Loading a default text/sample.md file.
2:49:19 PM - info:
{
  "$class": "org.accordproject.signature.tnd.TitleNameDateSignatureBlock",
  "title": "Title",
  "signature": "--------",
  "fullName": "Full Name",
  "dateSigned": "Date Signed",
  "signatory": "resource:org.accordproject.cicero.contract.AccordParty#buyer@example.com",
  "clauseId": "ddb2dcef-97ba-4aa4-ab70-7cc1002d0a52"
}
bash-3.2$ cicero initialize 
2:49:22 PM - info: Using current directory as template folder
2:49:22 PM - info: Loading a default text/sample.md file.
2:49:23 PM - error: Did not find any compiled JavaScript logic
jeromesimeon commented 4 years ago

^^^ @dselman

jeromesimeon commented 4 years ago

Note, this also mean that logicless templates, currently, cannot be open in template studio:

Screenshot 2020-10-07 at 3 07 41 PM Screenshot 2020-10-07 at 3 07 18 PM
sanketshevkar commented 3 years ago

@jeromesimeon while investigating this issue, I was working with ergo-engine code. I found out the following behaviour.

(node:29066) UnhandledPromiseRejectionWarning: TypeNotFoundException: Namespace is not defined for type org.accordproject.runtime.State
    at APModelManager.getType (/home/user/Desktop/templateHandling/node_modules/@accordproject/concerto-core/lib/modelmanager.js:569:19)
    at Serializer.fromJSON (/home/user/Desktop/templateHandling/node_modules/@accordproject/concerto-core/lib/serializer.js:149:52)
    at LogicManager.validateInput (/home/user/Desktop/templateHandling/node_modules/@accordproject/ergo-compiler/lib/logicmanager.js:324:39)
    at VMEngine.invoke (/home/user/Documents/ergo/packages/ergo-engine/lib/engine.js:170:34)
    at VMEngine.init (/home/user/Documents/ergo/packages/ergo-engine/lib/engine.js:215:21)
    at Engine.init (/home/user/Desktop/templateHandling/node_modules/@accordproject/cicero-engine/lib/engine.js:85:32)
    at main (/home/user/Desktop/templateHandling/index.js:20:30)

.

I guess v0.22.0 still must be in development so just thought of reporting this behaviour to you.

sanketshevkar commented 3 years ago

Hello @jeromesimeon , I wanted to test a template with formulae but without logic. Can you please suggest a template that I can use for the same?

jeromesimeon commented 3 years ago

I guess v0.22.0 still must be in development so just thought of reporting this behaviour to you.

It's expected. Not really because Ergo 0.22 is still an alpha version (although, of course it is), but simply because that new version is a breaking change so we have to make changes to template studio to support it.

jeromesimeon commented 3 years ago

Hello @jeromesimeon , I wanted to test a template with formulae but without logic. Can you please suggest a template that I can use for the same?

Look in the template library for templates without a logic directory (I think there are a few).

jeromesimeon commented 3 years ago

Hello @jeromesimeon , I wanted to test a template with formulae but without logic. Can you please suggest a template that I can use for the same?

Look in the template library for templates without a logic directory (I think there are a few).

@sanketshevkar I think I read your question a little fast. I don't think there is one without logic but with formulae... Someone will have to try and create one!

sanketshevkar commented 3 years ago

@jeromesimeon I have searched templates in cicero template library, but found none.

Also, I was curious that what would be the cases where there could be a need to initialize and trigger templates without logic? Since no logic involved, there is no state type, request type, response type and emit type associated with it.

If we want to initialize these templates we'll need at least need a state type and a response type associated with it. Is that correct?

jeromesimeon commented 3 years ago

@jeromesimeon I have searched templates in cicero template library, but found none.

Also, I was curious that what would be the cases where there could be a need to initialize and trigger templates without logic? Since no logic involved, there is no state type, request type, response type and emit type associated with it.

If we want to initialize these templates we'll need at least need a state type and a response type associated with it. Is that correct?

Those are all good question. I think it depends how you think of "no logic" is it really no logic, or is it "empty logic" in which case you could have a default initialisation to an empty state and no request would trigger execution but the trigger call could still exist.

sanketshevkar commented 3 years ago

Thank you @jeromesimeon. I think this problem is better handled from the ergo packages than cicero. I am trying the same. Would that be the correct thing to do?

Also, do all templates need to have a contractName? I am the same signature block template you used above. I'm getting a error in ergo-engine because the contractName is null.

(node:11895) UnhandledPromiseRejectionWarning: Error: Cannot create invoke call for target: cicero without a contract name
    at LogicManager.getInvokeCall (/home/user/Documents/ergo/packages/ergo-compiler/lib/logicmanager.js:144:23)
    at VMEngine.invoke (/home/user/Documents/ergo/packages/ergo-engine/lib/engine.js:180:34)
    at VMEngine.init (/home/user/Documents/ergo/packages/ergo-engine/lib/engine.js:227:21)
    at Engine.init (/home/user/Desktop/templateHandling/node_modules/@accordproject/cicero-engine/lib/engine.js:85:32)
jeromesimeon commented 3 years ago

@sanketshevkar I think it could probably be handled directly in template studio? This would be worth investigating as it's much less intrusive. (i.e., not do the invoke call in the first place)

sanketshevkar commented 3 years ago

@jeromesimeon, yeah I'll investigate this approach too. But then cicero init & cicero trigger would still fail.

I have changed some code on the ergo-engine and ergo-compiler v0.21.9 to solve this issue. Should I create a PR for that?

jeromesimeon commented 3 years ago

@jeromesimeon, yeah I'll investigate this approach too. But then cicero init & cicero trigger would still fail.

I have changed some code on the ergo-engine and ergo-compiler v0.21.9 to solve this issue. Should I create a PR for that?

Right. yes sorry I confused two different issues here maybe. If we do want to support initialise even in the absence of user-logic, it's quite possible that doing it in Ergo as you suggest would be better. And sure, if you have something to review, I'll be happy to take a look!

sanketshevkar commented 3 years ago

@jeromesimeon, yeah I'll investigate this approach too. But then cicero init & cicero trigger would still fail. I have changed some code on the ergo-engine and ergo-compiler v0.21.9 to solve this issue. Should I create a PR for that?

Right. yes sorry I confused two different issues here maybe. If we do want to support initialise even in the absence of user-logic, it's quite possible that doing it in Ergo as you suggest would be better. And sure, if you have something to review, I'll be happy to take a look!

Hi @jeromesimeon,

I have created a PR for the ergo respository.