From d6df729f8553195dda3f8723f56b40610be362fe Mon Sep 17 00:00:00 2001 From: Nabarun Date: Fri, 23 Aug 2024 08:08:32 +0530 Subject: [PATCH] Add option for setting gas price --- src/auction.test.ts | 2 +- src/bond.test.ts | 2 +- src/index.test.ts | 2 +- src/index.ts | 21 +++++++++++++++++---- src/nameservice-expiry.test.ts | 2 +- src/naming.test.ts | 2 +- src/onboarding.test.ts | 4 ++-- src/sdk.test.ts | 2 +- src/util.test.ts | 2 +- 9 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/auction.test.ts b/src/auction.test.ts index 62bd654..4bec436 100644 --- a/src/auction.test.ts +++ b/src/auction.test.ts @@ -16,7 +16,7 @@ const auctionTests = (numBidders = 3) => { beforeAll(async () => { console.log('Running auction tests with num bidders', numBidders); - registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); + registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId }); }); test('Setup bidder accounts', async () => { diff --git a/src/bond.test.ts b/src/bond.test.ts index ce4524c..f59550a 100644 --- a/src/bond.test.ts +++ b/src/bond.test.ts @@ -21,7 +21,7 @@ const bondTests = () => { }; beforeAll(async () => { - registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); + registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId }); }); test('Create bond.', async () => { diff --git a/src/index.test.ts b/src/index.test.ts index c8d006a..e91ae88 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -11,7 +11,7 @@ const registryTests = () => { let registry: Registry; beforeAll(async () => { - registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); + registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId }); }); test('Get account info.', async () => { diff --git a/src/index.ts b/src/index.ts index 17047ff..7a3b776 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ import { sha256 } from 'js-sha256'; -import { DeliverTxResponse, StdFee } from '@cosmjs/stargate'; +import { DeliverTxResponse, StdFee, GasPrice } from '@cosmjs/stargate'; import { RegistryClient } from './registry-client'; import { Account } from './account'; @@ -60,19 +60,26 @@ export const createBid = async (chainId: string, auctionId: string, bidderAddres }; }; +interface RegistryOptions { + chainId?: string + gasPrice?: GasPrice +} + export class Registry { _endpoints: { [key: string]: string }; _chainID: string; _client: RegistryClient; + _gasPrice?: GasPrice; - constructor (gqlUrl: string, rpcUrl = '', chainId: string = DEFAULT_CHAIN_ID) { + constructor (gqlUrl: string, rpcUrl = '', options?: RegistryOptions) { this._endpoints = { rpc: rpcUrl, gql: gqlUrl }; this._client = new RegistryClient(gqlUrl, rpcUrl); - this._chainID = chainId; + this._chainID = options?.chainId ?? DEFAULT_CHAIN_ID; + this._gasPrice = options?.gasPrice; } /** @@ -441,7 +448,13 @@ export class Registry { } async getLaconicClient (account: Account) { - return LaconicClient.connectWithSigner(this._endpoints.rpc, account.wallet); + return LaconicClient.connectWithSigner( + this._endpoints.rpc, + account.wallet, + { + gasPrice: this._gasPrice + } + ); } /** diff --git a/src/nameservice-expiry.test.ts b/src/nameservice-expiry.test.ts index c19de2a..1724cce 100644 --- a/src/nameservice-expiry.test.ts +++ b/src/nameservice-expiry.test.ts @@ -21,7 +21,7 @@ const nameserviceExpiryTests = () => { let recordExpiryTime: Date; beforeAll(async () => { - registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); + registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId }); // Create bond. bondId = await registry.getNextBondId(privateKey); diff --git a/src/naming.test.ts b/src/naming.test.ts index 1bac15b..4d90228 100644 --- a/src/naming.test.ts +++ b/src/naming.test.ts @@ -34,7 +34,7 @@ const namingTests = () => { let account: CosmosAccount; beforeAll(async () => { - registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); + registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId }); // Create bond. bondId = await registry.getNextBondId(privateKey); diff --git a/src/onboarding.test.ts b/src/onboarding.test.ts index 25e6f51..5f882ad 100644 --- a/src/onboarding.test.ts +++ b/src/onboarding.test.ts @@ -20,7 +20,7 @@ const onboardingEnabledTests = () => { let expectedParticipants: Participant[] = []; beforeAll(async () => { - registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); + registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId }); const mnemonic = Account.generateMnemonic(); ethWallet = Wallet.fromMnemonic(mnemonic); @@ -76,7 +76,7 @@ const onboardingDisabledTests = () => { let ethWallet: Wallet; beforeAll(async () => { - registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); + registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId }); }); test('Error on onboarding attempt.', async () => { diff --git a/src/sdk.test.ts b/src/sdk.test.ts index f3217f5..9b13c7f 100644 --- a/src/sdk.test.ts +++ b/src/sdk.test.ts @@ -16,7 +16,7 @@ describe('Querying', () => { let bondId: string; beforeAll(async () => { - registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); + registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId }); bondId = await registry.getNextBondId(privateKey); await registry.createBond({ denom: DENOM, amount: '1000000000' }, privateKey, fee); diff --git a/src/util.test.ts b/src/util.test.ts index 4e198a9..7815e4e 100644 --- a/src/util.test.ts +++ b/src/util.test.ts @@ -19,7 +19,7 @@ const utilTests = () => { let watcherId: string; beforeAll(async () => { - registry = new Registry(gqlEndpoint, rpcEndpoint, chainId); + registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId }); // Create bond. bondId = await registry.getNextBondId(privateKey);