Implement commands for record operations
This commit is contained in:
@@ -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;
|
||||
};
|
||||
@@ -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);
|
||||
};
|
||||
@@ -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)
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from './fees';
|
||||
export * from './config';
|
||||
export * from './common';
|
||||
Reference in New Issue
Block a user