accordproject / template-archive

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

feat(server) Add new /get/:template endpoint implementation #750

Closed mehmettokgoz closed 1 year ago

mehmettokgoz commented 2 years ago

Changes

Flags

Demo

Sample request.body (Does not contain any argument):

{}

Response to sample request:

{
    "result": [
        {
            "name": "@models.accordproject.org.time@0.2.0.cto",
            "namespace": "org.accordproject.time",
            "content": "/*\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nnamespace org.accordproject.time\n\n/**\n * Months of the year\n */\nenum Month {\n  o January\n  o February\n  o March\n  o April\n  o May\n  o June\n  o July\n  o August\n  o September\n  o October\n  o November\n  o December\n}\n\n/**\n * Days of the week\n */\nenum Day {\n  o Monday\n  o Tuesday\n  o Wednesday\n  o Thursday\n  o Friday\n  o Saturday\n  o Sunday\n}\n\n/**\n * Units for a duration.\n */\nenum TemporalUnit {\n  o seconds\n  o minutes\n  o hours\n  o days\n  o weeks\n}\n\n/**\n * A duration. For example, 6 hours.\n */\nconcept Duration {\n  o Long amount\n  o TemporalUnit unit\n}\n\n/**\n * Units for a time period.\n */\nenum PeriodUnit {\n  o days\n  o weeks\n  o months\n  o quarters\n  o years\n}\n\n/**\n * A time period. For example, 2 months.\n */\nconcept Period {\n  o Long amount\n  o PeriodUnit unit\n}\n"
        },
        {
            "name": "@models.accordproject.org.accordproject.money@0.2.0.cto",
            "namespace": "org.accordproject.money",
            "content": "/*\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nnamespace org.accordproject.money\n\n/**\n * Represents an amount of Cryptocurrency\n */\nconcept DigitalMonetaryAmount {\n  o Double doubleValue\n  o DigitalCurrencyCode digitalCurrencyCode\n}\n\n/**\n * Digital Currency codes. From https://en.wikipedia.org/wiki/List_of_cryptocurrencies\n */\nenum DigitalCurrencyCode {\n  o ADA\n  o BCH\n  o BTC\n  o DASH\n  o EOS\n  o ETC\n  o ETH\n  o LTC\n  o NEO\n  o XLM\n  o XMR\n  o XRP\n  o ZEC\n}\n\n/**\n * Represents an amount of money\n */\nconcept MonetaryAmount {\n  o Double doubleValue // convert to fixed-point?\n  o CurrencyCode currencyCode\n}\n\n/**\n * ISO 4217 codes. From https://en.wikipedia.org/wiki/ISO_4217\n * https://www.currency-iso.org/en/home/tables/table-a1.html\n */\nenum CurrencyCode {\no AED\no AFN\no ALL\no AMD\no ANG\no AOA\no ARS\no AUD\no AWG\no AZN\no BAM\no BBD\no BDT\no BGN\no BHD\no BIF\no BMD\no BND\no BOB\no BOV\no BRL\no BSD\no BTN\no BWP\no BYN\no BZD\no CAD\no CDF\no CHE\no CHF\no CHW\no CLF\no CLP\no CNY\no COP\no COU\no CRC\no CUC\no CUP\no CVE\no CZK\no DJF\no DKK\no DOP\no DZD\no EGP\no ERN\no ETB\no EUR\no FJD\no FKP\no GBP\no GEL\no GHS\no GIP\no GMD\no GNF\no GTQ\no GYD\no HKD\no HNL\no HRK\no HTG\no HUF\no IDR\no ILS\no INR\no IQD\no IRR\no ISK\no JMD\no JOD\no JPY\no KES\no KGS\no KHR\no KMF\no KPW\no KRW\no KWD\no KYD\no KZT\no LAK\no LBP\no LKR\no LRD\no LSL\no LYD\no MAD\no MDL\no MGA\no MKD\no MMK\no MNT\no MOP\no MRU\no MUR\no MVR\no MWK\no MXN\no MXV\no MYR\no MZN\no NAD\no NGN\no NIO\no NOK\no NPR\no NZD\no OMR\no PAB\no PEN\no PGK\no PHP\no PKR\no PLN\no PYG\no QAR\no RON\no RSD\no RUB\no RWF\no SAR\no SBD\no SCR\no SDG\no SEK\no SGD\no SHP\no SLL\no SOS\no SRD\no SSP\no STN\no SVC\no SYP\no SZL\no THB\no TJS\no TMT\no TND\no TOP\no TRY\no TTD\no TWD\no TZS\no UAH\no UGX\no USD\no USN\no UYI\no UYU\no UZS\no VEF\no VND\no VUV\no WST\no XAF\no XAG\no XAU\no XBA\no XBB\no XBC\no XBD\no XCD\no XDR\no XOF\no XPD\no XPF\no XPT\no XSU\no XTS\no XUA\no XXX\no YER\no ZAR\no ZMW\no ZWL\n}\n\n/**\n * Represents a currency conversion pair and exchange rate\n */\nconcept CurrencyConversion {\n   o CurrencyCode from\n   o CurrencyCode to\n   o Double rate\n}\n"
        },
        {
            "name": "@models.accordproject.org.accordproject.contract.cto",
            "namespace": "org.accordproject.contract",
            "content": "/*\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nconcerto version \">= 1.0.0\"\n\nnamespace org.accordproject.contract\n\n/**\n * Contract Data\n * -- Describes the structure of contracts and clauses\n */\n\n/* A contract is a asset -- This contains the contract data */\nabstract asset Contract identified by contractId {\n  o String contractId\n}\n\n/* A clause is an asset -- This contains the clause data */\nabstract asset Clause identified by clauseId {\n  o String clauseId\n}\n"
        },
        {
            "name": "@models.accordproject.org.accordproject.runtime.cto",
            "namespace": "org.accordproject.runtime",
            "content": "/*\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nconcerto version \">= 1.0.0\"\n\nnamespace org.accordproject.runtime\n\nimport org.accordproject.contract.Contract from https://models.accordproject.org/accordproject/contract.cto\n\n/**\n * Runtime API\n * -- Describes input and output of calls to a contract's clause\n */\n\n/* A request is a transaction */\ntransaction Request {\n}\n\n/* A response is a transaction */\ntransaction Response {\n}\n\n/* An event that represents an obligation that needs to be fulfilled */\nabstract event Obligation identified {\n  /* A back reference to the governing contract that emitted this obligation */\n  --> Contract contract\n\n  /* The party that is obligated */\n  --> Participant promisor optional\n\n  /* The party that receives the performance */\n  --> Participant promisee optional\n\n  /* The time before which the obligation is fulfilled */\n  o DateTime deadline optional\n}\n\n/* A contract state is an asset -- The runtime state of the contract */\nasset State {\n}\n"
        },
        {
            "name": "@org.accordproject.ergo.options.cto",
            "namespace": "org.accordproject.ergo.options",
            "content": "/*\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nnamespace org.accordproject.ergo.options\n\nconcept Options {\n  o Boolean wrapVariables\n  o Boolean template\n}\n"
        },
        {
            "name": "model.cto",
            "namespace": "org.accordproject.latedeliveryandpenalty",
            "content": "namespace org.accordproject.latedeliveryandpenalty\n\nimport org.accordproject.time.TemporalUnit from https://models.accordproject.org/time@0.2.0.cto\nimport org.accordproject.time.Duration from https://models.accordproject.org/time@0.2.0.cto\n\nimport org.accordproject.contract.Clause from https://models.accordproject.org/accordproject/contract.cto\nimport org.accordproject.runtime.Request from https://models.accordproject.org/accordproject/runtime.cto\nimport org.accordproject.runtime.Response from https://models.accordproject.org/accordproject/runtime.cto\n\n/**\n * Defines the data model for the LateDeliveryAndPenalty template.\n * This defines the structure of the abstract syntax tree that the parser for the template\n * must generate from input source text.\n */\nasset TemplateModel extends Clause {\n  /**\n   * Does the clause include a force majeure provision?\n   */\n  o Boolean forceMajeure\n\n  /**\n   * For every penaltyDuration that the goods are late\n   */\n  o Duration penaltyDuration\n\n  /**\n   * Seller pays the buyer penaltyPercentage % of the value of the goods\n   */\n  o Double penaltyPercentage\n\n  /**\n   * Up to capPercentage % of the value of the goods\n   */\n  o Double capPercentage\n\n  /**\n   * If the goods are >= termination late then the buyer may terminate the contract\n   */\n  o Duration termination\n\n  /**\n   * Fractional part of a ... is considered a whole ...\n   */\n  o TemporalUnit fractionalPart\n}\n\n/**\n * Defines the input data required by the template\n */\ntransaction LateDeliveryAndPenaltyRequest extends Request {\n\n  /**\n   * Are we in a force majeure situation? \n   */\n  o Boolean forceMajeure\n\n  /**\n   * What was the agreed delivery date for the goods?\n   */\n  o DateTime agreedDelivery\n\n  /**\n   * If the goods have been delivered, when where they delivered?\n   */\n  o DateTime deliveredAt optional\n\n  /**\n   * What is the value of the goods?\n   */\n  o Double goodsValue\n}\n\n/**\n * Defines the output data for the template\n */\ntransaction LateDeliveryAndPenaltyResponse extends Response {\n  /**\n   * The penalty to be paid by the seller\n   */\n  o Double penalty\n\n  /**\n   * Whether the buyer may terminate the contract \n   */\n  o Boolean buyerMayTerminate\n}"
        },
        {
            "name": "test.cto",
            "namespace": "org.accord.test",
            "content": "namespace org.accord.test\n\n\nenum Status {\n  o ON\n  o OFF\n}\n\nconcept Child {\n  o String name\n}\n\n/**\n * A test concept\n */\nconcept Foo {\n  o String bar\n  --> Participant p\n  --> Asset a\n  o Double d\n  o Long l\n  o DateTime t\n  o Boolean b\n  o Status s\n  o Integer i\n  o Child child\n}"
        }
    ]
}

Author Checklist

coveralls commented 1 year ago

Coverage Status

Coverage increased (+0.03%) to 93.657% when pulling ab7c79b6c9ac6ccbc8bdeefb7546597b70ea1760 on mehmettokgoz:get into 62a2f44c40e26cd417c6502933f63f467e8fa579 on accordproject:master.