From 7a493ee4e9ae119f8523f18cec26ebaf7713d51c Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 17 Jun 2025 18:49:12 +0530 Subject: [PATCH] Use cosmjs-util package --- package.json | 1 + src/index.ts | 2 +- src/utils.ts | 34 ---------------------------------- 3 files changed, 2 insertions(+), 35 deletions(-) delete mode 100644 src/utils.ts diff --git a/package.json b/package.json index b9f783f..fae2074 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "@cosmjs/encoding": "^0.33.1", "@cosmjs/proto-signing": "^0.33.1", "@cosmjs/stargate": "^0.33.1", + "@LaconicNetwork/cosmjs-util": "^0.1.0", "@keyv/sqlite": "^3.6.7", "cors": "^2.8.5", "express": "^4.19.2", diff --git a/src/index.ts b/src/index.ts index 31f596d..3d24c02 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,7 +11,7 @@ import { Comet38Client } from '@cosmjs/tendermint-rpc'; import { fromBech32 } from '@cosmjs/encoding'; import KeyvSqlite from '@keyv/sqlite'; -import { parseCustomGasPrice } from './utils'; +import { parseCustomGasPrice } from '@LaconicNetwork/cosmjs-util'; const CONFIG_PATH = 'environments/local.toml'; const FAUCET_DATA_FILE = 'faucet_data.sqlite'; diff --git a/src/utils.ts b/src/utils.ts deleted file mode 100644 index fddcf95..0000000 --- a/src/utils.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { GasPrice } from '@cosmjs/stargate'; -import { Decimal } from '@cosmjs/math'; - -/** - * Parses a gas price string with a more flexible denom regex. - * This function is a custom implementation to allow for denoms that can start with - * numbers or other valid characters, while still supporting an optional dollar sign prefix. - * - * @param gasPrice The gas price string, e.g., '0.012utoken' or '0.001$mydenom'. - * @returns A GasPrice object. - * @throws If the gas price string is invalid. - */ -export function parseCustomGasPrice (gasPrice: string): GasPrice { - // This regex allows the denom to start with an optional '$' followed by any - // alphanumeric character or ':', '.', '_', '-'. It must have at least one such character. - const matchResult = gasPrice.match(/^([0-9.]+)(\$?[a-zA-Z][a-zA-Z0-9/:._-]*)$/); - - if (!matchResult) { - throw new Error('Invalid gas price string'); - } - - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const [_, amount, denom] = matchResult; - - // Basic denom length check (similar to checkDenom in @cosmjs/stargate) - if (denom.length < 2 || denom.length > 128) { - throw new Error('Denom must be between 2 and 128 characters'); - } - - const fractionalDigits = 18; // Standard for Cosmos SDK decimals - const decimalAmount = Decimal.fromUserInput(amount, fractionalDigits); - - return new GasPrice(decimalAmount, denom); -}