Implement commands for record operations

This commit is contained in:
2022-04-25 15:18:12 +05:30
committed by Ashwin Phatak
parent 977d9a8ffa
commit 97dbbf87c0
17 changed files with 1615 additions and 19 deletions
+16
View File
@@ -0,0 +1,16 @@
import { Arguments } from "yargs";
import clean from 'lodash-clean';
export const getConnectionInfo = (argv: Arguments, config: any) => {
const { server, userKey, bondId, txKey, chainId, fees, gas } = argv;
const result = {
...config,
...clean({ server, userKey, bondId, txKey, chainId }),
privateKey: txKey || userKey || config.userKey,
gas: String(gas || config.gas),
fees: String(fees || config.fees)
};
return result;
};
+9
View File
@@ -0,0 +1,9 @@
import yaml from 'js-yaml'
import fs from 'fs'
import path from 'path'
export const getConfig = (configFilePath: string): any => {
const resolvedFilePath = path.resolve(process.cwd(), configFilePath);
const configFile = fs.readFileSync(resolvedFilePath, 'utf-8')
return yaml.load(configFile);
};
+20
View File
@@ -0,0 +1,20 @@
import assert from 'assert';
import { Arguments } from 'yargs';
export const parseGasAndFees = (gas: string, fees = '') => {
assert(gas, 'Invalid gas.');
const [{ amount, denom }] = fees.trim().split(',')
.map(fee => fee.trim().split(/(\d+)/))
.filter(([_, amount, denom]) => (denom && amount))
.map(([_, amount, denom]) => ({ denom, amount }));
return { amount, denom, gas };
};
export const getGasAndFees = (argv: Arguments, config: any = {}) => {
return parseGasAndFees(
String(argv.gas || config.gas),
String(argv.fees || config.fees)
);
};
+3
View File
@@ -0,0 +1,3 @@
export * from './fees';
export * from './config';
export * from './common';