Add a config option and arg to set gas price for auto fees calculation #81

Merged
nabarun merged 9 commits from deep-stack/laconic-registry-cli:pm-support-auto-gas into main 2024-09-06 09:44:48 +00:00
2 changed files with 18 additions and 17 deletions
Showing only changes of commit 5dcbdf505d - Show all commits

View File

@ -5,22 +5,23 @@ import { Arguments } from 'yargs';
import { StdFee, GasPrice, parseCoins } from '@cosmjs/stargate'; import { StdFee, GasPrice, parseCoins } from '@cosmjs/stargate';
export const parseGasAndFees = (gas?: string, fees?: string): StdFee | number | undefined => { export const parseGasAndFees = (gas?: string, fees?: string): StdFee | number | undefined => {
const isFeesANumber = !isNaN(Number(fees)); // If fees is not given or a number, treat it as a gas estimation multiplier
if (fees === null || fees === undefined) {
// If fees is a number or not given, treat it as a gas estimation multiplier
if (fees == null) {
return undefined; return undefined;
} else if (isFeesANumber) {
return Number(fees);
} else {
// If fees is not a gas estimation multiplier, gas is required
assert(gas, 'Invalid gas.');
return {
amount: parseCoins(String(fees)),
gas: String(gas)
};
} }
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 => {

View File

@ -126,19 +126,19 @@ export function updateGasAndFeesConfig (gas?: string | null, fees?: string | nul
const configFilePath = './config.yml'; const configFilePath = './config.yml';
const config = getConfig(path.resolve(configFilePath)); const config = getConfig(path.resolve(configFilePath));
if (gas != null) { if (gas) {
config.services.registry.gas = gas; config.services.registry.gas = gas;
} else if (gas === null) { } else if (gas === null) {
delete config.services.registry.gas; delete config.services.registry.gas;
} }
if (fees != null) { if (fees) {
config.services.registry.fees = fees; config.services.registry.fees = fees;
} else if (fees === null) { } else if (fees === null) {
delete config.services.registry.fees; delete config.services.registry.fees;
} }
if (gasPrice != null) { if (gasPrice) {
config.services.registry.gasPrice = gasPrice; config.services.registry.gasPrice = gasPrice;
} else if (gasPrice === null) { } else if (gasPrice === null) {
delete config.services.registry.gasPrice; delete config.services.registry.gasPrice;