[WIP] Setup lint #1

Closed
prathamesh wants to merge 4 commits from pm-setup-lint into pm-add-tests
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 = { module.exports = {
preset: 'ts-jest', preset: 'ts-jest',
testEnvironment: 'node', testEnvironment: 'node',
setupFiles: ["dotenv/config"] setupFiles: ['dotenv/config']
}; };

View File

@ -12,9 +12,19 @@
"@types/lodash": "^4.14.182", "@types/lodash": "^4.14.182",
"@types/node": "^17.0.25", "@types/node": "^17.0.25",
"@types/yargs": "^17.0.10", "@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", "jest": "29.0.0",
"ts-jest": "^29.0.2", "ts-jest": "^29.0.2",
"dotenv": "^16.3.2",
"typescript": "^4.6.3" "typescript": "^4.6.3"
}, },
"dependencies": { "dependencies": {
@ -29,9 +39,10 @@
"test": "jest --runInBand --verbose test/cli.test.ts", "test": "jest --runInBand --verbose test/cli.test.ts",
"lint": "eslint .", "lint": "eslint .",
"clean": "rm -rf ./dist", "clean": "rm -rf ./dist",
"build": "tsc" "build": "tsc",
"prepare": "husky"
}, },
"bin": { "bin": {
"laconic": "bin/laconic" "laconic": "bin/laconic"
} }
} }

View File

@ -11,7 +11,7 @@ export const desc = 'Get account.';
export const handler = async (argv: Arguments) => { export const handler = async (argv: Arguments) => {
let address = argv.address as string; 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); const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.'); assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL 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 registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.getAccounts([address]); 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) => { exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('account-cmds') return yargs.commandDir('account-cmds')
.demandCommand(); .demandCommand();
} };

View File

@ -21,7 +21,7 @@ export const handler = async (argv: Arguments) => {
assert(quantity, 'Invalid token quantity.'); assert(quantity, 'Invalid token quantity.');
assert(denom, 'Invalid token type.'); 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); const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.'); assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.'); assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -43,7 +43,7 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.commitBid({ auctionId, commitHash }, privateKey, fee); 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(auctionId, 'Invalid auction ID.');
assert(filePath, 'Invalid reveal file path.'); 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); const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.'); assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL 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 reveal = fs.readFileSync(path.resolve(filePath));
const result = await registry.revealBid({ auctionId, reveal: reveal.toString('hex') }, privateKey, fee); const result = await registry.revealBid({ auctionId, reveal: reveal.toString('hex') }, 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

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

View File

@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
const { id, config } = argv; const { id, config } = argv;
assert(id, 'Invalid auction ID.'); 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); const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.'); assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL 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 registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.getAuctionsByIds([id as string]); 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) => { exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('auction-cmds') return yargs.commandDir('auction-cmds')
.demandCommand(); .demandCommand();
} };

View File

@ -14,7 +14,7 @@ export const handler = async (argv: Arguments) => {
assert(name, 'Invalid authority name.'); assert(name, 'Invalid authority name.');
assert(bondId, 'Invalid Bond 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); const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.'); assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL 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 registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.setAuthorityBond({ name, bondId }, privateKey, fee); 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) => { exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('bond-cmds') return yargs.commandDir('bond-cmds')
.demandCommand(); .demandCommand();
} };

View File

@ -13,14 +13,14 @@ export const builder = {
type: 'string', type: 'string',
default: '' default: ''
} }
} };
export const handler = async (argv: Arguments) => { export const handler = async (argv: Arguments) => {
const name = argv.name as string; const name = argv.name as string;
const owner = argv.owner as string; const owner = argv.owner as string;
assert(name, 'Invalid authority name.'); 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); const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.'); assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.'); assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -31,6 +31,6 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.reserveAuthority({ name, owner }, privateKey, fee); const result = await registry.reserveAuthority({ name, owner }, 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

@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
const name = argv.name as string; const name = argv.name as string;
assert(name, 'Invalid authority name.'); 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); const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.'); assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL 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 registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.lookupAuthorities([name], true); 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) => { exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('authority-cmds') return yargs.commandDir('authority-cmds')
.demandCommand(); .demandCommand();
} };

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; 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'; export const command = 'associate';
@ -12,7 +12,7 @@ export const builder = {
'bond-id': { 'bond-id': {
type: 'string' type: 'string'
} }
} };
export const handler = async (argv: Arguments) => { export const handler = async (argv: Arguments) => {
const id = argv.id as string; const id = argv.id as string;
@ -20,7 +20,7 @@ export const handler = async (argv: Arguments) => {
assert(id, 'Invalid Record ID.'); assert(id, 'Invalid Record ID.');
assert(bondId, 'Invalid Bond 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); const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.'); assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL 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 registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.associateBond({ recordId: id, bondId }, privateKey, fee); const result = await registry.associateBond({ recordId: id, 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

@ -2,17 +2,17 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; 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 command = 'cancel';
export const desc = 'Cancel bond.'; export const desc = 'Cancel bond.';
export const handler = async (argv: Arguments) => { export const handler = async (argv: Arguments) => {
const id = argv.id as string const id = argv.id as string;
assert(id, 'Invalid Bond ID.'); 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); const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.'); assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL 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 registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.cancelBond({ id }, privateKey, fee); const result = await registry.cancelBond({ id }, 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

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; 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'; export const command = 'create';
@ -15,17 +15,17 @@ export const builder = {
quantity: { quantity: {
type: 'string' type: 'string'
} }
} };
export const handler = async (argv: Arguments) => { export const handler = async (argv: Arguments) => {
const { config, verbose } = argv; const { config } = argv;
const denom = argv.type as string; const denom = argv.type as string;
const amount = argv.quantity as string; const amount = argv.quantity as string;
assert(denom, 'Invalid Type.'); assert(denom, 'Invalid Type.');
assert(amount, 'Invalid Quantity.'); 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); const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.'); assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.'); assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -36,8 +36,7 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
const bondId = await registry.getNextBondId(privateKey); const bondId = await registry.getNextBondId(privateKey);
const result = await registry.createBond({ denom, amount }, privateKey, fee); 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 assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; 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'; export const command = 'dissociate';
@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
const id = argv.id as string; const id = argv.id as string;
assert(id, 'Invalid Record ID.'); 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); const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.'); assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL 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 registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.dissociateBond({ recordId: id }, privateKey, fee); const result = await registry.dissociateBond({ recordId: id }, 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

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util'; import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'get'; export const command = 'get';
@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
const { id, config } = argv; const { id, config } = argv;
console.assert(id, 'Bond Id is required.'); 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); const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.'); assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL 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]); 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 assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util'; import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'list'; export const command = 'list';
@ -12,10 +12,10 @@ export const builder = {
owner: { owner: {
type: 'string' type: 'string'
} }
} };
export const handler = async (argv: Arguments) => { 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 { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.'); assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.'); assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -26,5 +26,5 @@ export const handler = async (argv: Arguments) => {
const { owner } = argv; const { owner } = argv;
const result = await registry.queryBonds({ owner }); 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 assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; 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'; export const command = 'dissociate';
@ -12,13 +12,13 @@ export const builder = {
'bond-id': { 'bond-id': {
type: 'string' type: 'string'
} }
} };
export const handler = async (argv: Arguments) => { export const handler = async (argv: Arguments) => {
const bondId = argv.bondId as string; const bondId = argv.bondId as string;
assert(bondId, 'Invalid Bond 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); const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.'); assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL 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 registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.dissociateRecords({ bondId }, privateKey, fee); const result = await registry.dissociateRecords({ 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

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; 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'; export const command = 'reassociate';
@ -15,7 +15,7 @@ export const builder = {
'new-bond-id': { 'new-bond-id': {
type: 'string' type: 'string'
} }
} };
export const handler = async (argv: Arguments) => { export const handler = async (argv: Arguments) => {
const oldBondId = argv.oldBondId as string; const oldBondId = argv.oldBondId as string;
@ -23,7 +23,7 @@ export const handler = async (argv: Arguments) => {
assert(oldBondId, 'Invalid Old Bond ID.'); assert(oldBondId, 'Invalid Old Bond ID.');
assert(newBondId, 'Invalid New 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); const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.'); assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL 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 registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.reassociateRecords({ oldBondId, newBondId }, privateKey, fee); const result = await registry.reassociateRecords({ oldBondId, newBondId }, 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 = 'Bond records operations.';
exports.builder = (yargs: yargs.Argv) => { exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('records-cmds') return yargs.commandDir('records-cmds')
.demandCommand(); .demandCommand();
} };

View File

@ -2,8 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util'; import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
import { isNil } from 'lodash';
export const command = 'refill'; export const command = 'refill';
@ -16,18 +15,18 @@ export const builder = {
quantity: { quantity: {
type: 'string' type: 'string'
} }
} };
export const handler = async (argv: Arguments) => { export const handler = async (argv: Arguments) => {
const denom = argv.type as string; const denom = argv.type as string;
const amount = argv.quantity 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(id, 'Invalid Bond ID.');
assert(denom, 'Invalid Type.'); assert(denom, 'Invalid Type.');
assert(amount, 'Invalid Quantity.'); 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); const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.'); assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL 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 registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.refillBond({ id, denom, amount }, privateKey, fee); const result = await registry.refillBond({ id, denom, amount }, 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

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; 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'; export const command = 'withdraw';
@ -15,18 +15,18 @@ export const builder = {
quantity: { quantity: {
type: 'string' type: 'string'
} }
} };
export const handler = async (argv: Arguments) => { export const handler = async (argv: Arguments) => {
const denom = argv.type as string; const denom = argv.type as string;
const amount = argv.quantity 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(id, 'Invalid Bond ID.');
assert(denom, 'Invalid Type.'); assert(denom, 'Invalid Type.');
assert(amount, 'Invalid Quantity.'); 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); const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.'); assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL 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 registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.withdrawBond({ id, denom, amount }, privateKey, fee); const result = await registry.withdrawBond({ id, denom, amount }, 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 = 'Bonds operations.';
exports.builder = (yargs: yargs.Argv) => { exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('bond-cmds') return yargs.commandDir('bond-cmds')
.demandCommand(); .demandCommand();
} };

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; 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]'; export const command = 'delete [name]';
@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
const name = argv.name as string; const name = argv.name as string;
assert(name, 'Invalid Name.'); 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); const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.'); assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.'); assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -23,7 +23,6 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.deleteName({ crn: name }, privateKey, fee); const result = await registry.deleteName({ crn: name }, 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

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

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; 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]'; export const command = 'set [name] [id]';
@ -14,7 +14,7 @@ export const handler = async (argv: Arguments) => {
assert(name, 'Invalid Name.'); assert(name, 'Invalid Name.');
assert(id, 'Invalid Record ID.'); 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); const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.'); assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.'); assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -25,7 +25,6 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.setName({ crn: name, cid: id }, privateKey, fee); const result = await registry.setName({ crn: name, cid: id }, 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

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

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util'; import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'get'; export const command = 'get';
@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
const { id, config } = argv; const { id, config } = argv;
assert(id, 'Invalid Record ID.'); 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); const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.'); assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL 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 registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.getRecordsByIds([id as string]); 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 assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util'; import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'list'; export const command = 'list';
@ -25,17 +25,17 @@ export const builder = {
type: 'boolean', type: 'boolean',
default: false default: false
} }
} };
export const handler = async (argv: Arguments) => { 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 { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
const { type, name, bondId, owner, all } = argv; const { type, name, bondId, owner, all } = argv;
const filters: any = {}; const filters: any = {};
const filterArgs = argv._.slice(3); const filterArgs = argv._.slice(3);
for (let i = 0; i < filterArgs.length-1; i+=2) { for (let i = 0; i < filterArgs.length - 1; i += 2) {
filters[String(filterArgs[i]).replace(/^-+/,"")] = filterArgs[i+1]; filters[String(filterArgs[i]).replace(/^-+/, '')] = filterArgs[i + 1];
} }
assert(restEndpoint, 'Invalid CNS REST endpoint.'); assert(restEndpoint, 'Invalid CNS REST endpoint.');
@ -44,7 +44,7 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId); 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. // Apply ex post filters.
if (bondId) { if (bondId) {
@ -55,5 +55,5 @@ export const handler = async (argv: Arguments) => {
result = result.filter((v: any) => v.owners?.find((e: string) => e === owner)); 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 { Arguments } from 'yargs';
import assert from 'assert'; import assert from 'assert';
import path from 'path';
import yaml from 'js-yaml'; import yaml from 'js-yaml';
import fs from 'fs'; import fs from 'fs';
import { Registry } from '@cerc-io/laconic-sdk'; import { Registry } from '@cerc-io/laconic-sdk';
@ -14,12 +13,12 @@ export const desc = 'Register record.';
export const builder = { export const builder = {
'bond-id': { 'bond-id': {
type: 'string' type: 'string'
}, }
} };
export const handler = async (argv: Arguments) => { export const handler = async (argv: Arguments) => {
const { txKey, filename, verbose, config } = argv; const { txKey, filename, config } = argv;
const { services: { cns: cnsConfig } } = getConfig(config as string) const { services: { cns: cnsConfig } } = getConfig(config as string);
const { restEndpoint, gqlEndpoint, userKey, bondId, chainId } = getConnectionInfo(argv, cnsConfig); const { restEndpoint, gqlEndpoint, userKey, bondId, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.'); 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. // Convert sub-objects (other than arrays) to a JSON automatically.
for (const [k, v] of Object.entries(record)) { 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); record[k] = JSON.stringify(v);
} }
} }
@ -48,5 +47,5 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.setRecord({ privateKey: userKey, record, bondId }, txKey as string, fee); 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) => { exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('record-cmds') return yargs.commandDir('record-cmds')
.parserConfiguration({'unknown-options-as-args': true}) .parserConfiguration({ 'unknown-options-as-args': true })
.demandCommand() .demandCommand();
} };

View File

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

View File

@ -15,7 +15,7 @@ export const builder = {
quantity: { quantity: {
type: 'string' type: 'string'
} }
} };
export const handler = async (argv: Arguments) => { export const handler = async (argv: Arguments) => {
const destinationAddress = argv.address as string; const destinationAddress = argv.address as string;
@ -26,7 +26,7 @@ export const handler = async (argv: Arguments) => {
assert(denom, 'Invalid Type.'); assert(denom, 'Invalid Type.');
assert(amount, 'Invalid Quantity.'); 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); const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.'); assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.'); assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -40,5 +40,5 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig); const fee = getGasAndFees(argv, cnsConfig);
await registry.sendCoins({ denom, amount, destinationAddress }, privateKey, fee); await registry.sendCoins({ denom, amount, destinationAddress }, privateKey, fee);
const result = await registry.getAccounts([fromAddress, destinationAddress]); 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) => { exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('tokens-cmds') return yargs.commandDir('tokens-cmds')
.demandCommand(); .demandCommand();
} };

View File

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

View File

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

View File

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

View File

@ -1,9 +1,9 @@
import yaml from 'js-yaml' import yaml from 'js-yaml';
import fs from 'fs' import fs from 'fs';
import path from 'path' import path from 'path';
export const getConfig = (configFilePath: string): any => { export const getConfig = (configFilePath: string): any => {
const resolvedFilePath = path.resolve(process.cwd(), configFilePath); 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); return yaml.load(configFile);
}; };

View File

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

View File

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

View File

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

View File

@ -12,7 +12,7 @@ export const AUCTION_FEES = {
export const COMMIT_DURATION = 60; // 60s export const COMMIT_DURATION = 60; // 60s
export const REVEAL_DURATION = 60; // 60s export const REVEAL_DURATION = 60; // 60s
export function checkResultAndRetrieveOutput(result: SpawnSyncReturns<Buffer>): any { export function checkResultAndRetrieveOutput (result: SpawnSyncReturns<Buffer>): any {
expect(result.status).toBe(0); expect(result.status).toBe(0);
const errorOutput = result.stderr.toString().trim(); const errorOutput = result.stderr.toString().trim();
@ -24,14 +24,14 @@ export function checkResultAndRetrieveOutput(result: SpawnSyncReturns<Buffer>):
return JSON.parse(output); 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 result = spawnSync('laconic', ['cns', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', quantity.toString(), '--gas', '200000', '--fees', `200000${TOKEN_TYPE}`]);
const output = result.stdout.toString().trim(); const output = result.stdout.toString().trim();
return JSON.parse(output); 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 { return {
id: params.id, id: params.id,
owner: params.owner, owner: params.owner,
@ -44,7 +44,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 }; const balanceObj: any = { type: TOKEN_TYPE };
if (params.balance) { if (params.balance) {
balanceObj.quantity = params.balance; balanceObj.quantity = params.balance;
@ -56,7 +56,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; const recordContent = yaml.load(fs.readFileSync(recordFilePath, 'utf8')) as any;
return { return {
@ -67,7 +67,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 { return {
ownerAddress: params.owner, ownerAddress: params.owner,
status: params.status, status: params.status,
@ -76,7 +76,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 { return {
status: params.status || 'commit', status: params.status || 'commit',
ownerAddress: params.owner, ownerAddress: params.owner,
@ -92,11 +92,11 @@ export function getAuctionObj(params: { owner: string, status?: string }): any {
type: TOKEN_TYPE, type: TOKEN_TYPE,
quantity: AUCTION_FEES.minimumBid quantity: AUCTION_FEES.minimumBid
}, },
winnerAddress: '', winnerAddress: ''
}; };
} }
export function getBidObject(params: { bidder: string, status?: string }): any { export function getBidObject (params: { bidder: string, status?: string }): any {
return { return {
bidderAddress: params.bidder, bidderAddress: params.bidder,
status: params.status || 'commit', status: params.status || 'commit',
@ -115,6 +115,6 @@ export function getBidObject(params: { bidder: string, status?: string }): any {
}; };
} }
export async function delay(ms: number): Promise<any> { export async function delay (ms: number): Promise<any> {
return new Promise(res => setTimeout(res, ms)) return new Promise((resolve) => setTimeout(resolve, ms));
} }

1349
yarn.lock

File diff suppressed because it is too large Load Diff