Skip to content

Commit

Permalink
v2.0.0
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
bakasura980 authored Sep 2, 2020
2 parents 77b6bd4 + 740af63 commit 57dc3ef
Show file tree
Hide file tree
Showing 89 changed files with 4,391 additions and 519 deletions.
93 changes: 92 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![npm version](https://badge.fury.io/js/eoslime.svg)](https://badge.fury.io/js/eoslime.svg)
[![codecov](https://codecov.io/gh/LimeChain/eoslime/branch/master/graph/badge.svg)](https://codecov.io/gh/LimeChain/eoslime)
[![support typescript](https://badgen.net/badge/Support/TypeScript/cyan)](https://badgen.net/badge/Support/TypeScript/cyan)

eoslime.js
============
Expand All @@ -23,13 +24,103 @@ Thanks these wonderful people for helping improve EOSLime
<td align="center"><a href="https://github.com/Avm07"><img src="https://avatars1.githubusercontent.com/u/24969602?s=400&u=c2ab916dba523284faa1310b363fed7ef27634f2&v=4" width="100px;" alt=""/><br/><sub><b>Artem</b></sub></a><br/>
<a href="https://github.com/LimeChain/eoslime/issues/53" title="Ideas">💡</a>
</td>
<td align="center"><a href="https://github.com/prcolaco"><img src="https://avatars2.githubusercontent.com/u/3846701?s=460&v=4" width="100px;" alt=""/><br/><sub><b>Pedro Reis Colaço</b></sub></a><br/>
<a href="https://github.com/LimeChain/eoslime/pulls/prcolaco" title="Code">💻</a>
</td>
</tr>
</table>



# Change log

## Version 2.0.0 change log
## [Typescript support && Codebase code coverage]
### Breaking changes
* Rename **Account.addAuthorityKey** to **Account.addOnBehalfKey**
* Rename **Account.executiveAuth** to **Account.authority**
* New way to access contract actions and tables
**Actions**
```
const tokenContract = await eoslime.Contract.at('contract name');
// Before
tokenContract.issue(params, options)
// Now
tokenContract.actions.issue([params], options)
```
**Tables**
```
const tokenContract = await eoslime.Contract.at('contract name');
// Before
tokenContract.balances()
// Now
tokenContract.tables.balances()
```
* Contract.on('deploy')
```
// Before
Contract.on('deploy', (tx, contract) => {}))
// Now
Contract.on('deploy', (contract, tx) => {}))
```
* Remove AuthorityAccount
* Deprecate **Account.createSubAuthority**
* Replace **createSubAuthority** with **addAuthority**
```
const account = await eoslime.Account.createRandom();
// ------------ [ Before ] ------------
// Add subAuthority and return an instance of AuthorityAccount
const subAuthorityAccount = await account.createSubAuthority('subauthority');
// Add what actions the new authority could access
await subAuthorityAccount.setAuthorityAbilities([
{ action: 'produce', contract: faucetContract.name }
]);
// ------------ [ Now ] ------------
// Add subAuthority and return tx receipt
const tx = await account.addAuthority('subauthority');
// Add what actions the new authority could access
await account.setAuthorityAbilities('subauthority', [
{ action: 'produce', contract: faucetContract.name }
]);
const subAuthorityAccount = eoslime.Account.load('name', 'key', 'subauthority');
```

### News
* Typescript support
* Refactor CLI commands
* Fix nodeos pre-loaded accounts to have different keys
* Unit tests for all CLI commands
* Return transaction receipts on every chain iteraction
* Use logger instead console.log
* Update Kylin network endpoint
* Add Jungle3 support
* Remove the check requiring an executor to be provided on contract instantiation. Without executor, one could fetch only the data from the contract tables
* contract.action.sign(params)
```
// Before
contract.action.sign(params)
// Now
// Options are the same like the ones for contract.action(params, options)
contract.actions.action.sign([params], options)
```
* contract.action.getRawTransaction(params)
```
// Before
contract.action.getRawTransaction(params)
// Now
// Options are the same like the ones for contract.action(params, options)
contract.actions.action.getRawTransaction([params], options)
```

## Version 1.0.4 change log

* **eoslime nodeos**
Expand Down Expand Up @@ -91,7 +182,7 @@ EOSLIME was able to be initialized only with pre-configured providers connection
const eoslime = require('eoslime').init('bos', { url: 'Your url', chainId: 'Your chainId' });
// ... any other supported netwok ...
```
* **Allow read-only contracts** - You are able now to instantiate a contract withouth a signer/executor and read the contract's tables
* **Allow read-only contracts** - You are able now to instantiate a contract without a signer/executor and read the contract's tables
* **Add Tutorial section in the documentation**
* **Describe how examples in the documentation could be run**
* **Increase the code coverage from 46% to 90+ %**
Expand Down
6 changes: 3 additions & 3 deletions cli-commands/command-definer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class CommandDefiner {
constructor(yargs) {
constructor (yargs) {
this.yargs = yargs;
}

Expand Down Expand Up @@ -28,8 +28,8 @@ class CommandDefiner {

handle (command) {
return async (args) => {
const result = await command.execute(args);
if (!result) {
await command.execute(args);
if (!command.hasBeenExecuted) {
this.yargs.showHelp();
}
}
Expand Down
7 changes: 4 additions & 3 deletions cli-commands/commands/command.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
class Command {
constructor(commandDefinition) {
constructor (commandDefinition) {
this.subcommands = [];
this.options = commandDefinition.options || [];
this.template = commandDefinition.template || '';
this.description = commandDefinition.description || '';

this.hasBeenExecuted = true;
}

async processOptions (args) {
Expand All @@ -21,8 +23,7 @@ class Command {
return optionResults;
}

execute (args) { }

async execute (args) { }
}

module.exports = Command;
31 changes: 19 additions & 12 deletions cli-commands/commands/compile/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const AsyncSoftExec = require('../../helpers/async-soft-exec');
const Command = require('../command');

const commandMessages = require('./messages');
const MESSAGE_COMMAND = require('./messages').COMMAND;
const MESSAGE_CONTRACT = require('./messages').CONTRACT;

const compiledDirectories = require('./specific/directories.json');
const compileCommandDefinition = require('./definition');

Expand All @@ -11,13 +13,13 @@ const fileSysUtils = require('../../helpers/file-system-util');

class CompileCommand extends Command {

constructor() {
constructor () {
super(compileCommandDefinition);
}

async execute (args) {
try {
commandMessages.StartCompilation();
MESSAGE_COMMAND.Start();

const optionsResults = await super.processOptions(args);

Expand All @@ -26,20 +28,25 @@ class CompileCommand extends Command {

for (let i = 0; i < optionsResults.path.length; i++) {
const contractPath = optionsResults.path[i];
// Todo: Check how to compile without using eosio-cpp
const asyncSoftExec = new AsyncSoftExec(`eosio-cpp -I . -o ./compiled/${contractPath.fileName}.wasm ${contractPath.fullPath} --abigen`);
asyncSoftExec.onError((error) => commandMessages.UnsuccessfulCompilationOfContract(error, contractPath.fileName));
asyncSoftExec.onSuccess(() => commandMessages.SuccessfulCompilationOfContract(contractPath.fileName));

await asyncSoftExec.exec();
await processCompilation(contractPath)
}
} else {
commandMessages.ContractNotExisting();
MESSAGE_CONTRACT.NotFound();
}
} catch (error) {
commandMessages.UnsuccessfulCompilation(error);
MESSAGE_COMMAND.Error(error);
}
return true;
}
}

const processCompilation = async function (contract) {
try {
const asyncSoftExec = new AsyncSoftExec(`eosio-cpp -I . -o ./compiled/${contract.fileName}.wasm ${contract.fullPath} --abigen`);
await asyncSoftExec.exec();

MESSAGE_CONTRACT.Compiled(contract.fileName);
} catch (error) {
MESSAGE_CONTRACT.NotCompiled(error, contract.fileName);
}
}

Expand Down
20 changes: 9 additions & 11 deletions cli-commands/commands/compile/messages.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
const chalk = require('chalk');
const logger = require('../../common/logger');

module.exports = {
'StartCompilation': () => { console.log(chalk.magentaBright('===== Compilation has started... =====')); },
'UnsuccessfulCompilation': (error) => {
console.log(chalk.redBright(`===== Unsuccessful compilation =====`));
console.log(error);
'CONTRACT': {
'Compiled': (contract) => { logger.success(`===== ${contract} has been successfully compiled =====`); },
'NotCompiled': (error, file) => { logger.error(`===== Unsuccessful compilation of ${file} =====`, error); },
'NotFound': () => { logger.info(`===== There is not a contract to compile =====`); }
},
'SuccessfulCompilationOfContract': (contract) => { console.log(chalk.greenBright(`===== Successfully compilation of ${contract} =====`)); },
'UnsuccessfulCompilationOfContract': (error, file) => {
console.log(chalk.redBright(`===== Unsuccessful compilation of ${file} =====`));
console.log(error);
},
'ContractNotExisting': () => { console.log(chalk.redBright(`===== There is not a contract to compile =====`)); }
'COMMAND': {
'Start': () => { logger.info('===== Compilation has started... ====='); },
'Error': (error) => { logger.error(`===== Unsuccessful compilation =====`, error); },
}
}
5 changes: 3 additions & 2 deletions cli-commands/commands/compile/options/path-option.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const fileSystemUtil = require('../../../helpers/file-system-util');
const path = require('path');

const Option = require('../../option');

class PathOption extends Option {

constructor() {
constructor () {
super(
'path',
{
Expand All @@ -28,7 +29,7 @@ class PathOption extends Option {
});
}

return optionValue.endsWith('.cpp') ? [`${__dirname}/${optionValue}`] : [];
return optionValue.endsWith('.cpp') ? [{ fullPath: optionValue, fileName: path.basename(optionValue, '.cpp') }] : [];
}
}

Expand Down
16 changes: 9 additions & 7 deletions cli-commands/commands/deploy/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
const Command = require('../command');

const commandMessages = require('./messages');
const MESSAGE_COMMAND = require('./messages').COMMAND;
const MESSAGE_SCRIPT = require('./messages').SCRIPT;

const deployCommandDefinition = require('./definition');

// eoslime deploy --path --network --deployer

class DeployCommand extends Command {
constructor() {
constructor () {
super(deployCommandDefinition);
}

async execute (args) {
try {
commandMessages.StartDeployment();
MESSAGE_COMMAND.Start();

const optionsResults = await super.processOptions(args);
await runDeploymentScripts(optionsResults.path, optionsResults.network, optionsResults.deployer);
} catch (error) {
commandMessages.UnsuccessfulDeployment(error);
MESSAGE_COMMAND.Error(error);
}
return true;
}
}

Expand All @@ -27,9 +29,9 @@ const runDeploymentScripts = async function (deploymentScripts, ...configuration
const deploymentScript = deploymentScripts[i];
try {
await deploymentScript.deploy(...configuration);
commandMessages.SuccessfulDeploymentOfScript(deploymentScript.fileName);
MESSAGE_SCRIPT.Processed(deploymentScript.fileName);
} catch (error) {
commandMessages.UnsuccessfulDeploymentOfScript(deploymentScript.fileName, error);
MESSAGE_SCRIPT.NotProcessed(deploymentScript.fileName, error);
}
}
}
Expand Down
16 changes: 7 additions & 9 deletions cli-commands/commands/deploy/messages.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
const chalk = require('chalk');
const logger = require('../../common/logger');

module.exports = {
'StartDeployment': () => { console.log(chalk.magentaBright('===== Deployment has started... =====')); },
'SuccessfulDeploymentOfScript': (script) => { console.log(chalk.greenBright(`===== Successful deployment of ${script} =====`)); },
'UnsuccessfulDeploymentOfScript': (script, error) => {
console.log(chalk.redBright(`===== Unsuccessful deployment of ${script} =====`));
console.log(error);
'SCRIPT': {
'Processed': (script) => { logger.success(`===== Successful deployment of ${script} =====`); },
'NotProcessed': (script, error) => { logger.error(`===== Unsuccessful deployment of ${script} =====`, error); },
},
'UnsuccessfulDeployment': (error) => {
console.log(chalk.redBright(`===== Unsuccessful deployment =====`));
console.log(error);
'COMMAND': {
'Start': () => { logger.info('===== Deployment has started... ====='); },
'Error': (error) => { logger.error(`===== Unsuccessful deployment =====`, error); }
}
}
6 changes: 2 additions & 4 deletions cli-commands/commands/deploy/options/network-option.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const Option = require('../../option');
const eoslime = require('../../../../index');

class NetworkOption extends Option {
constructor() {
constructor () {
super(
'network',
{
Expand All @@ -15,9 +15,7 @@ class NetworkOption extends Option {
}

process (optionValue) {
if (optionValue) {
return eoslime.init(optionValue);
}
return eoslime.init(optionValue);
}
}

Expand Down
12 changes: 6 additions & 6 deletions cli-commands/commands/deploy/options/path-option.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Option = require('../../option');
const fileSystemUtil = require('../../../helpers/file-system-util');

class PathOption extends Option {
constructor() {
constructor () {
super(
'path',
{
Expand All @@ -16,8 +16,8 @@ class PathOption extends Option {
}

async process (optionValue) {
let deploymentFilesFunctions = [];
if (fileSystemUtil.isDir(optionValue)) {
const deploymentFilesFunctions = [];
const dirFiles = await fileSystemUtil.recursivelyReadDir(optionValue);

for (let i = 0; i < dirFiles.length; i++) {
Expand All @@ -27,16 +27,16 @@ class PathOption extends Option {
deploy: require(path.resolve('./', dirFile.fullPath))
});
}

return deploymentFilesFunctions;
}

if (fileSystemUtil.isFile(optionValue)) {
deploymentFilesFunctions.push({
return [{
fileName: optionValue,
deploy: require(path.resolve('./', optionValue))
});
}];
}

return deploymentFilesFunctions;
}
}

Expand Down
Loading

0 comments on commit 57dc3ef

Please sign in to comment.