Add a config option and arg to set gas price for auto
fees calculation
#81
@ -5,22 +5,23 @@ import { Arguments } from 'yargs';
|
||||
import { StdFee, GasPrice, parseCoins } from '@cosmjs/stargate';
|
||||
|
||||
export const parseGasAndFees = (gas?: string, fees?: string): StdFee | number | undefined => {
|
||||
const isFeesANumber = !isNaN(Number(fees));
|
||||
|
||||
// If fees is a number or not given, treat it as a gas estimation multiplier
|
||||
if (fees == null) {
|
||||
// If fees is not given or a number, treat it as a gas estimation multiplier
|
||||
if (fees === null || fees === 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 => {
|
||||
|
@ -126,19 +126,19 @@ export function updateGasAndFeesConfig (gas?: string | null, fees?: string | nul
|
||||
const configFilePath = './config.yml';
|
||||
const config = getConfig(path.resolve(configFilePath));
|
||||
|
||||
if (gas != null) {
|
||||
if (gas) {
|
||||
config.services.registry.gas = gas;
|
||||
} else if (gas === null) {
|
||||
delete config.services.registry.gas;
|
||||
}
|
||||
|
||||
if (fees != null) {
|
||||
if (fees) {
|
||||
config.services.registry.fees = fees;
|
||||
} else if (fees === null) {
|
||||
delete config.services.registry.fees;
|
||||
}
|
||||
|
||||
if (gasPrice != null) {
|
||||
if (gasPrice) {
|
||||
config.services.registry.gasPrice = gasPrice;
|
||||
} else if (gasPrice === null) {
|
||||
delete config.services.registry.gasPrice;
|
||||
|
Loading…
Reference in New Issue
Block a user