@injectivelabs/wallet-core 1.19.25 → 1.19.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +105 -33
- package/dist/cjs/index.d.cts +11 -1
- package/dist/esm/index.d.ts +11 -1
- package/dist/esm/index.js +106 -34
- package/package.json +7 -7
package/dist/cjs/index.cjs
CHANGED
|
@@ -244,6 +244,7 @@ var MsgBroadcaster = class {
|
|
|
244
244
|
_defineProperty(this, "gasBufferCoefficient", 1.2);
|
|
245
245
|
_defineProperty(this, "retriesOnError", defaultRetriesConfig());
|
|
246
246
|
_defineProperty(this, "httpHeaders", void 0);
|
|
247
|
+
_defineProperty(this, "txInclusion", void 0);
|
|
247
248
|
const networkInfo = (0, __injectivelabs_networks.getNetworkInfo)(options.network);
|
|
248
249
|
this.options = options;
|
|
249
250
|
this.simulateTx = options.simulateTx !== void 0 ? options.simulateTx : true;
|
|
@@ -255,11 +256,13 @@ var MsgBroadcaster = class {
|
|
|
255
256
|
this.endpoints = options.endpoints || (0, __injectivelabs_networks.getNetworkEndpoints)(options.network);
|
|
256
257
|
this.walletStrategy = options.walletStrategy;
|
|
257
258
|
this.httpHeaders = options.httpHeaders;
|
|
259
|
+
this.txInclusion = options.txInclusion;
|
|
258
260
|
}
|
|
259
261
|
setOptions(options) {
|
|
260
262
|
this.simulateTx = options.simulateTx || this.simulateTx;
|
|
261
263
|
this.txTimeout = options.txTimeout || this.txTimeout;
|
|
262
264
|
this.txTimeoutOnFeeDelegation = options.txTimeoutOnFeeDelegation || this.txTimeoutOnFeeDelegation;
|
|
265
|
+
this.txInclusion = options.txInclusion || this.txInclusion;
|
|
263
266
|
}
|
|
264
267
|
async getEvmChainId() {
|
|
265
268
|
const { walletStrategy } = this;
|
|
@@ -373,7 +376,7 @@ var MsgBroadcaster = class {
|
|
|
373
376
|
* @param privateKey Taker (autosign) private key — hex, with or without `0x`
|
|
374
377
|
* @returns transaction response with txHash
|
|
375
378
|
*/
|
|
376
|
-
async broadcastWithFeePayerSig({ tx, privateKey, feePayerSig, accountNumber, txTimeoutInBlocks: txTimeoutInBlocksParam }) {
|
|
379
|
+
async broadcastWithFeePayerSig({ tx, privateKey, feePayerSig, accountNumber, txInclusion, txTimeoutInBlocks: txTimeoutInBlocksParam }) {
|
|
377
380
|
const { chainId, endpoints, walletStrategy } = this;
|
|
378
381
|
const txTimeoutInBlocks = this.resolveTimeoutInBlocks(txTimeoutInBlocksParam);
|
|
379
382
|
const pk = __injectivelabs_sdk_ts_core_accounts.PrivateKey.fromHex(privateKey);
|
|
@@ -395,6 +398,7 @@ var MsgBroadcaster = class {
|
|
|
395
398
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
396
399
|
const txResponse = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).broadcast(txRaw, {
|
|
397
400
|
txTimeout: txTimeoutInBlocks,
|
|
401
|
+
...this.resolveTxInclusionOptions({ txInclusion }),
|
|
398
402
|
onBroadcast: () => {
|
|
399
403
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
400
404
|
}
|
|
@@ -416,6 +420,37 @@ var MsgBroadcaster = class {
|
|
|
416
420
|
resolveTimeoutInBlocks(override) {
|
|
417
421
|
return typeof override === "number" && Number.isInteger(override) && override > 0 ? override : this.txTimeout;
|
|
418
422
|
}
|
|
423
|
+
resolveTxInclusionOptions(tx) {
|
|
424
|
+
var _txInclusion$eventInc;
|
|
425
|
+
const txInclusion = (tx === null || tx === void 0 ? void 0 : tx.txInclusion) || this.txInclusion;
|
|
426
|
+
if (!txInclusion) return;
|
|
427
|
+
return {
|
|
428
|
+
...txInclusion,
|
|
429
|
+
eventInclusion: {
|
|
430
|
+
...txInclusion.eventInclusion,
|
|
431
|
+
rpcEndpoint: ((_txInclusion$eventInc = txInclusion.eventInclusion) === null || _txInclusion$eventInc === void 0 ? void 0 : _txInclusion$eventInc.rpcEndpoint) || this.endpoints.rpc
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
createTxGrpcApi() {
|
|
436
|
+
const client = new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(this.endpoints.grpc);
|
|
437
|
+
if (this.httpHeaders) client.setMetadata(this.httpHeaders);
|
|
438
|
+
return client;
|
|
439
|
+
}
|
|
440
|
+
async waitForTxInclusion(txHash, timeout, tx) {
|
|
441
|
+
return this.createTxGrpcApi().waitForTxInclusion(txHash, timeout, this.resolveTxInclusionOptions(tx));
|
|
442
|
+
}
|
|
443
|
+
async prepareTxInclusionWaiter(txRawOrSignResponse, timeout, tx) {
|
|
444
|
+
const txRaw = (0, __injectivelabs_sdk_ts_core_tx.createTxRawFromSigResponse)(txRawOrSignResponse);
|
|
445
|
+
const txHash = __injectivelabs_sdk_ts_core_tx.TxClient.hash(txRaw);
|
|
446
|
+
return this.createTxGrpcApi().prepareTxInclusionWait(txHash, timeout, this.resolveTxInclusionOptions(tx));
|
|
447
|
+
}
|
|
448
|
+
async waitForPreparedTxInclusion(responseTxHash, timeout, tx, inclusionWaiter) {
|
|
449
|
+
if (!inclusionWaiter) return this.waitForTxInclusion(responseTxHash, timeout, tx);
|
|
450
|
+
const confirmedTx = await inclusionWaiter.wait(responseTxHash);
|
|
451
|
+
if (!confirmedTx) throw new __injectivelabs_exceptions.TransactionException(/* @__PURE__ */ new Error(`The transaction with ${responseTxHash} is not found`));
|
|
452
|
+
return confirmedTx;
|
|
453
|
+
}
|
|
419
454
|
/**
|
|
420
455
|
* Prepare/sign/broadcast transaction using
|
|
421
456
|
* Ethereum native wallets on the client side.
|
|
@@ -497,14 +532,21 @@ var MsgBroadcaster = class {
|
|
|
497
532
|
const txRawEip712 = (0, __injectivelabs_sdk_ts_core_tx.createTxRawEIP712)(txRaw, (0, __injectivelabs_sdk_ts_core_tx.createWeb3Extension)({ evmChainId }));
|
|
498
533
|
/** Append Signatures */
|
|
499
534
|
txRawEip712.signatures = [(0, __injectivelabs_sdk_ts_utils.hexToBuff)(signature)];
|
|
500
|
-
const
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
535
|
+
const inclusionWaiter = await this.prepareTxInclusionWaiter(txRawEip712, txTimeoutTimeInMilliSeconds, tx);
|
|
536
|
+
let response;
|
|
537
|
+
try {
|
|
538
|
+
response = await walletStrategy.sendTransaction(txRawEip712, {
|
|
539
|
+
chainId,
|
|
540
|
+
endpoints,
|
|
541
|
+
txTimeout: txTimeoutInBlocks,
|
|
542
|
+
address: tx.injectiveAddress
|
|
543
|
+
});
|
|
544
|
+
} catch (e) {
|
|
545
|
+
inclusionWaiter.close();
|
|
546
|
+
throw e;
|
|
547
|
+
}
|
|
506
548
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
507
|
-
const confirmedTx = await
|
|
549
|
+
const confirmedTx = await this.waitForPreparedTxInclusion(response.txHash, txTimeoutTimeInMilliSeconds, tx, inclusionWaiter);
|
|
508
550
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
509
551
|
return confirmedTx;
|
|
510
552
|
}
|
|
@@ -591,14 +633,21 @@ var MsgBroadcaster = class {
|
|
|
591
633
|
const txRawEip712 = (0, __injectivelabs_sdk_ts_core_tx.createTxRawEIP712)(txRaw, (0, __injectivelabs_sdk_ts_core_tx.createWeb3Extension)({ evmChainId }));
|
|
592
634
|
/** Append Signatures */
|
|
593
635
|
txRawEip712.signatures = [(0, __injectivelabs_sdk_ts_utils.hexToBuff)(signature)];
|
|
594
|
-
const
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
636
|
+
const inclusionWaiter = await this.prepareTxInclusionWaiter(txRawEip712, txTimeoutTimeInMilliSeconds, tx);
|
|
637
|
+
let response;
|
|
638
|
+
try {
|
|
639
|
+
response = await walletStrategy.sendTransaction(txRawEip712, {
|
|
640
|
+
chainId,
|
|
641
|
+
endpoints,
|
|
642
|
+
txTimeout: txTimeoutInBlocks,
|
|
643
|
+
address: tx.injectiveAddress
|
|
644
|
+
});
|
|
645
|
+
} catch (e) {
|
|
646
|
+
inclusionWaiter.close();
|
|
647
|
+
throw e;
|
|
648
|
+
}
|
|
600
649
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
601
|
-
const confirmedTx = await
|
|
650
|
+
const confirmedTx = await this.waitForPreparedTxInclusion(response.txHash, txTimeoutTimeInMilliSeconds, tx, inclusionWaiter);
|
|
602
651
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
603
652
|
return confirmedTx;
|
|
604
653
|
}
|
|
@@ -644,7 +693,7 @@ var MsgBroadcaster = class {
|
|
|
644
693
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
645
694
|
const response = await broadcast();
|
|
646
695
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
647
|
-
const confirmedTx = await
|
|
696
|
+
const confirmedTx = await this.waitForTxInclusion(response.txHash, txTimeoutTimeInMilliSeconds, tx);
|
|
648
697
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
649
698
|
return confirmedTx;
|
|
650
699
|
} catch (e) {
|
|
@@ -726,14 +775,21 @@ var MsgBroadcaster = class {
|
|
|
726
775
|
address: tx.injectiveAddress
|
|
727
776
|
})).signature.signature)];
|
|
728
777
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
729
|
-
const
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
778
|
+
const inclusionWaiter$1 = await this.prepareTxInclusionWaiter(txRaw, txTimeoutTimeInMilliSeconds, tx);
|
|
779
|
+
let response$1;
|
|
780
|
+
try {
|
|
781
|
+
response$1 = await walletStrategy.sendTransaction(txRaw, {
|
|
782
|
+
chainId,
|
|
783
|
+
endpoints,
|
|
784
|
+
address: tx.injectiveAddress,
|
|
785
|
+
txTimeout: txTimeoutInBlocks
|
|
786
|
+
});
|
|
787
|
+
} catch (e) {
|
|
788
|
+
inclusionWaiter$1.close();
|
|
789
|
+
throw e;
|
|
790
|
+
}
|
|
735
791
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
736
|
-
const confirmedTx$1 = await
|
|
792
|
+
const confirmedTx$1 = await this.waitForPreparedTxInclusion(response$1.txHash, txTimeoutTimeInMilliSeconds, tx, inclusionWaiter$1);
|
|
737
793
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
738
794
|
return confirmedTx$1;
|
|
739
795
|
}
|
|
@@ -744,14 +800,21 @@ var MsgBroadcaster = class {
|
|
|
744
800
|
accountNumber: baseAccount.accountNumber
|
|
745
801
|
});
|
|
746
802
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
747
|
-
const
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
803
|
+
const inclusionWaiter = await this.prepareTxInclusionWaiter(directSignResponse, txTimeoutTimeInMilliSeconds, tx);
|
|
804
|
+
let response;
|
|
805
|
+
try {
|
|
806
|
+
response = await walletStrategy.sendTransaction(directSignResponse, {
|
|
807
|
+
chainId,
|
|
808
|
+
endpoints,
|
|
809
|
+
txTimeout: txTimeoutInBlocks,
|
|
810
|
+
address: tx.injectiveAddress
|
|
811
|
+
});
|
|
812
|
+
} catch (e) {
|
|
813
|
+
inclusionWaiter.close();
|
|
814
|
+
throw e;
|
|
815
|
+
}
|
|
753
816
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
754
|
-
const confirmedTx = await
|
|
817
|
+
const confirmedTx = await this.waitForPreparedTxInclusion(response.txHash, txTimeoutTimeInMilliSeconds, tx, inclusionWaiter);
|
|
755
818
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
756
819
|
return confirmedTx;
|
|
757
820
|
}
|
|
@@ -827,6 +890,7 @@ var MsgBroadcaster = class {
|
|
|
827
890
|
/** Broadcast the transaction */
|
|
828
891
|
const response = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).broadcast(txRawEip712, {
|
|
829
892
|
txTimeout: txTimeoutInBlocks,
|
|
893
|
+
...this.resolveTxInclusionOptions(tx),
|
|
830
894
|
onBroadcast: () => {
|
|
831
895
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
832
896
|
}
|
|
@@ -929,9 +993,10 @@ var MsgBroadcaster = class {
|
|
|
929
993
|
accountNumber: baseAccount.accountNumber
|
|
930
994
|
});
|
|
931
995
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionPreparationEnd);
|
|
996
|
+
const signedTxRaw = (0, __injectivelabs_sdk_ts_core_tx.createTxRawFromSigResponse)(directSignResponse);
|
|
932
997
|
const broadcast = async () => await transactionApi.broadcastCosmosTxRequest({
|
|
933
998
|
address: tx.injectiveAddress,
|
|
934
|
-
txRaw:
|
|
999
|
+
txRaw: signedTxRaw,
|
|
935
1000
|
signature: directSignResponse.signature.signature,
|
|
936
1001
|
pubKey: directSignResponse.signature.pub_key || {
|
|
937
1002
|
value: pubKey,
|
|
@@ -940,10 +1005,17 @@ var MsgBroadcaster = class {
|
|
|
940
1005
|
});
|
|
941
1006
|
try {
|
|
942
1007
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
943
|
-
const
|
|
1008
|
+
const inclusionWaiter = await this.prepareTxInclusionWaiter(signedTxRaw, txTimeoutTimeInMilliSeconds, tx);
|
|
1009
|
+
let response;
|
|
1010
|
+
try {
|
|
1011
|
+
response = await broadcast();
|
|
1012
|
+
} catch (e) {
|
|
1013
|
+
inclusionWaiter.close();
|
|
1014
|
+
throw e;
|
|
1015
|
+
}
|
|
944
1016
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
945
1017
|
if (canDisableCosmosGasCheck && cosmosWallet.enableGasCheck) cosmosWallet.enableGasCheck(chainId);
|
|
946
|
-
const confirmedTx = await
|
|
1018
|
+
const confirmedTx = await this.waitForPreparedTxInclusion(response.txHash, txTimeoutTimeInMilliSeconds, tx, inclusionWaiter);
|
|
947
1019
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
948
1020
|
return confirmedTx;
|
|
949
1021
|
} catch (e) {
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -2,7 +2,7 @@ import { ConcreteStrategiesArg, ConcreteWalletStrategy, CosmosWalletAbstraction,
|
|
|
2
2
|
import { StdSignDoc } from "@keplr-wallet/types";
|
|
3
3
|
import { OfflineSigner } from "@cosmjs/proto-signing";
|
|
4
4
|
import { AccountAddress, ChainId, EvmChainId } from "@injectivelabs/ts-types";
|
|
5
|
-
import { TxResponse } from "@injectivelabs/sdk-ts/core/tx";
|
|
5
|
+
import { TxClientInclusionOptions, TxResponse } from "@injectivelabs/sdk-ts/core/tx";
|
|
6
6
|
import { AminoSignResponse, DirectSignResponse, TxRaw } from "@injectivelabs/sdk-ts/types";
|
|
7
7
|
import { Msgs } from "@injectivelabs/sdk-ts/core/modules";
|
|
8
8
|
import { Network, NetworkEndpoints } from "@injectivelabs/networks";
|
|
@@ -81,6 +81,7 @@ interface MsgBroadcasterTxOptions {
|
|
|
81
81
|
injectiveAddress?: string;
|
|
82
82
|
accountDetails?: AuthBaseAccount;
|
|
83
83
|
txTimeoutInBlocks?: number;
|
|
84
|
+
txInclusion?: TxClientInclusionOptions;
|
|
84
85
|
gas?: {
|
|
85
86
|
gasPrice?: string;
|
|
86
87
|
gas?: number; /** gas limit */
|
|
@@ -101,6 +102,7 @@ interface MsgBroadcasterOptions {
|
|
|
101
102
|
simulateTx?: boolean;
|
|
102
103
|
txTimeoutOnFeeDelegation?: boolean;
|
|
103
104
|
txTimeout?: number;
|
|
105
|
+
txInclusion?: TxClientInclusionOptions;
|
|
104
106
|
walletStrategy: BaseWalletStrategy;
|
|
105
107
|
gasBufferCoefficient?: number;
|
|
106
108
|
httpHeaders?: Record<string, string>;
|
|
@@ -132,6 +134,7 @@ declare class MsgBroadcaster {
|
|
|
132
134
|
};
|
|
133
135
|
};
|
|
134
136
|
httpHeaders?: Record<string, string>;
|
|
137
|
+
txInclusion?: TxClientInclusionOptions;
|
|
135
138
|
constructor(options: MsgBroadcasterOptions);
|
|
136
139
|
setOptions(options: Partial<MsgBroadcasterOptions>): void;
|
|
137
140
|
getEvmChainId(): Promise<EvmChainId | undefined>;
|
|
@@ -182,15 +185,22 @@ declare class MsgBroadcaster {
|
|
|
182
185
|
privateKey,
|
|
183
186
|
feePayerSig,
|
|
184
187
|
accountNumber,
|
|
188
|
+
txInclusion,
|
|
185
189
|
txTimeoutInBlocks: txTimeoutInBlocksParam
|
|
186
190
|
}: {
|
|
187
191
|
privateKey: string;
|
|
188
192
|
feePayerSig: string;
|
|
189
193
|
accountNumber: number;
|
|
190
194
|
tx: Uint8Array | string;
|
|
195
|
+
txInclusion?: TxClientInclusionOptions;
|
|
191
196
|
txTimeoutInBlocks?: number;
|
|
192
197
|
}): Promise<TxResponse>;
|
|
193
198
|
private resolveTimeoutInBlocks;
|
|
199
|
+
private resolveTxInclusionOptions;
|
|
200
|
+
private createTxGrpcApi;
|
|
201
|
+
private waitForTxInclusion;
|
|
202
|
+
private prepareTxInclusionWaiter;
|
|
203
|
+
private waitForPreparedTxInclusion;
|
|
194
204
|
/**
|
|
195
205
|
* Prepare/sign/broadcast transaction using
|
|
196
206
|
* Ethereum native wallets on the client side.
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ConcreteStrategiesArg, ConcreteWalletStrategy, CosmosWalletAbstraction,
|
|
|
2
2
|
import { AccountAddress, ChainId, EvmChainId } from "@injectivelabs/ts-types";
|
|
3
3
|
import { Network, NetworkEndpoints } from "@injectivelabs/networks";
|
|
4
4
|
import { AuthBaseAccount } from "@injectivelabs/sdk-ts/client/chain";
|
|
5
|
-
import { TxResponse } from "@injectivelabs/sdk-ts/core/tx";
|
|
5
|
+
import { TxClientInclusionOptions, TxResponse } from "@injectivelabs/sdk-ts/core/tx";
|
|
6
6
|
import { StdSignDoc } from "@keplr-wallet/types";
|
|
7
7
|
import { OfflineSigner } from "@cosmjs/proto-signing";
|
|
8
8
|
import { AminoSignResponse, DirectSignResponse, TxRaw } from "@injectivelabs/sdk-ts/types";
|
|
@@ -81,6 +81,7 @@ interface MsgBroadcasterTxOptions {
|
|
|
81
81
|
injectiveAddress?: string;
|
|
82
82
|
accountDetails?: AuthBaseAccount;
|
|
83
83
|
txTimeoutInBlocks?: number;
|
|
84
|
+
txInclusion?: TxClientInclusionOptions;
|
|
84
85
|
gas?: {
|
|
85
86
|
gasPrice?: string;
|
|
86
87
|
gas?: number; /** gas limit */
|
|
@@ -101,6 +102,7 @@ interface MsgBroadcasterOptions {
|
|
|
101
102
|
simulateTx?: boolean;
|
|
102
103
|
txTimeoutOnFeeDelegation?: boolean;
|
|
103
104
|
txTimeout?: number;
|
|
105
|
+
txInclusion?: TxClientInclusionOptions;
|
|
104
106
|
walletStrategy: BaseWalletStrategy;
|
|
105
107
|
gasBufferCoefficient?: number;
|
|
106
108
|
httpHeaders?: Record<string, string>;
|
|
@@ -132,6 +134,7 @@ declare class MsgBroadcaster {
|
|
|
132
134
|
};
|
|
133
135
|
};
|
|
134
136
|
httpHeaders?: Record<string, string>;
|
|
137
|
+
txInclusion?: TxClientInclusionOptions;
|
|
135
138
|
constructor(options: MsgBroadcasterOptions);
|
|
136
139
|
setOptions(options: Partial<MsgBroadcasterOptions>): void;
|
|
137
140
|
getEvmChainId(): Promise<EvmChainId | undefined>;
|
|
@@ -182,15 +185,22 @@ declare class MsgBroadcaster {
|
|
|
182
185
|
privateKey,
|
|
183
186
|
feePayerSig,
|
|
184
187
|
accountNumber,
|
|
188
|
+
txInclusion,
|
|
185
189
|
txTimeoutInBlocks: txTimeoutInBlocksParam
|
|
186
190
|
}: {
|
|
187
191
|
privateKey: string;
|
|
188
192
|
feePayerSig: string;
|
|
189
193
|
accountNumber: number;
|
|
190
194
|
tx: Uint8Array | string;
|
|
195
|
+
txInclusion?: TxClientInclusionOptions;
|
|
191
196
|
txTimeoutInBlocks?: number;
|
|
192
197
|
}): Promise<TxResponse>;
|
|
193
198
|
private resolveTimeoutInBlocks;
|
|
199
|
+
private resolveTxInclusionOptions;
|
|
200
|
+
private createTxGrpcApi;
|
|
201
|
+
private waitForTxInclusion;
|
|
202
|
+
private prepareTxInclusionWaiter;
|
|
203
|
+
private waitForPreparedTxInclusion;
|
|
194
204
|
/**
|
|
195
205
|
* Prepare/sign/broadcast transaction using
|
|
196
206
|
* Ethereum native wallets on the client side.
|
package/dist/esm/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { IndexerGrpcWeb3GwApi } from "@injectivelabs/sdk-ts/client/indexer";
|
|
|
8
8
|
import { getNetworkEndpoints, getNetworkInfo, isMainnet, isTestnet } from "@injectivelabs/networks";
|
|
9
9
|
import { ChainGrpcAuthApi, ChainGrpcTendermintApi, ChainGrpcTxFeesApi } from "@injectivelabs/sdk-ts/client/chain";
|
|
10
10
|
import { DEFAULT_BLOCK_TIMEOUT_HEIGHT, DEFAULT_BLOCK_TIME_IN_SECONDS, DEFAULT_GAS_PRICE, getStdFee, sleep, toBigNumber } from "@injectivelabs/utils";
|
|
11
|
-
import { CosmosTxV1Beta1TxPb, SIGN_DIRECT, SIGN_EIP712, SIGN_EIP712_V2, TxGrpcApi, createTransaction, createTransactionWithSigners, createTxRawEIP712, createTxRawFromSigResponse, createWeb3Extension, getAminoStdSignDoc, getEip712TypedData, getEip712TypedDataV2 } from "@injectivelabs/sdk-ts/core/tx";
|
|
11
|
+
import { CosmosTxV1Beta1TxPb, SIGN_DIRECT, SIGN_EIP712, SIGN_EIP712_V2, TxClient, TxGrpcApi, createTransaction, createTransactionWithSigners, createTxRawEIP712, createTxRawFromSigResponse, createWeb3Extension, getAminoStdSignDoc, getEip712TypedData, getEip712TypedDataV2 } from "@injectivelabs/sdk-ts/core/tx";
|
|
12
12
|
|
|
13
13
|
//#region src/utils/tx.ts
|
|
14
14
|
const checkIfTxRunOutOfGas = (e) => {
|
|
@@ -244,6 +244,7 @@ var MsgBroadcaster = class {
|
|
|
244
244
|
_defineProperty(this, "gasBufferCoefficient", 1.2);
|
|
245
245
|
_defineProperty(this, "retriesOnError", defaultRetriesConfig());
|
|
246
246
|
_defineProperty(this, "httpHeaders", void 0);
|
|
247
|
+
_defineProperty(this, "txInclusion", void 0);
|
|
247
248
|
const networkInfo = getNetworkInfo(options.network);
|
|
248
249
|
this.options = options;
|
|
249
250
|
this.simulateTx = options.simulateTx !== void 0 ? options.simulateTx : true;
|
|
@@ -255,11 +256,13 @@ var MsgBroadcaster = class {
|
|
|
255
256
|
this.endpoints = options.endpoints || getNetworkEndpoints(options.network);
|
|
256
257
|
this.walletStrategy = options.walletStrategy;
|
|
257
258
|
this.httpHeaders = options.httpHeaders;
|
|
259
|
+
this.txInclusion = options.txInclusion;
|
|
258
260
|
}
|
|
259
261
|
setOptions(options) {
|
|
260
262
|
this.simulateTx = options.simulateTx || this.simulateTx;
|
|
261
263
|
this.txTimeout = options.txTimeout || this.txTimeout;
|
|
262
264
|
this.txTimeoutOnFeeDelegation = options.txTimeoutOnFeeDelegation || this.txTimeoutOnFeeDelegation;
|
|
265
|
+
this.txInclusion = options.txInclusion || this.txInclusion;
|
|
263
266
|
}
|
|
264
267
|
async getEvmChainId() {
|
|
265
268
|
const { walletStrategy } = this;
|
|
@@ -373,7 +376,7 @@ var MsgBroadcaster = class {
|
|
|
373
376
|
* @param privateKey Taker (autosign) private key — hex, with or without `0x`
|
|
374
377
|
* @returns transaction response with txHash
|
|
375
378
|
*/
|
|
376
|
-
async broadcastWithFeePayerSig({ tx, privateKey, feePayerSig, accountNumber, txTimeoutInBlocks: txTimeoutInBlocksParam }) {
|
|
379
|
+
async broadcastWithFeePayerSig({ tx, privateKey, feePayerSig, accountNumber, txInclusion, txTimeoutInBlocks: txTimeoutInBlocksParam }) {
|
|
377
380
|
const { chainId, endpoints, walletStrategy } = this;
|
|
378
381
|
const txTimeoutInBlocks = this.resolveTimeoutInBlocks(txTimeoutInBlocksParam);
|
|
379
382
|
const pk = PrivateKey.fromHex(privateKey);
|
|
@@ -395,6 +398,7 @@ var MsgBroadcaster = class {
|
|
|
395
398
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
396
399
|
const txResponse = await new TxGrpcApi(endpoints.grpc).broadcast(txRaw, {
|
|
397
400
|
txTimeout: txTimeoutInBlocks,
|
|
401
|
+
...this.resolveTxInclusionOptions({ txInclusion }),
|
|
398
402
|
onBroadcast: () => {
|
|
399
403
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
400
404
|
}
|
|
@@ -416,6 +420,37 @@ var MsgBroadcaster = class {
|
|
|
416
420
|
resolveTimeoutInBlocks(override) {
|
|
417
421
|
return typeof override === "number" && Number.isInteger(override) && override > 0 ? override : this.txTimeout;
|
|
418
422
|
}
|
|
423
|
+
resolveTxInclusionOptions(tx) {
|
|
424
|
+
var _txInclusion$eventInc;
|
|
425
|
+
const txInclusion = (tx === null || tx === void 0 ? void 0 : tx.txInclusion) || this.txInclusion;
|
|
426
|
+
if (!txInclusion) return;
|
|
427
|
+
return {
|
|
428
|
+
...txInclusion,
|
|
429
|
+
eventInclusion: {
|
|
430
|
+
...txInclusion.eventInclusion,
|
|
431
|
+
rpcEndpoint: ((_txInclusion$eventInc = txInclusion.eventInclusion) === null || _txInclusion$eventInc === void 0 ? void 0 : _txInclusion$eventInc.rpcEndpoint) || this.endpoints.rpc
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
createTxGrpcApi() {
|
|
436
|
+
const client = new TxGrpcApi(this.endpoints.grpc);
|
|
437
|
+
if (this.httpHeaders) client.setMetadata(this.httpHeaders);
|
|
438
|
+
return client;
|
|
439
|
+
}
|
|
440
|
+
async waitForTxInclusion(txHash, timeout, tx) {
|
|
441
|
+
return this.createTxGrpcApi().waitForTxInclusion(txHash, timeout, this.resolveTxInclusionOptions(tx));
|
|
442
|
+
}
|
|
443
|
+
async prepareTxInclusionWaiter(txRawOrSignResponse, timeout, tx) {
|
|
444
|
+
const txRaw = createTxRawFromSigResponse(txRawOrSignResponse);
|
|
445
|
+
const txHash = TxClient.hash(txRaw);
|
|
446
|
+
return this.createTxGrpcApi().prepareTxInclusionWait(txHash, timeout, this.resolveTxInclusionOptions(tx));
|
|
447
|
+
}
|
|
448
|
+
async waitForPreparedTxInclusion(responseTxHash, timeout, tx, inclusionWaiter) {
|
|
449
|
+
if (!inclusionWaiter) return this.waitForTxInclusion(responseTxHash, timeout, tx);
|
|
450
|
+
const confirmedTx = await inclusionWaiter.wait(responseTxHash);
|
|
451
|
+
if (!confirmedTx) throw new TransactionException(/* @__PURE__ */ new Error(`The transaction with ${responseTxHash} is not found`));
|
|
452
|
+
return confirmedTx;
|
|
453
|
+
}
|
|
419
454
|
/**
|
|
420
455
|
* Prepare/sign/broadcast transaction using
|
|
421
456
|
* Ethereum native wallets on the client side.
|
|
@@ -497,14 +532,21 @@ var MsgBroadcaster = class {
|
|
|
497
532
|
const txRawEip712 = createTxRawEIP712(txRaw, createWeb3Extension({ evmChainId }));
|
|
498
533
|
/** Append Signatures */
|
|
499
534
|
txRawEip712.signatures = [hexToBuff(signature)];
|
|
500
|
-
const
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
535
|
+
const inclusionWaiter = await this.prepareTxInclusionWaiter(txRawEip712, txTimeoutTimeInMilliSeconds, tx);
|
|
536
|
+
let response;
|
|
537
|
+
try {
|
|
538
|
+
response = await walletStrategy.sendTransaction(txRawEip712, {
|
|
539
|
+
chainId,
|
|
540
|
+
endpoints,
|
|
541
|
+
txTimeout: txTimeoutInBlocks,
|
|
542
|
+
address: tx.injectiveAddress
|
|
543
|
+
});
|
|
544
|
+
} catch (e) {
|
|
545
|
+
inclusionWaiter.close();
|
|
546
|
+
throw e;
|
|
547
|
+
}
|
|
506
548
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
507
|
-
const confirmedTx = await
|
|
549
|
+
const confirmedTx = await this.waitForPreparedTxInclusion(response.txHash, txTimeoutTimeInMilliSeconds, tx, inclusionWaiter);
|
|
508
550
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
509
551
|
return confirmedTx;
|
|
510
552
|
}
|
|
@@ -591,14 +633,21 @@ var MsgBroadcaster = class {
|
|
|
591
633
|
const txRawEip712 = createTxRawEIP712(txRaw, createWeb3Extension({ evmChainId }));
|
|
592
634
|
/** Append Signatures */
|
|
593
635
|
txRawEip712.signatures = [hexToBuff(signature)];
|
|
594
|
-
const
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
636
|
+
const inclusionWaiter = await this.prepareTxInclusionWaiter(txRawEip712, txTimeoutTimeInMilliSeconds, tx);
|
|
637
|
+
let response;
|
|
638
|
+
try {
|
|
639
|
+
response = await walletStrategy.sendTransaction(txRawEip712, {
|
|
640
|
+
chainId,
|
|
641
|
+
endpoints,
|
|
642
|
+
txTimeout: txTimeoutInBlocks,
|
|
643
|
+
address: tx.injectiveAddress
|
|
644
|
+
});
|
|
645
|
+
} catch (e) {
|
|
646
|
+
inclusionWaiter.close();
|
|
647
|
+
throw e;
|
|
648
|
+
}
|
|
600
649
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
601
|
-
const confirmedTx = await
|
|
650
|
+
const confirmedTx = await this.waitForPreparedTxInclusion(response.txHash, txTimeoutTimeInMilliSeconds, tx, inclusionWaiter);
|
|
602
651
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
603
652
|
return confirmedTx;
|
|
604
653
|
}
|
|
@@ -644,7 +693,7 @@ var MsgBroadcaster = class {
|
|
|
644
693
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
645
694
|
const response = await broadcast();
|
|
646
695
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
647
|
-
const confirmedTx = await
|
|
696
|
+
const confirmedTx = await this.waitForTxInclusion(response.txHash, txTimeoutTimeInMilliSeconds, tx);
|
|
648
697
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
649
698
|
return confirmedTx;
|
|
650
699
|
} catch (e) {
|
|
@@ -726,14 +775,21 @@ var MsgBroadcaster = class {
|
|
|
726
775
|
address: tx.injectiveAddress
|
|
727
776
|
})).signature.signature)];
|
|
728
777
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
729
|
-
const
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
778
|
+
const inclusionWaiter$1 = await this.prepareTxInclusionWaiter(txRaw, txTimeoutTimeInMilliSeconds, tx);
|
|
779
|
+
let response$1;
|
|
780
|
+
try {
|
|
781
|
+
response$1 = await walletStrategy.sendTransaction(txRaw, {
|
|
782
|
+
chainId,
|
|
783
|
+
endpoints,
|
|
784
|
+
address: tx.injectiveAddress,
|
|
785
|
+
txTimeout: txTimeoutInBlocks
|
|
786
|
+
});
|
|
787
|
+
} catch (e) {
|
|
788
|
+
inclusionWaiter$1.close();
|
|
789
|
+
throw e;
|
|
790
|
+
}
|
|
735
791
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
736
|
-
const confirmedTx$1 = await
|
|
792
|
+
const confirmedTx$1 = await this.waitForPreparedTxInclusion(response$1.txHash, txTimeoutTimeInMilliSeconds, tx, inclusionWaiter$1);
|
|
737
793
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
738
794
|
return confirmedTx$1;
|
|
739
795
|
}
|
|
@@ -744,14 +800,21 @@ var MsgBroadcaster = class {
|
|
|
744
800
|
accountNumber: baseAccount.accountNumber
|
|
745
801
|
});
|
|
746
802
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
747
|
-
const
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
803
|
+
const inclusionWaiter = await this.prepareTxInclusionWaiter(directSignResponse, txTimeoutTimeInMilliSeconds, tx);
|
|
804
|
+
let response;
|
|
805
|
+
try {
|
|
806
|
+
response = await walletStrategy.sendTransaction(directSignResponse, {
|
|
807
|
+
chainId,
|
|
808
|
+
endpoints,
|
|
809
|
+
txTimeout: txTimeoutInBlocks,
|
|
810
|
+
address: tx.injectiveAddress
|
|
811
|
+
});
|
|
812
|
+
} catch (e) {
|
|
813
|
+
inclusionWaiter.close();
|
|
814
|
+
throw e;
|
|
815
|
+
}
|
|
753
816
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
754
|
-
const confirmedTx = await
|
|
817
|
+
const confirmedTx = await this.waitForPreparedTxInclusion(response.txHash, txTimeoutTimeInMilliSeconds, tx, inclusionWaiter);
|
|
755
818
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
756
819
|
return confirmedTx;
|
|
757
820
|
}
|
|
@@ -827,6 +890,7 @@ var MsgBroadcaster = class {
|
|
|
827
890
|
/** Broadcast the transaction */
|
|
828
891
|
const response = await new TxGrpcApi(endpoints.grpc).broadcast(txRawEip712, {
|
|
829
892
|
txTimeout: txTimeoutInBlocks,
|
|
893
|
+
...this.resolveTxInclusionOptions(tx),
|
|
830
894
|
onBroadcast: () => {
|
|
831
895
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
832
896
|
}
|
|
@@ -929,9 +993,10 @@ var MsgBroadcaster = class {
|
|
|
929
993
|
accountNumber: baseAccount.accountNumber
|
|
930
994
|
});
|
|
931
995
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionPreparationEnd);
|
|
996
|
+
const signedTxRaw = createTxRawFromSigResponse(directSignResponse);
|
|
932
997
|
const broadcast = async () => await transactionApi.broadcastCosmosTxRequest({
|
|
933
998
|
address: tx.injectiveAddress,
|
|
934
|
-
txRaw:
|
|
999
|
+
txRaw: signedTxRaw,
|
|
935
1000
|
signature: directSignResponse.signature.signature,
|
|
936
1001
|
pubKey: directSignResponse.signature.pub_key || {
|
|
937
1002
|
value: pubKey,
|
|
@@ -940,10 +1005,17 @@ var MsgBroadcaster = class {
|
|
|
940
1005
|
});
|
|
941
1006
|
try {
|
|
942
1007
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
943
|
-
const
|
|
1008
|
+
const inclusionWaiter = await this.prepareTxInclusionWaiter(signedTxRaw, txTimeoutTimeInMilliSeconds, tx);
|
|
1009
|
+
let response;
|
|
1010
|
+
try {
|
|
1011
|
+
response = await broadcast();
|
|
1012
|
+
} catch (e) {
|
|
1013
|
+
inclusionWaiter.close();
|
|
1014
|
+
throw e;
|
|
1015
|
+
}
|
|
944
1016
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
945
1017
|
if (canDisableCosmosGasCheck && cosmosWallet.enableGasCheck) cosmosWallet.enableGasCheck(chainId);
|
|
946
|
-
const confirmedTx = await
|
|
1018
|
+
const confirmedTx = await this.waitForPreparedTxInclusion(response.txHash, txTimeoutTimeInMilliSeconds, tx, inclusionWaiter);
|
|
947
1019
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
948
1020
|
return confirmedTx;
|
|
949
1021
|
} catch (e) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-core",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.27",
|
|
4
4
|
"description": "Core wallet strategy",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@keplr-wallet/types": "^0.12.296",
|
|
46
46
|
"eventemitter3": "^5.0.1",
|
|
47
|
-
"@injectivelabs/exceptions": "1.19.
|
|
48
|
-
"@injectivelabs/networks": "1.19.
|
|
49
|
-
"@injectivelabs/sdk-ts": "1.19.
|
|
50
|
-
"@injectivelabs/
|
|
51
|
-
"@injectivelabs/utils": "1.19.
|
|
52
|
-
"@injectivelabs/
|
|
47
|
+
"@injectivelabs/exceptions": "1.19.27",
|
|
48
|
+
"@injectivelabs/networks": "1.19.27",
|
|
49
|
+
"@injectivelabs/sdk-ts": "1.19.27",
|
|
50
|
+
"@injectivelabs/ts-types": "1.19.27",
|
|
51
|
+
"@injectivelabs/utils": "1.19.27",
|
|
52
|
+
"@injectivelabs/wallet-base": "1.19.27"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|