Use method to parse gas and fees from registry-sdk

This commit is contained in:
IshaVenikar 2024-10-03 16:14:08 +05:30
parent 4813bdaa4d
commit 984c679988
7 changed files with 20 additions and 36 deletions

View File

@ -4,6 +4,7 @@ import { inc as semverInc } from 'semver';
import { DateTime } from 'luxon';
import { Registry as LaconicRegistry } from '@cerc-io/registry-sdk';
import { Util } from '@cerc-io/registry-sdk/src/util';
import { RegistryConfig } from './config';
import {
@ -13,7 +14,7 @@ import {
ApplicationDeploymentRemovalRequest
} from './entity/Deployment';
import { AppDeploymentRecord, AppDeploymentRemovalRecord, PackageJSON } from './types';
import { parseGasAndFees, sleep } from './utils';
import { sleep } from './utils';
const log = debug('snowball:registry');
@ -100,7 +101,7 @@ export class Registry {
...(packageJSON.version && { app_version: packageJSON.version })
};
const fee = parseGasAndFees(this.registryConfig.fee.gas, this.registryConfig.fee.fees);
const fee = Util.parseGasAndFees(this.registryConfig.fee.gas, this.registryConfig.fee.fees);
const result = await this.registry.setRecord(
{
@ -192,7 +193,7 @@ export class Registry {
await sleep(SLEEP_DURATION);
const fee = parseGasAndFees(this.registryConfig.fee.gas, this.registryConfig.fee.fees);
const fee = Util.parseGasAndFees(this.registryConfig.fee.gas, this.registryConfig.fee.fees);
const result = await this.registry.setRecord(
{
@ -286,7 +287,7 @@ export class Registry {
deployment: data.deploymentId
};
const fee = parseGasAndFees(this.registryConfig.fee.gas, this.registryConfig.fee.fees);
const fee = Util.parseGasAndFees(this.registryConfig.fee.gas, this.registryConfig.fee.fees);
const result = await this.registry.setRecord(
{

View File

@ -80,23 +80,3 @@ export const loadAndSaveData = async <Entity extends ObjectLiteral>(
export const sleep = async (ms: number): Promise<void> =>
new Promise((resolve) => setTimeout(resolve, ms));
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)
};
};

View File

@ -1,8 +1,9 @@
import debug from 'debug';
import { Registry } from '@cerc-io/registry-sdk';
import { Util } from '@cerc-io/registry-sdk/src/util';
import { getConfig, parseGasAndFees } from '../src/utils';
import { getConfig } from '../src/utils';
const log = debug('snowball:initialize-registry');
@ -20,7 +21,7 @@ async function main () {
const bondId = await registry.getNextBondId(registryConfig.privateKey);
log('bondId:', bondId);
const fee = parseGasAndFees(registryConfig.fee.gas, registryConfig.fee.fees);
const fee = Util.parseGasAndFees(registryConfig.fee.gas, registryConfig.fee.fees);
await registry.createBond(
{ denom: DENOM, amount: BOND_AMOUNT },

View File

@ -3,8 +3,9 @@ import { DataSource } from 'typeorm';
import path from 'path';
import { Registry } from '@cerc-io/registry-sdk';
import { Util } from '@cerc-io/registry-sdk/src/util';
import { getConfig, parseGasAndFees } from '../src/utils';
import { getConfig } from '../src/utils';
import { Deployment, DeploymentStatus, Environment } from '../src/entity/Deployment';
const log = debug('snowball:publish-deploy-records');
@ -59,7 +60,7 @@ async function main() {
url
};
const fee = parseGasAndFees(registryConfig.fee.gas, registryConfig.fee.fees);
const fee = Util.parseGasAndFees(registryConfig.fee.gas, registryConfig.fee.fees);
const result = await registry.setRecord(
{

View File

@ -3,8 +3,9 @@ import { DataSource } from 'typeorm';
import path from 'path';
import { Registry } from '@cerc-io/registry-sdk';
import { Util } from '@cerc-io/registry-sdk/src/util';
import { getConfig, parseGasAndFees } from '../src/utils';
import { getConfig } from '../src/utils';
import { Deployment, DeploymentStatus } from '../src/entity/Deployment';
const log = debug('snowball:publish-deployment-removal-records');
@ -45,7 +46,7 @@ async function main () {
request: deployment.applicationDeploymentRemovalRequestId,
}
const fee = parseGasAndFees(registryConfig.fee.gas, registryConfig.fee.fees);
const fee = Util.parseGasAndFees(registryConfig.fee.gas, registryConfig.fee.fees);
const result = await registry.setRecord(
{

View File

@ -5,6 +5,6 @@ services:
userKey: 87d00f66a73e2ca428adeb49ba9164d0ad9a87edc60e33d46ad3031b9c5701fe
bondId: 89c75c7bc5759861d10285aff6f9e7227d6855e446b77ad5d8324822dfec7deb
chainId: laconic_9000-1
gas: 200000
fees: 200000alnt
gasPrice:
gas:
fees:
gasPrice: 1

View File

@ -5,6 +5,6 @@ services:
userKey: 489c9dd3931c2a2d4dd77973302dc5eb01e2a49552f9d932c58d9da823512311
bondId: 99c0e9aec0ac1b8187faa579be3b54f93fafb6060ac1fd29170b860df605be32
chainId: laconic_9000-1
gas: 200000
fees: 200000alnt
gasPrice:
gas:
fees:
gasPrice: 1