Setup linter and add it to CI (#54)
All checks were successful
Lint / lint (18.x) (push) Successful in 1m13s
Tests / cli_tests (18.x) (push) Successful in 7m17s

- Setup eslint with husky for precommit lint
- Fix existing lint errors
- Setup linter CI

Reviewed-on: #54
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
This commit is contained in:
Prathamesh Musale 2024-01-29 05:21:34 +00:00 committed by Ashwin
parent b01201ca50
commit c3f8d53f09
51 changed files with 1601 additions and 215 deletions

5
.eslintignore Normal file
View File

@ -0,0 +1,5 @@
# Don't lint node_modules.
node_modules
# Don't lint build output.
dist

21
.eslintrc.json Normal file
View File

@ -0,0 +1,21 @@
{
"env": {
"node": true
},
"extends": [
"semistandard",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"indent": ["error", 2, { "SwitchCase": 1 }],
"@typescript-eslint/no-explicit-any": "off"
}
}

28
.gitea/workflows/lint.yml Normal file
View File

@ -0,0 +1,28 @@
name: Lint
on:
pull_request:
branches:
- '*'
push:
branches:
- main
jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v3
- name: Download yarn
run: |
curl -fsSL -o /usr/local/bin/yarn https://github.com/yarnpkg/yarn/releases/download/v1.22.21/yarn-1.22.21.js
chmod +x /usr/local/bin/yarn
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: yarn
- name: Linter check
run: yarn lint

1
.husky/pre-commit Normal file
View File

@ -0,0 +1 @@
yarn lint

View File

@ -2,5 +2,5 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
setupFiles: ["dotenv/config"]
setupFiles: ['dotenv/config']
};

View File

@ -12,9 +12,19 @@
"@types/lodash": "^4.14.182",
"@types/node": "^17.0.25",
"@types/yargs": "^17.0.10",
"@typescript-eslint/eslint-plugin": "^5.47.1",
"@typescript-eslint/parser": "^5.47.1",
"dotenv": "^16.3.2",
"eslint": "^8.35.0",
"eslint-config-semistandard": "^15.0.1",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-standard": "^5.0.0",
"husky": "^9.0.2",
"jest": "29.0.0",
"ts-jest": "^29.0.2",
"dotenv": "^16.3.2",
"typescript": "^4.6.3"
},
"dependencies": {
@ -29,9 +39,10 @@
"test": "jest --runInBand --verbose test/cli.test.ts",
"lint": "eslint .",
"clean": "rm -rf ./dist",
"build": "tsc"
"build": "tsc",
"prepare": "husky"
},
"bin": {
"laconic": "bin/laconic"
}
}
}

View File

@ -11,7 +11,7 @@ export const desc = 'Get account.';
export const handler = async (argv: Arguments) => {
let address = argv.address as string;
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -24,5 +24,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.getAccounts([address]);
queryOutput(result,argv.output);
}
queryOutput(result, argv.output);
};

View File

@ -7,4 +7,4 @@ export const desc = 'Account operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('account-cmds')
.demandCommand();
}
};

View File

@ -21,7 +21,7 @@ export const handler = async (argv: Arguments) => {
assert(quantity, 'Invalid token quantity.');
assert(denom, 'Invalid token type.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -43,7 +43,7 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.commitBid({ auctionId, commitHash }, privateKey, fee);
const revealFile = `{"reveal_file":"${revealFilePath}"}`
const revealFile = `{"reveal_file":"${revealFilePath}"}`;
txOutput(result,revealFile,argv.output,argv.verbose)
}
txOutput(result, revealFile, argv.output, argv.verbose);
};

View File

@ -16,7 +16,7 @@ export const handler = async (argv: Arguments) => {
assert(auctionId, 'Invalid auction ID.');
assert(filePath, 'Invalid reveal file path.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -28,7 +28,7 @@ export const handler = async (argv: Arguments) => {
const reveal = fs.readFileSync(path.resolve(filePath));
const result = await registry.revealBid({ auctionId, reveal: reveal.toString('hex') }, privateKey, fee);
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};

View File

@ -6,10 +6,10 @@ export const desc = 'Auction bid operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.options({
'auction-id': { type: 'string' },
'type': { type: 'string' },
'quantity': { type: 'string' },
'file-path': { type: 'string' }
}).commandDir('bid-cmds')
'auction-id': { type: 'string' },
type: { type: 'string' },
quantity: { type: 'string' },
'file-path': { type: 'string' }
}).commandDir('bid-cmds')
.demandCommand();
}
};

View File

@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
const { id, config } = argv;
assert(id, 'Invalid auction ID.');
const { services: { cns: cnsConfig } } = getConfig(config as string)
const { services: { cns: cnsConfig } } = getConfig(config as string);
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -21,5 +21,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.getAuctionsByIds([id as string]);
queryOutput(result,argv.output)
}
queryOutput(result, argv.output);
};

View File

@ -7,4 +7,4 @@ export const desc = 'Auction operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('auction-cmds')
.demandCommand();
}
};

View File

@ -14,7 +14,7 @@ export const handler = async (argv: Arguments) => {
assert(name, 'Invalid authority name.');
assert(bondId, 'Invalid Bond ID.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -24,7 +24,7 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.setAuthorityBond({ name, bondId }, privateKey, fee);
const success = `{"success":${result.code==0}}`
const success = `{"success":${result.code === 0}}`;
txOutput(result,success,argv.output,argv.verbose)
}
txOutput(result, success, argv.output, argv.verbose);
};

View File

@ -7,4 +7,4 @@ export const desc = 'Authority bond operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('bond-cmds')
.demandCommand();
}
};

View File

@ -13,14 +13,14 @@ export const builder = {
type: 'string',
default: ''
}
}
};
export const handler = async (argv: Arguments) => {
const name = argv.name as string;
const owner = argv.owner as string;
assert(name, 'Invalid authority name.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -31,6 +31,6 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.reserveAuthority({ name, owner }, privateKey, fee);
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};

View File

@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
const name = argv.name as string;
assert(name, 'Invalid authority name.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -21,5 +21,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.lookupAuthorities([name], true);
queryOutput(result,argv.output)
}
queryOutput(result, argv.output);
};

View File

@ -7,4 +7,4 @@ export const desc = 'Name authority operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('authority-cmds')
.demandCommand();
}
};

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
export const command = 'associate';
@ -12,7 +12,7 @@ export const builder = {
'bond-id': {
type: 'string'
}
}
};
export const handler = async (argv: Arguments) => {
const id = argv.id as string;
@ -20,7 +20,7 @@ export const handler = async (argv: Arguments) => {
assert(id, 'Invalid Record ID.');
assert(bondId, 'Invalid Bond ID.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -30,7 +30,6 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.associateBond({ recordId: id, bondId }, privateKey, fee);
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};

View File

@ -2,17 +2,17 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees,txOutput } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
export const command = 'cancel';
export const desc = 'Cancel bond.';
export const handler = async (argv: Arguments) => {
const id = argv.id as string
const id = argv.id as string;
assert(id, 'Invalid Bond ID.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -22,7 +22,6 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.cancelBond({ id }, privateKey, fee);
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
export const command = 'create';
@ -15,17 +15,17 @@ export const builder = {
quantity: {
type: 'string'
}
}
};
export const handler = async (argv: Arguments) => {
const { config, verbose } = argv;
const { config } = argv;
const denom = argv.type as string;
const amount = argv.quantity as string;
assert(denom, 'Invalid Type.');
assert(amount, 'Invalid Quantity.');
const { services: { cns: cnsConfig } } = getConfig(config as string)
const { services: { cns: cnsConfig } } = getConfig(config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -36,8 +36,7 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig);
const bondId = await registry.getNextBondId(privateKey);
const result = await registry.createBond({ denom, amount }, privateKey, fee);
const jsonString=`{"bondId":"${bondId}"}`
const jsonString = `{"bondId":"${bondId}"}`;
txOutput(result,jsonString,argv.output,argv.verbose)
}
txOutput(result, jsonString, argv.output, argv.verbose);
};

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
export const command = 'dissociate';
@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
const id = argv.id as string;
assert(id, 'Invalid Record ID.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -22,7 +22,6 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.dissociateBond({ recordId: id }, privateKey, fee);
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'get';
@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
const { id, config } = argv;
console.assert(id, 'Bond Id is required.');
const { services: { cns: cnsConfig } } = getConfig(config as string)
const { services: { cns: cnsConfig } } = getConfig(config as string);
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -22,5 +22,5 @@ export const handler = async (argv: Arguments) => {
const result = await registry.getBondsByIds([id as string]);
queryOutput(result,argv.output)
}
queryOutput(result, argv.output);
};

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'list';
@ -12,10 +12,10 @@ export const builder = {
owner: {
type: 'string'
}
}
};
export const handler = async (argv: Arguments) => {
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -26,5 +26,5 @@ export const handler = async (argv: Arguments) => {
const { owner } = argv;
const result = await registry.queryBonds({ owner });
queryOutput(result,argv.output)
}
queryOutput(result, argv.output);
};

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees,txOutput } from '../../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../../util';
export const command = 'dissociate';
@ -12,13 +12,13 @@ export const builder = {
'bond-id': {
type: 'string'
}
}
};
export const handler = async (argv: Arguments) => {
const bondId = argv.bondId as string;
assert(bondId, 'Invalid Bond ID.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -28,7 +28,6 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.dissociateRecords({ bondId }, privateKey, fee);
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../../util';
export const command = 'reassociate';
@ -15,7 +15,7 @@ export const builder = {
'new-bond-id': {
type: 'string'
}
}
};
export const handler = async (argv: Arguments) => {
const oldBondId = argv.oldBondId as string;
@ -23,7 +23,7 @@ export const handler = async (argv: Arguments) => {
assert(oldBondId, 'Invalid Old Bond ID.');
assert(newBondId, 'Invalid New Bond ID.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -33,7 +33,6 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.reassociateRecords({ oldBondId, newBondId }, privateKey, fee);
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};

View File

@ -7,4 +7,4 @@ export const desc = 'Bond records operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('records-cmds')
.demandCommand();
}
};

View File

@ -2,8 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
import { isNil } from 'lodash';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
export const command = 'refill';
@ -16,18 +15,18 @@ export const builder = {
quantity: {
type: 'string'
}
}
};
export const handler = async (argv: Arguments) => {
const denom = argv.type as string;
const amount = argv.quantity as string;
const id = argv.id as string
const id = argv.id as string;
assert(id, 'Invalid Bond ID.');
assert(denom, 'Invalid Type.');
assert(amount, 'Invalid Quantity.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -37,7 +36,6 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.refillBond({ id, denom, amount }, privateKey, fee);
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees,txOutput } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
export const command = 'withdraw';
@ -15,18 +15,18 @@ export const builder = {
quantity: {
type: 'string'
}
}
};
export const handler = async (argv: Arguments) => {
const denom = argv.type as string;
const amount = argv.quantity as string;
const id = argv.id as string
const id = argv.id as string;
assert(id, 'Invalid Bond ID.');
assert(denom, 'Invalid Type.');
assert(amount, 'Invalid Quantity.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -36,7 +36,6 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.withdrawBond({ id, denom, amount }, privateKey, fee);
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};

View File

@ -7,4 +7,4 @@ export const desc = 'Bonds operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('bond-cmds')
.demandCommand();
}
};

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
export const command = 'delete [name]';
@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
const name = argv.name as string;
assert(name, 'Invalid Name.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -23,7 +23,6 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.deleteName({ crn: name }, privateKey, fee);
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'lookup [name]';
@ -12,13 +12,13 @@ export const builder = {
history: {
type: 'boolean'
}
}
};
export const handler = async (argv: Arguments) => {
const name = argv.name as string;
assert(name, 'Invalid Name.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -27,5 +27,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.lookupNames([name], argv.history as boolean);
queryOutput(result,argv.output)
}
queryOutput(result, argv.output);
};

View File

@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
const name = argv.name as string;
assert(name, 'Invalid Name.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -24,4 +24,4 @@ export const handler = async (argv: Arguments) => {
result = result.filter((v: any) => v);
queryOutput(result, argv.output);
}
};

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees,txOutput } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
export const command = 'set [name] [id]';
@ -14,7 +14,7 @@ export const handler = async (argv: Arguments) => {
assert(name, 'Invalid Name.');
assert(id, 'Invalid Record ID.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -25,7 +25,6 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.setName({ crn: name, cid: id }, privateKey, fee);
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};

View File

@ -6,5 +6,5 @@ export const desc = 'Name operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('name-cmds')
.demandCommand()
}
.demandCommand();
};

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'get';
@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
const { id, config } = argv;
assert(id, 'Invalid Record ID.');
const { services: { cns: cnsConfig } } = getConfig(config as string)
const { services: { cns: cnsConfig } } = getConfig(config as string);
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -21,5 +21,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.getRecordsByIds([id as string]);
queryOutput(result,argv.output)
}
queryOutput(result, argv.output);
};

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'list';
@ -25,17 +25,17 @@ export const builder = {
type: 'boolean',
default: false
}
}
};
export const handler = async (argv: Arguments) => {
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
const { type, name, bondId, owner, all } = argv;
const filters: any = {};
const filterArgs = argv._.slice(3);
for (let i = 0; i < filterArgs.length-1; i+=2) {
filters[String(filterArgs[i]).replace(/^-+/,"")] = filterArgs[i+1];
for (let i = 0; i < filterArgs.length - 1; i += 2) {
filters[String(filterArgs[i]).replace(/^-+/, '')] = filterArgs[i + 1];
}
assert(restEndpoint, 'Invalid CNS REST endpoint.');
@ -44,7 +44,7 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
let result = await registry.queryRecords({...filters, type, name}, all as boolean);
let result = await registry.queryRecords({ ...filters, type, name }, all as boolean);
// Apply ex post filters.
if (bondId) {
@ -55,5 +55,5 @@ export const handler = async (argv: Arguments) => {
result = result.filter((v: any) => v.owners?.find((e: string) => e === owner));
}
queryOutput(result, argv.output)
}
queryOutput(result, argv.output);
};

View File

@ -1,6 +1,5 @@
import { Arguments } from 'yargs';
import assert from 'assert';
import path from 'path';
import yaml from 'js-yaml';
import fs from 'fs';
import { Registry } from '@cerc-io/laconic-sdk';
@ -14,12 +13,12 @@ export const desc = 'Register record.';
export const builder = {
'bond-id': {
type: 'string'
},
}
}
};
export const handler = async (argv: Arguments) => {
const { txKey, filename, verbose, config } = argv;
const { services: { cns: cnsConfig } } = getConfig(config as string)
const { txKey, filename, config } = argv;
const { services: { cns: cnsConfig } } = getConfig(config as string);
const { restEndpoint, gqlEndpoint, userKey, bondId, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
@ -39,7 +38,7 @@ export const handler = async (argv: Arguments) => {
// Convert sub-objects (other than arrays) to a JSON automatically.
for (const [k, v] of Object.entries(record)) {
if (v && typeof v === "object" && !Array.isArray(v)) {
if (v && typeof v === 'object' && !Array.isArray(v)) {
record[k] = JSON.stringify(v);
}
}
@ -48,5 +47,5 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.setRecord({ privateKey: userKey, record, bondId }, txKey as string, fee);
txOutput(result,JSON.stringify(result.data,undefined,2),argv.output,argv.verbose)
}
txOutput(result, JSON.stringify(result.data, undefined, 2), argv.output, argv.verbose);
};

View File

@ -6,6 +6,6 @@ export const desc = 'Record operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('record-cmds')
.parserConfiguration({'unknown-options-as-args': true})
.demandCommand()
}
.parserConfiguration({ 'unknown-options-as-args': true })
.demandCommand();
};

View File

@ -9,7 +9,7 @@ export const command = 'status';
export const desc = 'Get CNS status.';
export const handler = async (argv: Arguments) => {
const { services: { cns } } = getConfig(argv.config as string)
const { services: { cns } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cns);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -19,4 +19,4 @@ export const handler = async (argv: Arguments) => {
const result = await registry.getStatus();
console.log(JSON.stringify(result, undefined, 2));
}
};

View File

@ -15,7 +15,7 @@ export const builder = {
quantity: {
type: 'string'
}
}
};
export const handler = async (argv: Arguments) => {
const destinationAddress = argv.address as string;
@ -26,7 +26,7 @@ export const handler = async (argv: Arguments) => {
assert(denom, 'Invalid Type.');
assert(amount, 'Invalid Quantity.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -40,5 +40,5 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig);
await registry.sendCoins({ denom, amount, destinationAddress }, privateKey, fee);
const result = await registry.getAccounts([fromAddress, destinationAddress]);
queryOutput(result,argv.output)
}
queryOutput(result, argv.output);
};

View File

@ -7,4 +7,4 @@ export const desc = 'Tokens operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('tokens-cmds')
.demandCommand();
}
};

View File

@ -11,13 +11,13 @@ exports.builder = (yargs: yargs.Argv) => {
'tx-key': { type: 'string' },
'bond-id': { type: 'string' },
'chain-id': { type: 'string' },
'filename': { alias: 'f' },
'id': { type: 'string' },
'address': { type: 'string' },
'gas': { type: 'string' },
'fees': { type: 'string' }
filename: { alias: 'f' },
id: { type: 'string' },
address: { type: 'string' },
gas: { type: 'string' },
fees: { type: 'string' }
})
.commandDir('cns-cmds')
.demandCommand()
.help()
}
.help();
};

View File

@ -1,6 +1,7 @@
import yargs from 'yargs/yargs';
import { hideBin } from 'yargs/helpers';
// eslint-disable-next-line no-unused-expressions
yargs(hideBin(process.argv))
.options({
verbose: {

View File

@ -1,4 +1,4 @@
import { Arguments } from "yargs";
import { Arguments } from 'yargs';
import clean from 'lodash-clean';
export const getConnectionInfo = (argv: Arguments, config: any) => {

View File

@ -1,9 +1,9 @@
import yaml from 'js-yaml'
import fs from 'fs'
import path from 'path'
import yaml from 'js-yaml';
import fs from 'fs';
import path from 'path';
export const getConfig = (configFilePath: string): any => {
const resolvedFilePath = path.resolve(process.cwd(), configFilePath);
const configFile = fs.readFileSync(resolvedFilePath, 'utf-8')
const configFile = fs.readFileSync(resolvedFilePath, 'utf-8');
return yaml.load(configFile);
};

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import assert from 'assert';
import { Arguments } from 'yargs';

View File

@ -1,22 +1,22 @@
export const txOutput = (result:any,msg:string,output:unknown,verbose:unknown) => {
if (output=="json"){
console.log(verbose ? JSON.parse(JSON.stringify(result)) : JSON.parse(msg));
} else {
console.log(verbose ? JSON.stringify(result,undefined,2) : msg);
}
export const txOutput = (result:any, msg:string, output:unknown, verbose:unknown) => {
if (output === 'json') {
console.log(verbose ? JSON.parse(JSON.stringify(result)) : JSON.parse(msg));
} else {
console.log(verbose ? JSON.stringify(result, undefined, 2) : msg);
}
};
export const queryOutput = (result: any, output: unknown) => {
if (output=="json"){
console.log(JSON.parse(JSON.stringify(result)));
} else {
console.log(JSON.stringify(result, (key, value) => {
try {
return JSON.parse(value)
} catch (e) {
return value;
}
}, 2));
}
}
if (output === 'json') {
console.log(JSON.parse(JSON.stringify(result)));
} else {
console.log(JSON.stringify(result, (key, value) => {
try {
return JSON.parse(value);
} catch (e) {
return value;
}
}, 2));
}
};

View File

@ -191,7 +191,7 @@ describe('Test laconic CLI commands', () => {
const outputObj = checkResultAndRetrieveOutput(result);
// Expected account
const expectedAccount = getAccountObj({ address: testAccount })
const expectedAccount = getAccountObj({ address: testAccount });
expect(outputObj.length).toEqual(1);
expect(outputObj[0]).toMatchObject(expectedAccount);
@ -213,7 +213,7 @@ describe('Test laconic CLI commands', () => {
// Expected acconts
const expectedAccounts = [
getAccountObj({ address: testAccount, balance: balanceAfterSend }),
getAccountObj({ address: testAccount2, balance: sendAmount }),
getAccountObj({ address: testAccount2, balance: sendAmount })
];
expect(outputObj.length).toEqual(2);
@ -282,7 +282,6 @@ describe('Test laconic CLI commands', () => {
expect(recordOutputObj.length).toEqual(1);
expect(recordOutputObj[0]).toMatchObject(expectedRecord);
});
test('laconic cns bond associate --id <record_id> --bond-id <bond_id>', async () => {

View File

@ -13,7 +13,7 @@ export const AUCTION_FEES = {
export const AUCTION_COMMIT_DURATION = 60; // 60s
export const AUCTION_REVEAL_DURATION = 60; // 60s
export function checkResultAndRetrieveOutput(result: SpawnSyncReturns<Buffer>): any {
export function checkResultAndRetrieveOutput (result: SpawnSyncReturns<Buffer>): any {
expect(result.status).toBe(0);
const errorOutput = result.stderr.toString().trim();
@ -25,14 +25,14 @@ export function checkResultAndRetrieveOutput(result: SpawnSyncReturns<Buffer>):
return JSON.parse(output);
}
export function createBond(quantity: number): { bondId: string } {
export function createBond (quantity: number): { bondId: string } {
const result = spawnSync('laconic', ['cns', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', quantity.toString(), '--gas', '200000', '--fees', `200000${TOKEN_TYPE}`]);
const output = result.stdout.toString().trim();
return JSON.parse(output);
}
export function getBondObj(params: { id: string, owner: string, balance: number}): any {
export function getBondObj (params: { id: string, owner: string, balance: number}): any {
return {
id: params.id,
owner: params.owner,
@ -45,7 +45,7 @@ export function getBondObj(params: { id: string, owner: string, balance: number}
};
}
export function getAccountObj(params: { address: string, balance?: number }): any {
export function getAccountObj (params: { address: string, balance?: number }): any {
const balanceObj: any = { type: TOKEN_TYPE };
if (params.balance) {
balanceObj.quantity = params.balance;
@ -57,7 +57,7 @@ export function getAccountObj(params: { address: string, balance?: number }): an
};
}
export function getRecordObj(recordFilePath: string, params: { bondId: string, recordId: string, names: any }): any {
export function getRecordObj (recordFilePath: string, params: { bondId: string, recordId: string, names: any }): any {
const recordContent = yaml.load(fs.readFileSync(recordFilePath, 'utf8')) as any;
return {
@ -68,7 +68,7 @@ export function getRecordObj(recordFilePath: string, params: { bondId: string, r
};
}
export function getAuthorityObj(params: { owner: string, status: string, auction: any, bondId?: string }): any {
export function getAuthorityObj (params: { owner: string, status: string, auction: any, bondId?: string }): any {
return {
ownerAddress: params.owner,
status: params.status,
@ -77,7 +77,7 @@ export function getAuthorityObj(params: { owner: string, status: string, auction
};
}
export function getAuctionObj(params: { owner: string, status?: string }): any {
export function getAuctionObj (params: { owner: string, status?: string }): any {
return {
status: params.status || 'commit',
ownerAddress: params.owner,
@ -93,11 +93,11 @@ export function getAuctionObj(params: { owner: string, status?: string }): any {
type: TOKEN_TYPE,
quantity: AUCTION_FEES.minimumBid
},
winnerAddress: '',
winnerAddress: ''
};
}
export function getBidObj(params: { bidder: string, status?: string }): any {
export function getBidObj (params: { bidder: string, status?: string }): any {
return {
bidderAddress: params.bidder,
status: params.status || 'commit',
@ -116,6 +116,6 @@ export function getBidObj(params: { bidder: string, status?: string }): any {
};
}
export async function delay(ms: number): Promise<any> {
return new Promise(res => setTimeout(res, ms))
export async function delay (ms: number): Promise<any> {
return new Promise((resolve) => setTimeout(resolve, ms));
}

1349
yarn.lock

File diff suppressed because it is too large Load Diff