From 72c98e14a1c0eabc6084ffe616aa6f7f7befd02a Mon Sep 17 00:00:00 2001 From: nabarun Date: Mon, 25 Apr 2022 20:19:34 +0530 Subject: [PATCH] Add commands for bond and records associate/dissociate --- package.json | 2 +- src/cmds/cns-cmds/bond-cmds/associate.ts | 34 +++++++++++++++++ src/cmds/cns-cmds/bond-cmds/dissociate.ts | 26 +++++++++++++ .../bond-cmds/records-cmds/dissociate.ts | 32 ++++++++++++++++ .../bond-cmds/records-cmds/reassociate.ts | 37 +++++++++++++++++++ src/cmds/cns-cmds/bond-cmds/records.ts | 10 +++++ yarn.lock | 4 +- 7 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 src/cmds/cns-cmds/bond-cmds/associate.ts create mode 100644 src/cmds/cns-cmds/bond-cmds/dissociate.ts create mode 100644 src/cmds/cns-cmds/bond-cmds/records-cmds/dissociate.ts create mode 100644 src/cmds/cns-cmds/bond-cmds/records-cmds/reassociate.ts create mode 100644 src/cmds/cns-cmds/bond-cmds/records.ts diff --git a/package.json b/package.json index f306526..5ca0e3e 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "typescript": "^4.6.3" }, "dependencies": { - "chiba-clonk-client": "https://github.com/vulcanize/chiba-clonk-client.git#cf7e47cde72e6807244bae7101aeb25342fc5588", + "chiba-clonk-client": "https://github.com/vulcanize/chiba-clonk-client.git#ec31da8cdea79170a87caf6124d9c12cd54dfbe4", "js-yaml": "^4.1.0", "lodash": "^4.17.21", "lodash-clean": "^2.2.3", diff --git a/src/cmds/cns-cmds/bond-cmds/associate.ts b/src/cmds/cns-cmds/bond-cmds/associate.ts new file mode 100644 index 0000000..e2546db --- /dev/null +++ b/src/cmds/cns-cmds/bond-cmds/associate.ts @@ -0,0 +1,34 @@ +import { Arguments } from 'yargs'; +import assert from 'assert'; +import { Registry } from 'chiba-clonk-client'; + +import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util'; + +export const command = 'associate'; + +export const desc = 'Associate record with bond.'; + +export const builder = { + 'bond-id': { + type: 'string' + } +} + +export const handler = async (argv: Arguments) => { + const id = argv.id as string; + const bondId = argv.bondId as string; + assert(id, 'Invalid Record ID.'); + assert(bondId, 'Invalid Bond 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.associateBond({ recordId: id, bondId }, privateKey, fee); + console.log(JSON.stringify(result, undefined, 2)); +} diff --git a/src/cmds/cns-cmds/bond-cmds/dissociate.ts b/src/cmds/cns-cmds/bond-cmds/dissociate.ts new file mode 100644 index 0000000..716608f --- /dev/null +++ b/src/cmds/cns-cmds/bond-cmds/dissociate.ts @@ -0,0 +1,26 @@ +import { Arguments } from 'yargs'; +import assert from 'assert'; +import { Registry } from 'chiba-clonk-client'; + +import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util'; + +export const command = 'dissociate'; + +export const desc = 'Dissociate record from bond.'; + +export const handler = async (argv: Arguments) => { + const id = argv.id as string; + 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.dissociateBond({ recordId: id }, privateKey, fee); + console.log(JSON.stringify(result, undefined, 2)); +} diff --git a/src/cmds/cns-cmds/bond-cmds/records-cmds/dissociate.ts b/src/cmds/cns-cmds/bond-cmds/records-cmds/dissociate.ts new file mode 100644 index 0000000..f0bcf06 --- /dev/null +++ b/src/cmds/cns-cmds/bond-cmds/records-cmds/dissociate.ts @@ -0,0 +1,32 @@ +import { Arguments } from 'yargs'; +import assert from 'assert'; +import { Registry } from 'chiba-clonk-client'; + +import { getConfig, getConnectionInfo, getGasAndFees } from '../../../../util'; + +export const command = 'dissociate'; + +export const desc = 'Dissociate all records from bond.'; + +export const builder = { + 'bond-id': { + type: 'string' + } +} + +export const handler = async (argv: Arguments) => { + const bondId = argv.bondId as string; + assert(bondId, 'Invalid Bond 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.dissociateRecords({ bondId }, privateKey, fee); + console.log(JSON.stringify(result, undefined, 2)); +} diff --git a/src/cmds/cns-cmds/bond-cmds/records-cmds/reassociate.ts b/src/cmds/cns-cmds/bond-cmds/records-cmds/reassociate.ts new file mode 100644 index 0000000..b8dda30 --- /dev/null +++ b/src/cmds/cns-cmds/bond-cmds/records-cmds/reassociate.ts @@ -0,0 +1,37 @@ +import { Arguments } from 'yargs'; +import assert from 'assert'; +import { Registry } from 'chiba-clonk-client'; + +import { getConfig, getConnectionInfo, getGasAndFees } from '../../../../util'; + +export const command = 'reassociate'; + +export const desc = 'Reassociate records with new bond.'; + +export const builder = { + 'old-bond-id': { + type: 'string' + }, + 'new-bond-id': { + type: 'string' + } +} + +export const handler = async (argv: Arguments) => { + const oldBondId = argv.oldBondId as string; + const newBondId = argv.newBondId as string; + assert(oldBondId, 'Invalid Old Bond ID.'); + assert(newBondId, 'Invalid New Bond 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.reassociateRecords({ oldBondId, newBondId }, privateKey, fee); + console.log(JSON.stringify(result, undefined, 2)); +} diff --git a/src/cmds/cns-cmds/bond-cmds/records.ts b/src/cmds/cns-cmds/bond-cmds/records.ts new file mode 100644 index 0000000..33a29f2 --- /dev/null +++ b/src/cmds/cns-cmds/bond-cmds/records.ts @@ -0,0 +1,10 @@ +import yargs from 'yargs'; + +export const command = 'records'; + +export const desc = 'Bond records operations.'; + +exports.builder = (yargs: yargs.Argv) => { + return yargs.commandDir('records-cmds') + .demandCommand(); +} diff --git a/yarn.lock b/yarn.lock index 0f8eaea..844e991 100644 --- a/yarn.lock +++ b/yarn.lock @@ -714,9 +714,9 @@ chalk@^2.4.1: escape-string-regexp "^1.0.5" supports-color "^5.3.0" -"chiba-clonk-client@https://github.com/vulcanize/chiba-clonk-client.git#cf7e47cde72e6807244bae7101aeb25342fc5588": +"chiba-clonk-client@https://github.com/vulcanize/chiba-clonk-client.git#ec31da8cdea79170a87caf6124d9c12cd54dfbe4": version "0.1.0" - resolved "https://github.com/vulcanize/chiba-clonk-client.git#cf7e47cde72e6807244bae7101aeb25342fc5588" + resolved "https://github.com/vulcanize/chiba-clonk-client.git#ec31da8cdea79170a87caf6124d9c12cd54dfbe4" dependencies: "@cosmjs/amino" "^0.28.1" "@cosmjs/crypto" "^0.28.1"