Setup linter and add it to CI #54
5
.eslintignore
Normal file
5
.eslintignore
Normal file
@ -0,0 +1,5 @@
|
||||
# Don't lint node_modules.
|
||||
node_modules
|
||||
|
||||
# Don't lint build output.
|
||||
dist
|
21
.eslintrc.json
Normal file
21
.eslintrc.json
Normal 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
28
.gitea/workflows/lint.yml
Normal 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
1
.husky/pre-commit
Normal file
@ -0,0 +1 @@
|
||||
yarn lint
|
@ -2,5 +2,5 @@
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
setupFiles: ["dotenv/config"]
|
||||
setupFiles: ['dotenv/config']
|
||||
};
|
||||
|
15
package.json
15
package.json
@ -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,7 +39,8 @@
|
||||
"test": "jest --runInBand --verbose test/cli.test.ts",
|
||||
"lint": "eslint .",
|
||||
"clean": "rm -rf ./dist",
|
||||
"build": "tsc"
|
||||
"build": "tsc",
|
||||
"prepare": "husky"
|
||||
},
|
||||
"bin": {
|
||||
"laconic": "bin/laconic"
|
||||
|
@ -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.');
|
||||
@ -25,4 +25,4 @@ export const handler = async (argv: Arguments) => {
|
||||
const result = await registry.getAccounts([address]);
|
||||
|
||||
queryOutput(result, argv.output);
|
||||
}
|
||||
};
|
||||
|
@ -7,4 +7,4 @@ export const desc = 'Account operations.';
|
||||
exports.builder = (yargs: yargs.Argv) => {
|
||||
return yargs.commandDir('account-cmds')
|
||||
.demandCommand();
|
||||
}
|
||||
};
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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}}`
|
||||
const success = `{"success":${result.code === 0}}`;
|
||||
|
||||
txOutput(result,success,argv.output,argv.verbose)
|
||||
}
|
||||
txOutput(result, success, argv.output, argv.verbose);
|
||||
};
|
||||
|
@ -7,9 +7,9 @@ export const desc = 'Auction bid operations.';
|
||||
exports.builder = (yargs: yargs.Argv) => {
|
||||
return yargs.options({
|
||||
'auction-id': { type: 'string' },
|
||||
'type': { type: 'string' },
|
||||
'quantity': { type: 'string' },
|
||||
type: { type: 'string' },
|
||||
quantity: { type: 'string' },
|
||||
'file-path': { type: 'string' }
|
||||
}).commandDir('bid-cmds')
|
||||
.demandCommand();
|
||||
}
|
||||
};
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -7,4 +7,4 @@ export const desc = 'Auction operations.';
|
||||
exports.builder = (yargs: yargs.Argv) => {
|
||||
return yargs.commandDir('auction-cmds')
|
||||
.demandCommand();
|
||||
}
|
||||
};
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -7,4 +7,4 @@ export const desc = 'Authority bond operations.';
|
||||
exports.builder = (yargs: yargs.Argv) => {
|
||||
return yargs.commandDir('bond-cmds')
|
||||
.demandCommand();
|
||||
}
|
||||
};
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -7,4 +7,4 @@ export const desc = 'Name authority operations.';
|
||||
exports.builder = (yargs: yargs.Argv) => {
|
||||
return yargs.commandDir('authority-cmds')
|
||||
.demandCommand();
|
||||
}
|
||||
};
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -9,10 +9,10 @@ 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);
|
||||
};
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -7,4 +7,4 @@ export const desc = 'Bond records operations.';
|
||||
exports.builder = (yargs: yargs.Argv) => {
|
||||
return yargs.commandDir('records-cmds')
|
||||
.demandCommand();
|
||||
}
|
||||
};
|
||||
|
@ -3,7 +3,6 @@ import assert from 'assert';
|
||||
import { Registry } from '@cerc-io/laconic-sdk';
|
||||
|
||||
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
|
||||
import { isNil } from 'lodash';
|
||||
|
||||
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);
|
||||
};
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -7,4 +7,4 @@ export const desc = 'Bonds operations.';
|
||||
exports.builder = (yargs: yargs.Argv) => {
|
||||
return yargs.commandDir('bond-cmds')
|
||||
.demandCommand();
|
||||
}
|
||||
};
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -6,5 +6,5 @@ export const desc = 'Name operations.';
|
||||
|
||||
exports.builder = (yargs: yargs.Argv) => {
|
||||
return yargs.commandDir('name-cmds')
|
||||
.demandCommand()
|
||||
}
|
||||
.demandCommand();
|
||||
};
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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];
|
||||
filters[String(filterArgs[i]).replace(/^-+/, '')] = filterArgs[i + 1];
|
||||
}
|
||||
|
||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||
@ -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);
|
||||
};
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -7,5 +7,5 @@ export const desc = 'Record operations.';
|
||||
exports.builder = (yargs: yargs.Argv) => {
|
||||
return yargs.commandDir('record-cmds')
|
||||
.parserConfiguration({ 'unknown-options-as-args': true })
|
||||
.demandCommand()
|
||||
}
|
||||
.demandCommand();
|
||||
};
|
||||
|
@ -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));
|
||||
}
|
||||
};
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -7,4 +7,4 @@ export const desc = 'Tokens operations.';
|
||||
exports.builder = (yargs: yargs.Argv) => {
|
||||
return yargs.commandDir('tokens-cmds')
|
||||
.demandCommand();
|
||||
}
|
||||
};
|
||||
|
@ -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();
|
||||
};
|
||||
|
@ -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: {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Arguments } from "yargs";
|
||||
import { Arguments } from 'yargs';
|
||||
import clean from 'lodash-clean';
|
||||
|
||||
export const getConnectionInfo = (argv: Arguments, config: any) => {
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import assert from 'assert';
|
||||
import { Arguments } from 'yargs';
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
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));
|
||||
} else {
|
||||
console.log(verbose ? JSON.stringify(result, undefined, 2) : msg);
|
||||
@ -8,15 +8,15 @@ export const txOutput = (result:any,msg:string,output:unknown,verbose:unknown) =
|
||||
};
|
||||
|
||||
export const queryOutput = (result: any, output: unknown) => {
|
||||
if (output=="json"){
|
||||
if (output === 'json') {
|
||||
console.log(JSON.parse(JSON.stringify(result)));
|
||||
} else {
|
||||
console.log(JSON.stringify(result, (key, value) => {
|
||||
try {
|
||||
return JSON.parse(value)
|
||||
return JSON.parse(value);
|
||||
} catch (e) {
|
||||
return value;
|
||||
}
|
||||
}, 2));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -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 () => {
|
||||
|
@ -93,7 +93,7 @@ export function getAuctionObj(params: { owner: string, status?: string }): any {
|
||||
type: TOKEN_TYPE,
|
||||
quantity: AUCTION_FEES.minimumBid
|
||||
},
|
||||
winnerAddress: '',
|
||||
winnerAddress: ''
|
||||
};
|
||||
}
|
||||
|
||||
@ -117,5 +117,5 @@ export function getBidObj(params: { bidder: string, status?: string }): any {
|
||||
}
|
||||
|
||||
export async function delay (ms: number): Promise<any> {
|
||||
return new Promise(res => setTimeout(res, ms))
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user