Implement commands for bond operations
This commit is contained in:
parent
46a6389d58
commit
1133ac774c
26
src/cmds/cns-cmds/bond-cmds/cancel.ts
Normal file
26
src/cmds/cns-cmds/bond-cmds/cancel.ts
Normal file
@ -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 = 'cancel';
|
||||||
|
|
||||||
|
export const desc = 'Cancel bond.';
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const id = argv.id as string
|
||||||
|
assert(id, '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.cancelBond({ id }, privateKey, fee);
|
||||||
|
console.log(JSON.stringify(result, undefined, 2));
|
||||||
|
}
|
39
src/cmds/cns-cmds/bond-cmds/create.ts
Normal file
39
src/cmds/cns-cmds/bond-cmds/create.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Registry } from 'chiba-clonk-client';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'create';
|
||||||
|
|
||||||
|
export const desc = 'Create bond.';
|
||||||
|
|
||||||
|
export const builder = {
|
||||||
|
type: {
|
||||||
|
type: 'string'
|
||||||
|
},
|
||||||
|
quantity: {
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const { config, verbose } = argv;
|
||||||
|
const denom = argv.type as string;
|
||||||
|
const amount = argv.quantity as string;
|
||||||
|
|
||||||
|
assert(denom, 'Invalid Type.');
|
||||||
|
assert(amount, 'Invalid Quantity.');
|
||||||
|
|
||||||
|
const { services: { cns: cnsConfig } } = getConfig(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.createBond({ denom, amount }, privateKey, fee);
|
||||||
|
console.log(verbose ? JSON.stringify(result, undefined, 2) : result.data);
|
||||||
|
}
|
25
src/cmds/cns-cmds/bond-cmds/get.ts
Normal file
25
src/cmds/cns-cmds/bond-cmds/get.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 = 'get';
|
||||||
|
|
||||||
|
export const desc = 'Get bond.';
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const { id, config } = argv;
|
||||||
|
console.assert(id, 'Bond Id is required.');
|
||||||
|
|
||||||
|
const { services: { cns: cnsConfig } } = getConfig(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.getBondsByIds([id as string]);
|
||||||
|
console.log(JSON.stringify(result, undefined, 2));
|
||||||
|
}
|
29
src/cmds/cns-cmds/bond-cmds/list.ts
Normal file
29
src/cmds/cns-cmds/bond-cmds/list.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Registry } from 'chiba-clonk-client';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'list';
|
||||||
|
|
||||||
|
export const desc = 'List bonds.';
|
||||||
|
|
||||||
|
export const builder = {
|
||||||
|
owner: {
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
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 { owner } = argv;
|
||||||
|
const result = await registry.queryBonds({ owner });
|
||||||
|
console.log(JSON.stringify(result, undefined, 2));
|
||||||
|
}
|
40
src/cmds/cns-cmds/bond-cmds/refill.ts
Normal file
40
src/cmds/cns-cmds/bond-cmds/refill.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Registry } from 'chiba-clonk-client';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'refill';
|
||||||
|
|
||||||
|
export const desc = 'Refill bond.';
|
||||||
|
|
||||||
|
export const builder = {
|
||||||
|
type: {
|
||||||
|
type: 'string'
|
||||||
|
},
|
||||||
|
quantity: {
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const denom = argv.type as string;
|
||||||
|
const amount = argv.quantity as string;
|
||||||
|
const id = argv.id as string
|
||||||
|
|
||||||
|
assert(id, 'Invalid Bond ID.');
|
||||||
|
assert(denom, 'Invalid Type.');
|
||||||
|
assert(amount, 'Invalid Quantity.');
|
||||||
|
|
||||||
|
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.refillBond({ id, denom, amount }, privateKey, fee);
|
||||||
|
console.log(JSON.stringify(result, undefined, 2));
|
||||||
|
}
|
40
src/cmds/cns-cmds/bond-cmds/withdraw.ts
Normal file
40
src/cmds/cns-cmds/bond-cmds/withdraw.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Registry } from 'chiba-clonk-client';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'withdraw';
|
||||||
|
|
||||||
|
export const desc = 'Withdraw funds from bond.';
|
||||||
|
|
||||||
|
export const builder = {
|
||||||
|
type: {
|
||||||
|
type: 'string'
|
||||||
|
},
|
||||||
|
quantity: {
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const denom = argv.type as string;
|
||||||
|
const amount = argv.quantity as string;
|
||||||
|
const id = argv.id as string
|
||||||
|
|
||||||
|
assert(id, 'Invalid Bond ID.');
|
||||||
|
assert(denom, 'Invalid Type.');
|
||||||
|
assert(amount, 'Invalid Quantity.');
|
||||||
|
|
||||||
|
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.withdrawBond({ id, denom, amount }, privateKey, fee);
|
||||||
|
console.log(JSON.stringify(result, undefined, 2));
|
||||||
|
}
|
10
src/cmds/cns-cmds/bond.ts
Normal file
10
src/cmds/cns-cmds/bond.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import yargs from 'yargs';
|
||||||
|
|
||||||
|
export const command = 'bond';
|
||||||
|
|
||||||
|
export const desc = 'Bonds operations.';
|
||||||
|
|
||||||
|
exports.builder = (yargs: yargs.Argv) => {
|
||||||
|
return yargs.commandDir('bond-cmds')
|
||||||
|
.demandCommand();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user