Skip to content

Commit 57dc3ef

Browse files
authored
v2.0.0
Development
2 parents 77b6bd4 + 740af63 commit 57dc3ef

File tree

89 files changed

+4391
-519
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+4391
-519
lines changed

README.md

+92-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[![npm version](https://badge.fury.io/js/eoslime.svg)](https://badge.fury.io/js/eoslime.svg)
22
[![codecov](https://codecov.io/gh/LimeChain/eoslime/branch/master/graph/badge.svg)](https://codecov.io/gh/LimeChain/eoslime)
3+
[![support typescript](https://badgen.net/badge/Support/TypeScript/cyan)](https://badgen.net/badge/Support/TypeScript/cyan)
34

45
eoslime.js
56
============
@@ -23,13 +24,103 @@ Thanks these wonderful people for helping improve EOSLime
2324
<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/>
2425
<a href="https://github.com/LimeChain/eoslime/issues/53" title="Ideas">💡</a>
2526
</td>
27+
<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/>
28+
<a href="https://github.com/LimeChain/eoslime/pulls/prcolaco" title="Code">💻</a>
29+
</td>
2630
</tr>
2731
</table>
2832

2933

3034

3135
# Change log
3236

37+
## Version 2.0.0 change log
38+
## [Typescript support && Codebase code coverage]
39+
### Breaking changes
40+
* Rename **Account.addAuthorityKey** to **Account.addOnBehalfKey**
41+
* Rename **Account.executiveAuth** to **Account.authority**
42+
* New way to access contract actions and tables
43+
**Actions**
44+
```
45+
const tokenContract = await eoslime.Contract.at('contract name');
46+
// Before
47+
tokenContract.issue(params, options)
48+
// Now
49+
tokenContract.actions.issue([params], options)
50+
```
51+
**Tables**
52+
```
53+
const tokenContract = await eoslime.Contract.at('contract name');
54+
// Before
55+
tokenContract.balances()
56+
// Now
57+
tokenContract.tables.balances()
58+
```
59+
* Contract.on('deploy')
60+
```
61+
// Before
62+
Contract.on('deploy', (tx, contract) => {}))
63+
// Now
64+
Contract.on('deploy', (contract, tx) => {}))
65+
```
66+
* Remove AuthorityAccount
67+
* Deprecate **Account.createSubAuthority**
68+
* Replace **createSubAuthority** with **addAuthority**
69+
```
70+
const account = await eoslime.Account.createRandom();
71+
72+
// ------------ [ Before ] ------------
73+
74+
// Add subAuthority and return an instance of AuthorityAccount
75+
const subAuthorityAccount = await account.createSubAuthority('subauthority');
76+
77+
// Add what actions the new authority could access
78+
await subAuthorityAccount.setAuthorityAbilities([
79+
{ action: 'produce', contract: faucetContract.name }
80+
]);
81+
82+
// ------------ [ Now ] ------------
83+
84+
// Add subAuthority and return tx receipt
85+
const tx = await account.addAuthority('subauthority');
86+
87+
// Add what actions the new authority could access
88+
await account.setAuthorityAbilities('subauthority', [
89+
{ action: 'produce', contract: faucetContract.name }
90+
]);
91+
92+
const subAuthorityAccount = eoslime.Account.load('name', 'key', 'subauthority');
93+
```
94+
95+
### News
96+
* Typescript support
97+
* Refactor CLI commands
98+
* Fix nodeos pre-loaded accounts to have different keys
99+
* Unit tests for all CLI commands
100+
* Return transaction receipts on every chain iteraction
101+
* Use logger instead console.log
102+
* Update Kylin network endpoint
103+
* Add Jungle3 support
104+
* Remove the check requiring an executor to be provided on contract instantiation. Without executor, one could fetch only the data from the contract tables
105+
* contract.action.sign(params)
106+
```
107+
// Before
108+
contract.action.sign(params)
109+
110+
// Now
111+
// Options are the same like the ones for contract.action(params, options)
112+
contract.actions.action.sign([params], options)
113+
```
114+
* contract.action.getRawTransaction(params)
115+
```
116+
// Before
117+
contract.action.getRawTransaction(params)
118+
119+
// Now
120+
// Options are the same like the ones for contract.action(params, options)
121+
contract.actions.action.getRawTransaction([params], options)
122+
```
123+
33124
## Version 1.0.4 change log
34125
35126
* **eoslime nodeos**
@@ -91,7 +182,7 @@ EOSLIME was able to be initialized only with pre-configured providers connection
91182
const eoslime = require('eoslime').init('bos', { url: 'Your url', chainId: 'Your chainId' });
92183
// ... any other supported netwok ...
93184
```
94-
* **Allow read-only contracts** - You are able now to instantiate a contract withouth a signer/executor and read the contract's tables
185+
* **Allow read-only contracts** - You are able now to instantiate a contract without a signer/executor and read the contract's tables
95186
* **Add Tutorial section in the documentation**
96187
* **Describe how examples in the documentation could be run**
97188
* **Increase the code coverage from 46% to 90+ %**

cli-commands/command-definer.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class CommandDefiner {
2-
constructor(yargs) {
2+
constructor (yargs) {
33
this.yargs = yargs;
44
}
55

@@ -28,8 +28,8 @@ class CommandDefiner {
2828

2929
handle (command) {
3030
return async (args) => {
31-
const result = await command.execute(args);
32-
if (!result) {
31+
await command.execute(args);
32+
if (!command.hasBeenExecuted) {
3333
this.yargs.showHelp();
3434
}
3535
}

cli-commands/commands/command.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
class Command {
2-
constructor(commandDefinition) {
2+
constructor (commandDefinition) {
33
this.subcommands = [];
44
this.options = commandDefinition.options || [];
55
this.template = commandDefinition.template || '';
66
this.description = commandDefinition.description || '';
7+
8+
this.hasBeenExecuted = true;
79
}
810

911
async processOptions (args) {
@@ -21,8 +23,7 @@ class Command {
2123
return optionResults;
2224
}
2325

24-
execute (args) { }
25-
26+
async execute (args) { }
2627
}
2728

2829
module.exports = Command;

cli-commands/commands/compile/index.js

+19-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
const AsyncSoftExec = require('../../helpers/async-soft-exec');
22
const Command = require('../command');
33

4-
const commandMessages = require('./messages');
4+
const MESSAGE_COMMAND = require('./messages').COMMAND;
5+
const MESSAGE_CONTRACT = require('./messages').CONTRACT;
6+
57
const compiledDirectories = require('./specific/directories.json');
68
const compileCommandDefinition = require('./definition');
79

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

1214
class CompileCommand extends Command {
1315

14-
constructor() {
16+
constructor () {
1517
super(compileCommandDefinition);
1618
}
1719

1820
async execute (args) {
1921
try {
20-
commandMessages.StartCompilation();
22+
MESSAGE_COMMAND.Start();
2123

2224
const optionsResults = await super.processOptions(args);
2325

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

2729
for (let i = 0; i < optionsResults.path.length; i++) {
2830
const contractPath = optionsResults.path[i];
29-
// Todo: Check how to compile without using eosio-cpp
30-
const asyncSoftExec = new AsyncSoftExec(`eosio-cpp -I . -o ./compiled/${contractPath.fileName}.wasm ${contractPath.fullPath} --abigen`);
31-
asyncSoftExec.onError((error) => commandMessages.UnsuccessfulCompilationOfContract(error, contractPath.fileName));
32-
asyncSoftExec.onSuccess(() => commandMessages.SuccessfulCompilationOfContract(contractPath.fileName));
33-
34-
await asyncSoftExec.exec();
31+
await processCompilation(contractPath)
3532
}
3633
} else {
37-
commandMessages.ContractNotExisting();
34+
MESSAGE_CONTRACT.NotFound();
3835
}
3936
} catch (error) {
40-
commandMessages.UnsuccessfulCompilation(error);
37+
MESSAGE_COMMAND.Error(error);
4138
}
42-
return true;
39+
}
40+
}
41+
42+
const processCompilation = async function (contract) {
43+
try {
44+
const asyncSoftExec = new AsyncSoftExec(`eosio-cpp -I . -o ./compiled/${contract.fileName}.wasm ${contract.fullPath} --abigen`);
45+
await asyncSoftExec.exec();
46+
47+
MESSAGE_CONTRACT.Compiled(contract.fileName);
48+
} catch (error) {
49+
MESSAGE_CONTRACT.NotCompiled(error, contract.fileName);
4350
}
4451
}
4552

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
const chalk = require('chalk');
1+
const logger = require('../../common/logger');
22

33
module.exports = {
4-
'StartCompilation': () => { console.log(chalk.magentaBright('===== Compilation has started... =====')); },
5-
'UnsuccessfulCompilation': (error) => {
6-
console.log(chalk.redBright(`===== Unsuccessful compilation =====`));
7-
console.log(error);
4+
'CONTRACT': {
5+
'Compiled': (contract) => { logger.success(`===== ${contract} has been successfully compiled =====`); },
6+
'NotCompiled': (error, file) => { logger.error(`===== Unsuccessful compilation of ${file} =====`, error); },
7+
'NotFound': () => { logger.info(`===== There is not a contract to compile =====`); }
88
},
9-
'SuccessfulCompilationOfContract': (contract) => { console.log(chalk.greenBright(`===== Successfully compilation of ${contract} =====`)); },
10-
'UnsuccessfulCompilationOfContract': (error, file) => {
11-
console.log(chalk.redBright(`===== Unsuccessful compilation of ${file} =====`));
12-
console.log(error);
13-
},
14-
'ContractNotExisting': () => { console.log(chalk.redBright(`===== There is not a contract to compile =====`)); }
9+
'COMMAND': {
10+
'Start': () => { logger.info('===== Compilation has started... ====='); },
11+
'Error': (error) => { logger.error(`===== Unsuccessful compilation =====`, error); },
12+
}
1513
}

cli-commands/commands/compile/options/path-option.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
const fileSystemUtil = require('../../../helpers/file-system-util');
2+
const path = require('path');
23

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

56
class PathOption extends Option {
67

7-
constructor() {
8+
constructor () {
89
super(
910
'path',
1011
{
@@ -28,7 +29,7 @@ class PathOption extends Option {
2829
});
2930
}
3031

31-
return optionValue.endsWith('.cpp') ? [`${__dirname}/${optionValue}`] : [];
32+
return optionValue.endsWith('.cpp') ? [{ fullPath: optionValue, fileName: path.basename(optionValue, '.cpp') }] : [];
3233
}
3334
}
3435

cli-commands/commands/deploy/index.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
const Command = require('../command');
22

3-
const commandMessages = require('./messages');
3+
const MESSAGE_COMMAND = require('./messages').COMMAND;
4+
const MESSAGE_SCRIPT = require('./messages').SCRIPT;
5+
46
const deployCommandDefinition = require('./definition');
57

68
// eoslime deploy --path --network --deployer
79

810
class DeployCommand extends Command {
9-
constructor() {
11+
constructor () {
1012
super(deployCommandDefinition);
1113
}
1214

1315
async execute (args) {
1416
try {
15-
commandMessages.StartDeployment();
17+
MESSAGE_COMMAND.Start();
18+
1619
const optionsResults = await super.processOptions(args);
1720
await runDeploymentScripts(optionsResults.path, optionsResults.network, optionsResults.deployer);
1821
} catch (error) {
19-
commandMessages.UnsuccessfulDeployment(error);
22+
MESSAGE_COMMAND.Error(error);
2023
}
21-
return true;
2224
}
2325
}
2426

@@ -27,9 +29,9 @@ const runDeploymentScripts = async function (deploymentScripts, ...configuration
2729
const deploymentScript = deploymentScripts[i];
2830
try {
2931
await deploymentScript.deploy(...configuration);
30-
commandMessages.SuccessfulDeploymentOfScript(deploymentScript.fileName);
32+
MESSAGE_SCRIPT.Processed(deploymentScript.fileName);
3133
} catch (error) {
32-
commandMessages.UnsuccessfulDeploymentOfScript(deploymentScript.fileName, error);
34+
MESSAGE_SCRIPT.NotProcessed(deploymentScript.fileName, error);
3335
}
3436
}
3537
}
+7-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
const chalk = require('chalk');
1+
const logger = require('../../common/logger');
22

33
module.exports = {
4-
'StartDeployment': () => { console.log(chalk.magentaBright('===== Deployment has started... =====')); },
5-
'SuccessfulDeploymentOfScript': (script) => { console.log(chalk.greenBright(`===== Successful deployment of ${script} =====`)); },
6-
'UnsuccessfulDeploymentOfScript': (script, error) => {
7-
console.log(chalk.redBright(`===== Unsuccessful deployment of ${script} =====`));
8-
console.log(error);
4+
'SCRIPT': {
5+
'Processed': (script) => { logger.success(`===== Successful deployment of ${script} =====`); },
6+
'NotProcessed': (script, error) => { logger.error(`===== Unsuccessful deployment of ${script} =====`, error); },
97
},
10-
'UnsuccessfulDeployment': (error) => {
11-
console.log(chalk.redBright(`===== Unsuccessful deployment =====`));
12-
console.log(error);
8+
'COMMAND': {
9+
'Start': () => { logger.info('===== Deployment has started... ====='); },
10+
'Error': (error) => { logger.error(`===== Unsuccessful deployment =====`, error); }
1311
}
1412
}

cli-commands/commands/deploy/options/network-option.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const Option = require('../../option');
22
const eoslime = require('../../../../index');
33

44
class NetworkOption extends Option {
5-
constructor() {
5+
constructor () {
66
super(
77
'network',
88
{
@@ -15,9 +15,7 @@ class NetworkOption extends Option {
1515
}
1616

1717
process (optionValue) {
18-
if (optionValue) {
19-
return eoslime.init(optionValue);
20-
}
18+
return eoslime.init(optionValue);
2119
}
2220
}
2321

cli-commands/commands/deploy/options/path-option.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const Option = require('../../option');
44
const fileSystemUtil = require('../../../helpers/file-system-util');
55

66
class PathOption extends Option {
7-
constructor() {
7+
constructor () {
88
super(
99
'path',
1010
{
@@ -16,8 +16,8 @@ class PathOption extends Option {
1616
}
1717

1818
async process (optionValue) {
19-
let deploymentFilesFunctions = [];
2019
if (fileSystemUtil.isDir(optionValue)) {
20+
const deploymentFilesFunctions = [];
2121
const dirFiles = await fileSystemUtil.recursivelyReadDir(optionValue);
2222

2323
for (let i = 0; i < dirFiles.length; i++) {
@@ -27,16 +27,16 @@ class PathOption extends Option {
2727
deploy: require(path.resolve('./', dirFile.fullPath))
2828
});
2929
}
30+
31+
return deploymentFilesFunctions;
3032
}
3133

3234
if (fileSystemUtil.isFile(optionValue)) {
33-
deploymentFilesFunctions.push({
35+
return [{
3436
fileName: optionValue,
3537
deploy: require(path.resolve('./', optionValue))
36-
});
38+
}];
3739
}
38-
39-
return deploymentFilesFunctions;
4040
}
4141
}
4242

0 commit comments

Comments
 (0)