Skip to content

Commit

Permalink
Use registry-sdk methods to parse gas and fees (#85)
Browse files Browse the repository at this point in the history
Part of [Service provider auctions for web deployments](https://www.notion.so/Service-provider-auctions-for-web-deployments-104a6b22d47280dbad51d28aa3a91d75)

Co-authored-by: IshaVenikar <ishavenikar7@gmail.com>
Reviewed-on: https://git.vdb.to/cerc-io/laconic-registry-cli/pulls/85
Co-authored-by: Prathamesh Musale <prathamesh@noreply.git.vdb.to>
Co-committed-by: Prathamesh Musale <prathamesh@noreply.git.vdb.to>
  • Loading branch information
2 people authored and nabarun committed Oct 8, 2024
1 parent c770d14 commit 936ad73
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"typescript": "^4.6.3"
},
"dependencies": {
"@cerc-io/registry-sdk": "^0.2.10",
"@cerc-io/registry-sdk": "^0.2.11",
"@cosmjs/stargate": "^0.32.2",
"fs-extra": "^10.1.0",
"js-yaml": "^3.14.1",
Expand Down
26 changes: 3 additions & 23 deletions src/util/fees.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import assert from 'assert';
import { Arguments } from 'yargs';

import { StdFee, GasPrice, parseCoins } 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)
};
};
import { parseGasAndFees, getGasPrice as registryGetGasPrice } from '@cerc-io/registry-sdk';
import { StdFee, GasPrice } from '@cosmjs/stargate';

export const getGasAndFees = (argv: Arguments, config: any = {}): StdFee | number | undefined => {
return parseGasAndFees(
Expand All @@ -33,5 +13,5 @@ export const getGasAndFees = (argv: Arguments, config: any = {}): StdFee | numbe

export const getGasPrice = (argv: Arguments, config: any = {}): GasPrice | undefined => {
const gasPriceString = argv.gasPrice || config.gasPrice;
return gasPriceString != null ? GasPrice.fromString(String(gasPriceString)) : undefined;
return registryGetGasPrice(gasPriceString);
};

0 comments on commit 936ad73

Please sign in to comment.