Implement commands for account and token operations

This commit is contained in:
nabarun 2022-04-25 15:06:45 +05:30 committed by Ashwin Phatak
parent 97dbbf87c0
commit 46a6389d58
8 changed files with 98 additions and 3 deletions

View File

@ -13,7 +13,7 @@
"typescript": "^4.6.3"
},
"dependencies": {
"chiba-clonk-client": "https://github.com/vulcanize/chiba-clonk-client.git#646e44c1d29bc312834604ada7088e955dbc2303",
"chiba-clonk-client": "https://github.com/vulcanize/chiba-clonk-client.git#cf7e47cde72e6807244bae7101aeb25342fc5588",
"js-yaml": "^4.1.0",
"lodash": "^4.17.21",
"lodash-clean": "^2.2.3",

View File

@ -0,0 +1,28 @@
import { Arguments } from 'yargs';
import assert from 'assert';
import { Account, Registry } from 'chiba-clonk-client';
import { getConfig, getConnectionInfo } from '../../../util';
export const command = 'get';
export const desc = 'Get account.';
export const handler = async (argv: Arguments) => {
let address = argv.address as string;
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(chainId, 'Invalid CNS Chain ID.');
if (!address && privateKey) {
address = new Account(Buffer.from(privateKey, 'hex')).getCosmosAddress();
}
const registry = new Registry(restEndpoint, gqlEndpoint, chainId);
const result = await registry.getAccounts([address]);
console.log(JSON.stringify(result, undefined, 2));
}

View File

@ -0,0 +1,10 @@
import yargs from 'yargs';
export const command = 'account';
export const desc = 'Account operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('account-cmds')
.demandCommand();
}

View File

@ -6,4 +6,5 @@ export const desc = 'Record operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('record-cmds')
.demandCommand()
}

View File

@ -0,0 +1,44 @@
import { Arguments } from 'yargs';
import assert from 'assert';
import { Account, Registry } from 'chiba-clonk-client';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
export const command = 'send';
export const desc = 'Send tokens.';
export const builder = {
type: {
type: 'string'
},
quantity: {
type: 'string'
}
}
export const handler = async (argv: Arguments) => {
const destinationAddress = argv.address as string;
const denom = argv.type as string;
const amount = argv.quantity as string;
assert(destinationAddress, 'Invalid Address.');
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 account = new Account(Buffer.from(privateKey, 'hex'));
const fromAddress = account.formattedCosmosAddress;
const registry = new Registry(restEndpoint, gqlEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
await registry.sendCoins({ denom, amount, destinationAddress }, privateKey, fee);
const result = await registry.getAccounts([fromAddress, destinationAddress]);
console.log(JSON.stringify(result, undefined, 2));
}

View File

@ -0,0 +1,10 @@
import yargs from 'yargs';
export const command = 'tokens';
export const desc = 'Tokens operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('tokens-cmds')
.demandCommand();
}

View File

@ -13,9 +13,11 @@ exports.builder = (yargs: yargs.Argv) => {
'chain-id': { type: 'string' },
'filename': { alias: 'f' },
'id': { type: 'string' },
'address': { type: 'string' },
'gas': { type: 'string' },
'fees': { type: 'string' }
})
.commandDir('cns-cmds')
.demandCommand()
.help()
}

View File

@ -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#646e44c1d29bc312834604ada7088e955dbc2303":
"chiba-clonk-client@https://github.com/vulcanize/chiba-clonk-client.git#cf7e47cde72e6807244bae7101aeb25342fc5588":
version "0.1.0"
resolved "https://github.com/vulcanize/chiba-clonk-client.git#646e44c1d29bc312834604ada7088e955dbc2303"
resolved "https://github.com/vulcanize/chiba-clonk-client.git#cf7e47cde72e6807244bae7101aeb25342fc5588"
dependencies:
"@cosmjs/amino" "^0.28.1"
"@cosmjs/crypto" "^0.28.1"