Use registry-sdk methods to parse gas and fees #85

Merged
nabarun merged 2 commits from deep-stack/laconic-registry-cli:iv-update-gas-usage into main 2024-10-08 03:47:12 +00:00
2 changed files with 4 additions and 24 deletions

View File

@ -29,7 +29,7 @@
"typescript": "^4.6.3" "typescript": "^4.6.3"
}, },
"dependencies": { "dependencies": {
"@cerc-io/registry-sdk": "^0.2.10", "@cerc-io/registry-sdk": "^0.2.11",
"@cosmjs/stargate": "^0.32.2", "@cosmjs/stargate": "^0.32.2",
"fs-extra": "^10.1.0", "fs-extra": "^10.1.0",
"js-yaml": "^3.14.1", "js-yaml": "^3.14.1",

View File

@ -1,28 +1,8 @@
/* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-unused-vars */
import assert from 'assert';
import { Arguments } from 'yargs'; import { Arguments } from 'yargs';
import { StdFee, GasPrice, parseCoins } from '@cosmjs/stargate'; import { parseGasAndFees, getGasPrice as registryGetGasPrice } from '@cerc-io/registry-sdk';
import { StdFee, GasPrice } from '@cosmjs/stargate';
export const parseGasAndFees = (gas?: string, fees?: string): StdFee | number | undefined => {
// If fees is not given or a number, treat it as a gas estimation multiplier
if (fees === null || fees === undefined) {
return undefined;
}
const isFeesANumber = !isNaN(Number(fees));
if (isFeesANumber) {
return Number(fees);
}
// If fees is not a gas estimation multiplier, gas is required
assert(gas, 'Invalid gas.');
return {
amount: parseCoins(String(fees)),
gas: String(gas)
};
};
export const getGasAndFees = (argv: Arguments, config: any = {}): StdFee | number | undefined => { export const getGasAndFees = (argv: Arguments, config: any = {}): StdFee | number | undefined => {
return parseGasAndFees( return parseGasAndFees(
@ -33,5 +13,5 @@ export const getGasAndFees = (argv: Arguments, config: any = {}): StdFee | numbe
export const getGasPrice = (argv: Arguments, config: any = {}): GasPrice | undefined => { export const getGasPrice = (argv: Arguments, config: any = {}): GasPrice | undefined => {
const gasPriceString = argv.gasPrice || config.gasPrice; const gasPriceString = argv.gasPrice || config.gasPrice;
return gasPriceString != null ? GasPrice.fromString(String(gasPriceString)) : undefined; return registryGetGasPrice(gasPriceString);
}; };