Implement commands for record operations
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { Arguments } from 'yargs';
|
||||
import assert from 'assert';
|
||||
import { Registry } from 'chiba-clonk-client';
|
||||
|
||||
import { getConfig, getConnectionInfo } from '../../../util';
|
||||
|
||||
export const command = 'get';
|
||||
|
||||
export const desc = 'Get record.';
|
||||
|
||||
export const handler = async (argv: Arguments) => {
|
||||
const { id, config } = argv;
|
||||
assert(id, 'Invalid Record ID.');
|
||||
|
||||
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.');
|
||||
assert(chainId, 'Invalid CNS Chain ID.');
|
||||
|
||||
const registry = new Registry(restEndpoint, gqlEndpoint, chainId);
|
||||
const result = await registry.getRecordsByIds([id as string]);
|
||||
|
||||
console.log(JSON.stringify(result, undefined, 2));
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { Arguments } from 'yargs';
|
||||
import assert from 'assert';
|
||||
import { Registry } from 'chiba-clonk-client';
|
||||
|
||||
import { getConfig, getConnectionInfo } from '../../../util';
|
||||
|
||||
export const command = 'list';
|
||||
|
||||
export const desc = 'List records.';
|
||||
|
||||
export const builder = {
|
||||
'bond-id': {
|
||||
type: 'string'
|
||||
},
|
||||
type: {
|
||||
type: 'string'
|
||||
},
|
||||
name: {
|
||||
type: 'string'
|
||||
},
|
||||
all: {
|
||||
type: 'boolean',
|
||||
default: false
|
||||
}
|
||||
}
|
||||
|
||||
export const handler = async (argv: Arguments) => {
|
||||
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
|
||||
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||
const { type, name, bondId, all } = argv;
|
||||
|
||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||
assert(chainId, 'Invalid CNS Chain ID.');
|
||||
|
||||
const registry = new Registry(restEndpoint, gqlEndpoint, chainId);
|
||||
|
||||
const result = await registry.queryRecords({ bondId, type, name }, all as boolean);
|
||||
console.log(JSON.stringify(result, undefined, 2));
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { Arguments } from 'yargs';
|
||||
import assert from 'assert';
|
||||
import path from 'path';
|
||||
import yaml from 'js-yaml';
|
||||
import fs from 'fs';
|
||||
import { Registry } from 'chiba-clonk-client';
|
||||
|
||||
import { getConfig, getGasAndFees, getConnectionInfo } from '../../../util';
|
||||
|
||||
export const command = 'publish';
|
||||
|
||||
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 { restEndpoint, gqlEndpoint, userKey, bondId, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||
|
||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||
assert(userKey, 'Invalid User Key.');
|
||||
assert(bondId, 'Invalid Bond ID.');
|
||||
assert(chainId, 'Invalid CNS Chain ID.');
|
||||
|
||||
let file = null;
|
||||
if (filename) {
|
||||
file = path.join(process.cwd(), filename as string);
|
||||
} else {
|
||||
file = 0; // stdin
|
||||
}
|
||||
|
||||
const { record } = await yaml.load(fs.readFileSync(file, 'utf-8')) as any;
|
||||
const registry = new Registry(restEndpoint, gqlEndpoint, chainId);
|
||||
const fee = getGasAndFees(argv, cnsConfig);
|
||||
const result = await registry.setRecord({ privateKey: userKey, record, bondId }, txKey as string, fee);
|
||||
|
||||
console.log(verbose ? JSON.stringify(result, undefined, 2) : result.data);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import yargs from 'yargs';
|
||||
|
||||
export const command = 'record';
|
||||
|
||||
export const desc = 'Record operations.';
|
||||
|
||||
exports.builder = (yargs: yargs.Argv) => {
|
||||
return yargs.commandDir('record-cmds')
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
import yargs, { Arguments } from 'yargs';
|
||||
|
||||
export const command = 'start';
|
||||
|
||||
export const desc = 'Start local CNS.';
|
||||
|
||||
exports.builder = {
|
||||
'log-file': {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
|
||||
exports.handler = function (argv: Arguments) {
|
||||
const { logFile } = argv;
|
||||
|
||||
console.log('option logFile', logFile)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { Arguments } from 'yargs';
|
||||
import assert from 'assert';
|
||||
import { Registry } from 'chiba-clonk-client';
|
||||
|
||||
import { getConfig, getConnectionInfo } from '../../util';
|
||||
|
||||
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 { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cns);
|
||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||
assert(chainId, 'Invalid CNS Chain ID.');
|
||||
|
||||
console.log('parse argv', restEndpoint, gqlEndpoint, chainId)
|
||||
const registry = new Registry(restEndpoint, gqlEndpoint, chainId);
|
||||
|
||||
// TODO: Implement getStatus method.
|
||||
// const result = await registry.getStatus();
|
||||
// console.log(JSON.stringify(result, undefined, 2));
|
||||
}
|
||||
+13
-1
@@ -5,5 +5,17 @@ export const command = 'cns';
|
||||
export const desc = 'CNS tools';
|
||||
|
||||
exports.builder = (yargs: yargs.Argv) => {
|
||||
return yargs.commandDir('cns-cmds')
|
||||
return yargs
|
||||
.options({
|
||||
'user-key': { type: 'string' },
|
||||
'tx-key': { type: 'string' },
|
||||
'bond-id': { type: 'string' },
|
||||
'chain-id': { type: 'string' },
|
||||
'filename': { alias: 'f' },
|
||||
'id': { type: 'string' },
|
||||
'gas': { type: 'string' },
|
||||
'fees': { type: 'string' }
|
||||
})
|
||||
.commandDir('cns-cmds')
|
||||
.help()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user