Implement commands for account and token operations
This commit is contained in:
parent
97dbbf87c0
commit
46a6389d58
@ -13,7 +13,7 @@
|
|||||||
"typescript": "^4.6.3"
|
"typescript": "^4.6.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"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",
|
"js-yaml": "^4.1.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"lodash-clean": "^2.2.3",
|
"lodash-clean": "^2.2.3",
|
||||||
|
28
src/cmds/cns-cmds/account-cmds/get.ts
Normal file
28
src/cmds/cns-cmds/account-cmds/get.ts
Normal 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));
|
||||||
|
}
|
10
src/cmds/cns-cmds/account.ts
Normal file
10
src/cmds/cns-cmds/account.ts
Normal 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();
|
||||||
|
}
|
@ -6,4 +6,5 @@ export const desc = 'Record operations.';
|
|||||||
|
|
||||||
exports.builder = (yargs: yargs.Argv) => {
|
exports.builder = (yargs: yargs.Argv) => {
|
||||||
return yargs.commandDir('record-cmds')
|
return yargs.commandDir('record-cmds')
|
||||||
|
.demandCommand()
|
||||||
}
|
}
|
||||||
|
44
src/cmds/cns-cmds/tokens-cmds/send.ts
Normal file
44
src/cmds/cns-cmds/tokens-cmds/send.ts
Normal 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));
|
||||||
|
}
|
10
src/cmds/cns-cmds/tokens.ts
Normal file
10
src/cmds/cns-cmds/tokens.ts
Normal 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();
|
||||||
|
}
|
@ -13,9 +13,11 @@ exports.builder = (yargs: yargs.Argv) => {
|
|||||||
'chain-id': { type: 'string' },
|
'chain-id': { type: 'string' },
|
||||||
'filename': { alias: 'f' },
|
'filename': { alias: 'f' },
|
||||||
'id': { type: 'string' },
|
'id': { type: 'string' },
|
||||||
|
'address': { type: 'string' },
|
||||||
'gas': { type: 'string' },
|
'gas': { type: 'string' },
|
||||||
'fees': { type: 'string' }
|
'fees': { type: 'string' }
|
||||||
})
|
})
|
||||||
.commandDir('cns-cmds')
|
.commandDir('cns-cmds')
|
||||||
|
.demandCommand()
|
||||||
.help()
|
.help()
|
||||||
}
|
}
|
||||||
|
@ -714,9 +714,9 @@ chalk@^2.4.1:
|
|||||||
escape-string-regexp "^1.0.5"
|
escape-string-regexp "^1.0.5"
|
||||||
supports-color "^5.3.0"
|
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"
|
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:
|
dependencies:
|
||||||
"@cosmjs/amino" "^0.28.1"
|
"@cosmjs/amino" "^0.28.1"
|
||||||
"@cosmjs/crypto" "^0.28.1"
|
"@cosmjs/crypto" "^0.28.1"
|
||||||
|
Loading…
Reference in New Issue
Block a user