diff --git a/src/cmds/cns-cmds/authority-cmds/bond-cmds/set.ts b/src/cmds/cns-cmds/authority-cmds/bond-cmds/set.ts index aad98e4..5ef9936 100644 --- a/src/cmds/cns-cmds/authority-cmds/bond-cmds/set.ts +++ b/src/cmds/cns-cmds/authority-cmds/bond-cmds/set.ts @@ -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); diff --git a/src/cmds/cns-cmds/name-cmds/delete.ts b/src/cmds/cns-cmds/name-cmds/delete.ts new file mode 100644 index 0000000..c7e9a55 --- /dev/null +++ b/src/cmds/cns-cmds/name-cmds/delete.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 = '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)); +} diff --git a/src/cmds/cns-cmds/name-cmds/lookup.ts b/src/cmds/cns-cmds/name-cmds/lookup.ts new file mode 100644 index 0000000..af8a1c8 --- /dev/null +++ b/src/cmds/cns-cmds/name-cmds/lookup.ts @@ -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)); +} diff --git a/src/cmds/cns-cmds/name-cmds/resolve.ts b/src/cmds/cns-cmds/name-cmds/resolve.ts new file mode 100644 index 0000000..13e43f2 --- /dev/null +++ b/src/cmds/cns-cmds/name-cmds/resolve.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 = '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)); +} diff --git a/src/cmds/cns-cmds/name-cmds/set.ts b/src/cmds/cns-cmds/name-cmds/set.ts new file mode 100644 index 0000000..f4d0b8b --- /dev/null +++ b/src/cmds/cns-cmds/name-cmds/set.ts @@ -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)); +} diff --git a/src/cmds/cns-cmds/name.ts b/src/cmds/cns-cmds/name.ts new file mode 100644 index 0000000..de9a32d --- /dev/null +++ b/src/cmds/cns-cmds/name.ts @@ -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() +}