From fe739c325f35c3921d33ee62369839ce83a46050 Mon Sep 17 00:00:00 2001 From: nabarun Date: Tue, 26 Apr 2022 10:22:25 +0530 Subject: [PATCH] Add commands for authority operations --- .../cns-cmds/authority-cmds/bond-cmds/set.ts | 27 ++++++++++++++ src/cmds/cns-cmds/authority-cmds/bond.ts | 10 ++++++ src/cmds/cns-cmds/authority-cmds/reserve.ts | 35 +++++++++++++++++++ src/cmds/cns-cmds/authority-cmds/whois.ts | 25 +++++++++++++ src/cmds/cns-cmds/authority.ts | 10 ++++++ 5 files changed, 107 insertions(+) create mode 100644 src/cmds/cns-cmds/authority-cmds/bond-cmds/set.ts create mode 100644 src/cmds/cns-cmds/authority-cmds/bond.ts create mode 100644 src/cmds/cns-cmds/authority-cmds/reserve.ts create mode 100644 src/cmds/cns-cmds/authority-cmds/whois.ts create mode 100644 src/cmds/cns-cmds/authority.ts diff --git a/src/cmds/cns-cmds/authority-cmds/bond-cmds/set.ts b/src/cmds/cns-cmds/authority-cmds/bond-cmds/set.ts new file mode 100644 index 0000000..aad98e4 --- /dev/null +++ b/src/cmds/cns-cmds/authority-cmds/bond-cmds/set.ts @@ -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 = 'set [name] [bond-id]'; + +export const desc = 'Set bond for authority.'; + +export const handler = async (argv: Arguments) => { + const name = argv.name as string; + const bondId = argv.bondId as string; + assert(name, 'Invalid authority 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.setAuthorityBond({ name, bondId }, privateKey, fee); + console.log(JSON.stringify(result, undefined, 2)); +} diff --git a/src/cmds/cns-cmds/authority-cmds/bond.ts b/src/cmds/cns-cmds/authority-cmds/bond.ts new file mode 100644 index 0000000..408f2ed --- /dev/null +++ b/src/cmds/cns-cmds/authority-cmds/bond.ts @@ -0,0 +1,10 @@ +import yargs from 'yargs'; + +export const command = 'bond'; + +export const desc = 'Authority bond operations.'; + +exports.builder = (yargs: yargs.Argv) => { + return yargs.commandDir('bond-cmds') + .demandCommand(); +} diff --git a/src/cmds/cns-cmds/authority-cmds/reserve.ts b/src/cmds/cns-cmds/authority-cmds/reserve.ts new file mode 100644 index 0000000..66e3bea --- /dev/null +++ b/src/cmds/cns-cmds/authority-cmds/reserve.ts @@ -0,0 +1,35 @@ +import { Arguments } from 'yargs'; +import assert from 'assert'; +import { Registry } from 'chiba-clonk-client'; + +import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util'; + +export const command = 'reserve [name]'; + +export const desc = 'Reserve authority/name.'; + +export const builder = { + owner: { + 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 { 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.reserveAuthority({ name, owner }, privateKey, fee); + + console.log(JSON.stringify(result, undefined, 2)); +} diff --git a/src/cmds/cns-cmds/authority-cmds/whois.ts b/src/cmds/cns-cmds/authority-cmds/whois.ts new file mode 100644 index 0000000..aad9887 --- /dev/null +++ b/src/cmds/cns-cmds/authority-cmds/whois.ts @@ -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 = 'whois [name]'; + +export const desc = 'Lookup authority information.'; + +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 { 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.lookupAuthorities([name], true); + + console.log(JSON.stringify(result, undefined, 2)); +} diff --git a/src/cmds/cns-cmds/authority.ts b/src/cmds/cns-cmds/authority.ts new file mode 100644 index 0000000..13bc7a1 --- /dev/null +++ b/src/cmds/cns-cmds/authority.ts @@ -0,0 +1,10 @@ +import yargs from 'yargs'; + +export const command = 'authority'; + +export const desc = 'Name authority operations.'; + +exports.builder = (yargs: yargs.Argv) => { + return yargs.commandDir('authority-cmds') + .demandCommand(); +}