Skip to content
This repository has been archived by the owner on Dec 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #6 from oraichain/develop
Browse files Browse the repository at this point in the history
remove redundant params submit
  • Loading branch information
ducphamle2 authored May 11, 2022
2 parents 4aa20e8 + 26983dd commit b6a29e1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>;
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<any>;
submit(signerOrChild: bip32.BIP32Interface | OfflineDirectSigner, txBody: message.cosmos.tx.v1beta1.TxBody, broadCastMode?: BroadCastMode, fees?: Coin[], gas_limit?: number, timeoutIntervalCheck?: number): Promise<any>;
simulate(publicKey: Buffer, txBody: message.cosmos.tx.v1beta1.TxBody): Promise<any>;
}
declare namespace Cosmos {
Expand Down
19 changes: 9 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand All @@ -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) {
Expand Down

0 comments on commit b6a29e1

Please sign in to comment.