Add commands for name operations
This commit is contained in:
parent
fe739c325f
commit
7f3b07b394
@ -12,6 +12,7 @@ export const handler = async (argv: Arguments) => {
|
||||
const name = argv.name as string;
|
||||
const bondId = argv.bondId as string;
|
||||
assert(name, 'Invalid authority name.');
|
||||
assert(bondId, 'Invalid Bond ID.');
|
||||
|
||||
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
|
||||
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||
|
27
src/cmds/cns-cmds/name-cmds/delete.ts
Normal file
27
src/cmds/cns-cmds/name-cmds/delete.ts
Normal 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));
|
||||
}
|
31
src/cmds/cns-cmds/name-cmds/lookup.ts
Normal file
31
src/cmds/cns-cmds/name-cmds/lookup.ts
Normal 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));
|
||||
}
|
25
src/cmds/cns-cmds/name-cmds/resolve.ts
Normal file
25
src/cmds/cns-cmds/name-cmds/resolve.ts
Normal 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));
|
||||
}
|
29
src/cmds/cns-cmds/name-cmds/set.ts
Normal file
29
src/cmds/cns-cmds/name-cmds/set.ts
Normal 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
10
src/cmds/cns-cmds/name.ts
Normal 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()
|
||||
}
|
Loading…
Reference in New Issue
Block a user