From 26983dd6512757c3730237130436eba7cef439d4 Mon Sep 17 00:00:00 2001 From: ducphamle2 Date: Wed, 11 May 2022 11:08:24 +0700 Subject: [PATCH] remove redundant params submit --- package.json | 2 +- src/index.d.ts | 2 +- src/index.js | 19 +++++++++---------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index f4d67c9..17ba0ee 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@oraichain/cosmosjs", "licenses": [], - "version": "0.0.90", + "version": "0.0.91", "description": "A JavasSript Open Source Library for Oraichain and possibly many other Cosmos network blockchains as well", "main": "dist/index.js", "repository": { diff --git a/src/index.d.ts b/src/index.d.ts index 6c6a298..403238e 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -40,7 +40,7 @@ declare class Cosmos { signRaw(message: Buffer, privKey: Uint8Array): Uint8Array; sign(bodyBytes: Uint8Array, authInfoBytes: Uint8Array, accountNumber: any, privKey: Uint8Array): Uint8Array; broadcast(signedTxBytes: any, broadCastMode?: BroadCastMode): Promise; - submit(signerOrChild: bip32.BIP32Interface | OfflineDirectSigner, txBody: message.cosmos.tx.v1beta1.TxBody, broadCastMode?: BroadCastMode, fees?: Coin[], gas_limit?: number, gasMultiplier?: number, timeoutHeight?: number, timeoutIntervalCheck?: number): Promise; + submit(signerOrChild: bip32.BIP32Interface | OfflineDirectSigner, txBody: message.cosmos.tx.v1beta1.TxBody, broadCastMode?: BroadCastMode, fees?: Coin[], gas_limit?: number, timeoutIntervalCheck?: number): Promise; simulate(publicKey: Buffer, txBody: message.cosmos.tx.v1beta1.TxBody): Promise; } declare namespace Cosmos { diff --git a/src/index.js b/src/index.js index b39103f..8c82cd3 100644 --- a/src/index.js +++ b/src/index.js @@ -280,7 +280,7 @@ export default class Cosmos { return { address: firstAccount.address, pubkey: firstAccount.pubkey, isChildKey: false }; } - async submit(signerOrChild, txBody, broadCastMode = 'BROADCAST_MODE_SYNC', fees = [{ denom: 'orai', amount: String(0) }], gas_limit = 200000, gasMultiplier = 1.3, timeoutHeight = 0, timeoutIntervalCheck = 5000) { + async submit(signerOrChild, txBody, broadCastMode = 'BROADCAST_MODE_SYNC', fees = [{ denom: 'orai', amount: String(0) }], gas_limit = 200000, timeoutIntervalCheck = 5000) { const { address, pubkey, isChildKey } = await this.walletFactory(signerOrChild); // simple tx body filter if (!txBody) throw { status: CONSTANTS.STATUS_CODE.NOT_FOUND, message: "The txBody object is empty" }; @@ -295,18 +295,17 @@ export default class Cosmos { const bodyBytes = message.cosmos.tx.v1beta1.TxBody.encode(txBody).finish(); const signedTxBytes = isChildKey ? this.sign(bodyBytes, authInfoBytes, data.account.account_number, signerOrChild.privateKey) : await this.signExtension(signerOrChild, address, bodyBytes, authInfoBytes, data.account.account_number); - if (!timeoutHeight || timeoutHeight === 0) { + if (!txBody.timeout_height) { const res = await this.broadcast(signedTxBytes, broadCastMode); return this.handleTxResult(res); - } else { - // use broadcast mode async to collect tx hash - const res = await this.broadcast(signedTxBytes, 'BROADCAST_MODE_SYNC'); - // error that is not related to gas fees - if (res.tx_response.code !== 0) return this.handleTxResult(res); - const txHash = res.tx_response.txhash; - const txResult = await this.handleTxTimeout(txHash, timeoutHeight, timeoutIntervalCheck); - return this.handleTxResult(txResult); } + // use broadcast mode async to collect tx hash + const res = await this.broadcast(signedTxBytes, 'BROADCAST_MODE_SYNC'); + // error that is not related to gas fees + if (res.tx_response.code !== 0) return this.handleTxResult(res); + const txHash = res.tx_response.txhash; + const txResult = await this.handleTxTimeout(txHash, txBody.timeout_height, timeoutIntervalCheck); + return this.handleTxResult(txResult); } handleTxResult(res) {