Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Commit

Permalink
(fix) Remove unneeded --contractName in CLI
Browse files Browse the repository at this point in the history
Signed-off-by: Jerome Simeon <jeromesimeon@me.com>
  • Loading branch information
jeromesimeon committed Apr 30, 2019
1 parent 8f59079 commit 5f61880
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 63 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ the compiled JavaScript code in `./examples/volumediscount/logic.js`
To compile and execute a contract by sending a request:

```text
$ ergorun execute ./examples/volumediscount/model.cto ./examples/volumediscount/logic.ergo --contractName org.accordproject.volumediscount.VolumeDiscount --contract ./examples/volumediscount/contract.json --request ./examples/volumediscount/request.json --state ./examples/volumediscount/state.json
$ ergorun execute ./examples/volumediscount/model.cto ./examples/volumediscount/logic.ergo --contract ./examples/volumediscount/contract.json --request ./examples/volumediscount/request.json --state ./examples/volumediscount/state.json
06:40:01 - info:
{
"response": {
Expand All @@ -103,7 +103,7 @@ $ ergorun execute ./examples/volumediscount/model.cto ./examples/volumediscount/
To compile and invoke a specific contract clause:

```text
$ ergorun invoke ./examples/volumediscount/model.cto ./examples/volumediscount/logic.ergo --contractName org.accordproject.volumediscount.VolumeDiscount --clauseName volumediscount --contract ./examples/volumediscount/contract.json --params ./examples/volumediscount/params.json --state ./examples/volumediscount/state.json
$ ergorun invoke ./examples/volumediscount/model.cto ./examples/volumediscount/logic.ergo --clauseName volumediscount --contract ./examples/volumediscount/contract.json --params ./examples/volumediscount/params.json --state ./examples/volumediscount/state.json
06:40:29 - info:
{
"response": {
Expand All @@ -121,7 +121,7 @@ $ ergorun invoke ./examples/volumediscount/model.cto ./examples/volumediscount/l
To compile and obtain the initial state for the contract:

```text
$ ergorun init ./examples/volumediscount/model.cto ./examples/volumediscount/logic.ergo --contractName org.accordproject.volumediscount.VolumeDiscount --contract ./examples/volumediscount/contract.json
$ ergorun init ./examples/volumediscount/model.cto ./examples/volumediscount/logic.ergo --contract ./examples/volumediscount/contract.json
06:40:29 - info:
{
"response": null,
Expand Down
21 changes: 6 additions & 15 deletions packages/ergo-cli/bin/ergorun.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ const Logger = require('@accordproject/ergo-compiler').Logger;

require('yargs')
.command('execute', 'execute an Ergo contract with a request', (yargs) => {
yargs.demandOption(['contractName', 'contract', 'request'], 'Please provide at least the contractName, with contract data and request');
yargs.demandOption(['contract', 'request'], 'Please provide at least the contract data and request');
yargs.usage('Usage: $0 --contract [file] --state [file] --request [file] [ctos] [ergos]');
yargs.option('contractName', {
describe: 'the name of the contract'
});
yargs.option('contract', {
describe: 'path to the contract data'
});
Expand Down Expand Up @@ -63,7 +60,7 @@ require('yargs')
}

// Run contract
Commands.execute(ergoPaths, ctoPaths, argv.contractName, { file: argv.contract }, argv.state ? { file: argv.state } : null, argv.currentTime, argv.request.map(r => { return { file: r }; }))
Commands.execute(ergoPaths, ctoPaths, { file: argv.contract }, argv.state ? { file: argv.state } : null, argv.currentTime, argv.request.map(r => { return { file: r }; }))
.then((result) => {
Logger.info(JSON.stringify(result));
})
Expand All @@ -72,11 +69,8 @@ require('yargs')
});
})
.command('invoke', 'invoke a clause for an Ergo contract', (yargs) => {
yargs.demandOption(['contractName', 'clauseName', 'contract', 'state', 'params'], 'Please provide at least the contractName and clauseName, with contract data, state, and params');
yargs.demandOption(['clauseName', 'contract', 'state', 'params'], 'Please provide at least the clauseName, with contract data, state, and params');
yargs.usage('Usage: $0 --contract [file] --state [file] --params [file] [ctos] [ergos]');
yargs.option('contractName', {
describe: 'the name of the contract'
});
yargs.option('clauseName', {
describe: 'the name of the clause to invoke'
});
Expand Down Expand Up @@ -118,7 +112,7 @@ require('yargs')
}

// Run contract
Commands.invoke(ergoPaths, ctoPaths, argv.contractName, argv.clauseName, { file: argv.contract }, { file: argv.state }, argv.currentTime, { file: argv.params })
Commands.invoke(ergoPaths, ctoPaths, argv.clauseName, { file: argv.contract }, { file: argv.state }, argv.currentTime, { file: argv.params })
.then((result) => {
Logger.info(JSON.stringify(result));
})
Expand All @@ -127,11 +121,8 @@ require('yargs')
});
})
.command('init', 'invoke init for an Ergo contract', (yargs) => {
yargs.demandOption(['contractName', 'contract'], 'Please provide at least contract, params and contractName');
yargs.demandOption(['contract'], 'Please provide at least contract and params');
yargs.usage('Usage: $0 --contract [file] --params [file] [ctos] [ergos]');
yargs.option('contractName', {
describe: 'the name of the contract'
});
yargs.option('contract', {
describe: 'path to the contract data'
});
Expand Down Expand Up @@ -166,7 +157,7 @@ require('yargs')
}

// Run contract
Commands.init(ergoPaths, ctoPaths, argv.contractName, { file: argv.contract }, argv.currentTime, argv.params ? { file: argv.params } : { content: '{}' })
Commands.init(ergoPaths, ctoPaths, { file: argv.contract }, argv.currentTime, argv.params ? { file: argv.params } : { content: '{}' })
.then((result) => {
Logger.info(JSON.stringify(result));
})
Expand Down
20 changes: 7 additions & 13 deletions packages/ergo-cli/lib/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,16 @@ class Commands {
*
* @param {string[]} ergoPaths paths to the Ergo modules
* @param {string[]} ctoPaths paths to CTO models
* @param {string} contractName of the contract
* @param {string} contractInput the contract data
* @param {string} stateInput the contract state
* @param {string} currentTime the definition of 'now'
* @param {string[]} requestsInput the requests
* @returns {object} Promise to the result of execution
*/
static execute(ergoPaths,ctoPaths,contractName,contractInput,stateInput,currentTime,requestsInput) {
static execute(ergoPaths,ctoPaths,contractInput,stateInput,currentTime,requestsInput) {
const engine = new Engine();
const templateLogic = new TemplateLogic('es6');
templateLogic.addErgoBuiltin();
templateLogic.setContractName(contractName);
if (!ergoPaths) { return Promise.reject('No input ergo found'); }
for (let i = 0; i < ergoPaths.length; i++) {
const ergoFile = ergoPaths[i];
Expand All @@ -76,15 +74,15 @@ class Commands {
}
let initResponse;
if (stateInput === null) {
initResponse = engine.compileAndInit(templateLogic, contractName, contractJson, {}, currentTime);
initResponse = engine.compileAndInit(templateLogic, contractJson, {}, currentTime);
} else {
const stateJson = getJson(stateInput);
initResponse = Promise.resolve({ state: stateJson });
}
// Get all the other requests and chain execution through Promise.reduce()
return requestsJson.reduce((promise,requestJson) => {
return promise.then((result) => {
return engine.compileAndExecute(templateLogic,contractName,contractJson,requestJson,result.state,currentTime);
return engine.compileAndExecute(templateLogic, contractJson, requestJson, result.state, currentTime);
});
}, initResponse);
}
Expand All @@ -94,19 +92,17 @@ class Commands {
*
* @param {string[]} ergoPaths paths to the Ergo modules
* @param {string[]} ctoPaths paths to CTO models
* @param {string} contractName the contract
* @param {string} clauseName the name of the clause to invoke
* @param {string} contractInput the contract data
* @param {string} stateInput the contract state
* @param {string} currentTime the definition of 'now'
* @param {object} paramsInput the parameters for the clause
* @returns {object} Promise to the result of invocation
*/
static invoke(ergoPaths,ctoPaths,contractName,clauseName,contractInput,stateInput,currentTime,paramsInput) {
static invoke(ergoPaths,ctoPaths,clauseName,contractInput,stateInput,currentTime,paramsInput) {
const engine = new Engine();
const templateLogic = new TemplateLogic('es6');
templateLogic.addErgoBuiltin();
templateLogic.setContractName(contractName);
if (!ergoPaths) { return Promise.reject('No input ergo found'); }
for (let i = 0; i < ergoPaths.length; i++) {
const ergoFile = ergoPaths[i];
Expand All @@ -122,25 +118,23 @@ class Commands {
const contractJson = getJson(contractInput);
const clauseParams = getJson(paramsInput);
const stateJson = getJson(stateInput);
return engine.compileAndInvoke(templateLogic,contractName,clauseName,contractJson,clauseParams,stateJson,currentTime);
return engine.compileAndInvoke(templateLogic, clauseName, contractJson, clauseParams, stateJson, currentTime);
}

/**
* Invoke init for an Ergo contract
*
* @param {string[]} ergoPaths paths to the Ergo modules
* @param {string[]} ctoPaths paths to CTO models
* @param {string} contractName the contract name
* @param {string} contractInput the contract data
* @param {string} currentTime the definition of 'now'
* @param {object} paramsInput the parameters for the clause
* @returns {object} Promise to the result of execution
*/
static init(ergoPaths,ctoPaths,contractName,contractInput,currentTime,paramsInput) {
static init(ergoPaths,ctoPaths,contractInput,currentTime,paramsInput) {
const engine = new Engine();
const templateLogic = new TemplateLogic('es6');
templateLogic.addErgoBuiltin();
templateLogic.setContractName(contractName);
if (!ergoPaths) { return Promise.reject('No input ergo found'); }
for (let i = 0; i < ergoPaths.length; i++) {
const ergoFile = ergoPaths[i];
Expand All @@ -155,7 +149,7 @@ class Commands {
}
const contractJson = getJson(contractInput);
const clauseParams = getJson(paramsInput);
return engine.compileAndInit(templateLogic,contractName,contractJson,clauseParams,currentTime);
return engine.compileAndInit(templateLogic, contractJson, clauseParams, currentTime);
}

/**
Expand Down
Loading

0 comments on commit 5f61880

Please sign in to comment.