Add commands for name operations

This commit is contained in:
nabarun 2022-04-26 11:33:52 +05:30 committed by Ashwin Phatak
parent fe739c325f
commit 7f3b07b394
6 changed files with 123 additions and 0 deletions

View File

@ -12,6 +12,7 @@ export const handler = async (argv: Arguments) => {
const name = argv.name as string; const name = argv.name as string;
const bondId = argv.bondId as string; const bondId = argv.bondId as string;
assert(name, 'Invalid authority name.'); 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); const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);

View File

@ -0,0 +1,27 @@
import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from 'chiba-clonk-client';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
export const command = 'delete [name]';
export const desc = 'Delete name (remove name to record ID mapping).';
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 { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
assert(privateKey, 'Invalid Transaction Key.');
assert(chainId, 'Invalid CNS Chain ID.');
const registry = new Registry(restEndpoint, gqlEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.deleteName({ crn: name }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
}

View File

@ -0,0 +1,31 @@
import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from 'chiba-clonk-client';
import { getConfig, getConnectionInfo } from '../../../util';
export const command = 'lookup [name]';
export const desc = 'Lookup name information.';
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 { 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.lookupNames([name], argv.history as boolean);
console.log(JSON.stringify(result, undefined, 2));
}

View File

@ -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 = 'resolve [name]';
export const desc = 'Resolve name to record.';
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 { 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.resolveNames([name]);
console.log(JSON.stringify(result, undefined, 4));
}

View File

@ -0,0 +1,29 @@
import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from 'chiba-clonk-client';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
export const command = 'set [name] [id]';
export const desc = 'Set name (create name to record ID mapping).';
export const handler = async (argv: Arguments) => {
const name = argv.name as string;
const id = argv.id as string;
assert(name, 'Invalid Name.');
assert(id, 'Invalid Record ID.');
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.');
assert(privateKey, 'Invalid Transaction Key.');
assert(chainId, 'Invalid CNS Chain ID.');
const registry = new Registry(restEndpoint, gqlEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.setName({ crn: name, cid: id }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
}

10
src/cmds/cns-cmds/name.ts Normal file
View File

@ -0,0 +1,10 @@
import yargs from 'yargs';
export const command = 'name';
export const desc = 'Name operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('name-cmds')
.demandCommand()
}