@injectivelabs/wallet-core 1.19.18 → 1.19.20
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 +45 -42
- package/dist/cjs/index.d.cts +6 -6
- package/dist/esm/index.d.ts +6 -6
- package/dist/esm/index.js +45 -42
- package/package.json +7 -7
package/dist/cjs/index.cjs
CHANGED
|
@@ -373,8 +373,9 @@ var MsgBroadcaster = class {
|
|
|
373
373
|
* @param privateKey Taker (autosign) private key — hex, with or without `0x`
|
|
374
374
|
* @returns transaction response with txHash
|
|
375
375
|
*/
|
|
376
|
-
async broadcastWithFeePayerSig({ tx,
|
|
377
|
-
const { chainId, endpoints, walletStrategy
|
|
376
|
+
async broadcastWithFeePayerSig({ tx, privateKey, feePayerSig, accountNumber, txTimeoutInBlocks: txTimeoutInBlocksParam }) {
|
|
377
|
+
const { chainId, endpoints, walletStrategy } = this;
|
|
378
|
+
const txTimeoutInBlocks = this.resolveTimeoutInBlocks(txTimeoutInBlocksParam);
|
|
378
379
|
const pk = __injectivelabs_sdk_ts_core_accounts.PrivateKey.fromHex(privateKey);
|
|
379
380
|
if (__injectivelabs_sdk_ts_utils.ofacList.includes(pk.toHex().toLowerCase())) throw new __injectivelabs_exceptions.GeneralException(/* @__PURE__ */ new Error("You cannot execute this transaction"));
|
|
380
381
|
const txBytes = typeof tx === "string" ? (0, __injectivelabs_sdk_ts_utils.base64ToUint8Array)(tx) : tx;
|
|
@@ -393,8 +394,10 @@ var MsgBroadcaster = class {
|
|
|
393
394
|
txRaw.signatures = [takerSig, feePayerSig.startsWith("0x") ? (0, __injectivelabs_sdk_ts_utils.hexToUint8Array)(feePayerSig.slice(2)) : (0, __injectivelabs_sdk_ts_utils.base64ToUint8Array)(feePayerSig)];
|
|
394
395
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
395
396
|
const txResponse = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).broadcast(txRaw, {
|
|
396
|
-
|
|
397
|
-
|
|
397
|
+
txTimeout: txTimeoutInBlocks,
|
|
398
|
+
onBroadcast: () => {
|
|
399
|
+
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
400
|
+
}
|
|
398
401
|
});
|
|
399
402
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
400
403
|
if (txResponse.code !== 0) throw new __injectivelabs_exceptions.TransactionException(/* @__PURE__ */ new Error(`Transaction failed - ${txResponse.rawLog} - ${txResponse.txHash}`), {
|
|
@@ -410,6 +413,9 @@ var MsgBroadcaster = class {
|
|
|
410
413
|
throw new __injectivelabs_exceptions.TransactionException(new Error(error));
|
|
411
414
|
}
|
|
412
415
|
}
|
|
416
|
+
resolveTimeoutInBlocks(override) {
|
|
417
|
+
return typeof override === "number" && Number.isInteger(override) && override > 0 ? override : this.txTimeout;
|
|
418
|
+
}
|
|
413
419
|
/**
|
|
414
420
|
* Prepare/sign/broadcast transaction using
|
|
415
421
|
* Ethereum native wallets on the client side.
|
|
@@ -421,7 +427,8 @@ var MsgBroadcaster = class {
|
|
|
421
427
|
*/
|
|
422
428
|
async broadcastEip712(tx) {
|
|
423
429
|
var _tx$gas, _baseAccount$pubKey;
|
|
424
|
-
const { chainId, endpoints, walletStrategy
|
|
430
|
+
const { chainId, endpoints, walletStrategy } = this;
|
|
431
|
+
const txTimeoutInBlocks = this.resolveTimeoutInBlocks(tx.txTimeoutInBlocks);
|
|
425
432
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
426
433
|
const [evmChainId, { baseAccount, latestHeight }] = await Promise.all([this.getEvmChainId(), this.fetchAccountAndBlockDetails(tx.injectiveAddress, tx.accountDetails)]);
|
|
427
434
|
if (!evmChainId) throw new __injectivelabs_exceptions.GeneralException(/* @__PURE__ */ new Error("Please provide evmChainId"));
|
|
@@ -496,9 +503,10 @@ var MsgBroadcaster = class {
|
|
|
496
503
|
txTimeout: txTimeoutInBlocks,
|
|
497
504
|
address: tx.injectiveAddress
|
|
498
505
|
});
|
|
506
|
+
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
507
|
+
const confirmedTx = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
499
508
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
500
|
-
|
|
501
|
-
return await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
509
|
+
return confirmedTx;
|
|
502
510
|
}
|
|
503
511
|
/**
|
|
504
512
|
* Prepare/sign/broadcast transaction using
|
|
@@ -511,7 +519,8 @@ var MsgBroadcaster = class {
|
|
|
511
519
|
*/
|
|
512
520
|
async broadcastEip712V2(tx) {
|
|
513
521
|
var _tx$gas2, _baseAccount$pubKey2;
|
|
514
|
-
const { chainId, endpoints, walletStrategy
|
|
522
|
+
const { chainId, endpoints, walletStrategy } = this;
|
|
523
|
+
const txTimeoutInBlocks = this.resolveTimeoutInBlocks(tx.txTimeoutInBlocks);
|
|
515
524
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
516
525
|
const [evmChainId, { baseAccount, latestHeight }] = await Promise.all([this.getEvmChainId(), this.fetchAccountAndBlockDetails(tx.injectiveAddress, tx.accountDetails)]);
|
|
517
526
|
if (!evmChainId) throw new __injectivelabs_exceptions.GeneralException(/* @__PURE__ */ new Error("Please provide evmChainId"));
|
|
@@ -588,9 +597,10 @@ var MsgBroadcaster = class {
|
|
|
588
597
|
txTimeout: txTimeoutInBlocks,
|
|
589
598
|
address: tx.injectiveAddress
|
|
590
599
|
});
|
|
600
|
+
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
601
|
+
const confirmedTx = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
591
602
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
592
|
-
|
|
593
|
-
return await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
603
|
+
return confirmedTx;
|
|
594
604
|
}
|
|
595
605
|
/**
|
|
596
606
|
* Prepare/sign/broadcast transaction using
|
|
@@ -600,7 +610,8 @@ var MsgBroadcaster = class {
|
|
|
600
610
|
* @returns transaction hash
|
|
601
611
|
*/
|
|
602
612
|
async broadcastEip712WithFeeDelegation(tx) {
|
|
603
|
-
const { endpoints, simulateTx, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation
|
|
613
|
+
const { endpoints, simulateTx, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation } = this;
|
|
614
|
+
const txTimeoutInBlocks = this.resolveTimeoutInBlocks(tx.txTimeoutInBlocks);
|
|
604
615
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
605
616
|
const web3Msgs = msgs.map((msg) => msg.toWeb3());
|
|
606
617
|
const evmChainId = await this.getEvmChainId();
|
|
@@ -632,18 +643,10 @@ var MsgBroadcaster = class {
|
|
|
632
643
|
try {
|
|
633
644
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
634
645
|
const response = await broadcast();
|
|
646
|
+
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
647
|
+
const confirmedTx = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
635
648
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
636
|
-
|
|
637
|
-
txHash: response.txHash,
|
|
638
|
-
height: Number(response.height),
|
|
639
|
-
codespace: response.codespace,
|
|
640
|
-
code: response.code,
|
|
641
|
-
rawLog: response.rawLog,
|
|
642
|
-
timestamp: response.timestamp,
|
|
643
|
-
gasWanted: 0,
|
|
644
|
-
gasUsed: 0
|
|
645
|
-
};
|
|
646
|
-
return await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
649
|
+
return confirmedTx;
|
|
647
650
|
} catch (e) {
|
|
648
651
|
const error = e;
|
|
649
652
|
if ((0, __injectivelabs_exceptions.isThrownException)(error)) {
|
|
@@ -673,7 +676,8 @@ var MsgBroadcaster = class {
|
|
|
673
676
|
*/
|
|
674
677
|
async broadcastDirectSign(tx) {
|
|
675
678
|
var _tx$gas3;
|
|
676
|
-
const { chainId, endpoints, walletStrategy
|
|
679
|
+
const { chainId, endpoints, walletStrategy } = this;
|
|
680
|
+
const txTimeoutInBlocks = this.resolveTimeoutInBlocks(tx.txTimeoutInBlocks);
|
|
677
681
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
678
682
|
/**
|
|
679
683
|
* When using Ledger with Keplr/Leap we have
|
|
@@ -728,9 +732,10 @@ var MsgBroadcaster = class {
|
|
|
728
732
|
address: tx.injectiveAddress,
|
|
729
733
|
txTimeout: txTimeoutInBlocks
|
|
730
734
|
});
|
|
735
|
+
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
736
|
+
const confirmedTx$1 = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).fetchTxPoll(response$1.txHash, txTimeoutTimeInMilliSeconds);
|
|
731
737
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
732
|
-
|
|
733
|
-
return await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).fetchTxPoll(response$1.txHash, txTimeoutTimeInMilliSeconds);
|
|
738
|
+
return confirmedTx$1;
|
|
734
739
|
}
|
|
735
740
|
const directSignResponse = await walletStrategy.signCosmosTransaction({
|
|
736
741
|
txRaw,
|
|
@@ -745,9 +750,10 @@ var MsgBroadcaster = class {
|
|
|
745
750
|
txTimeout: txTimeoutInBlocks,
|
|
746
751
|
address: tx.injectiveAddress
|
|
747
752
|
});
|
|
753
|
+
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
754
|
+
const confirmedTx = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
748
755
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
749
|
-
|
|
750
|
-
return await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
756
|
+
return confirmedTx;
|
|
751
757
|
}
|
|
752
758
|
/**
|
|
753
759
|
* We use this method only when we want to broadcast a transaction using Ledger on Keplr/Leap for Injective
|
|
@@ -757,7 +763,8 @@ var MsgBroadcaster = class {
|
|
|
757
763
|
*/
|
|
758
764
|
async experimentalBroadcastWalletThroughLedger(tx) {
|
|
759
765
|
var _tx$gas5, _tx$gas6;
|
|
760
|
-
const { chainId, endpoints, evmChainId, simulateTx, walletStrategy
|
|
766
|
+
const { chainId, endpoints, evmChainId, simulateTx, walletStrategy } = this;
|
|
767
|
+
const txTimeoutInBlocks = this.resolveTimeoutInBlocks(tx.txTimeoutInBlocks);
|
|
761
768
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
762
769
|
/**
|
|
763
770
|
* We can only use this method
|
|
@@ -820,13 +827,16 @@ var MsgBroadcaster = class {
|
|
|
820
827
|
/** Broadcast the transaction */
|
|
821
828
|
const response = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).broadcast(txRawEip712, {
|
|
822
829
|
txTimeout: txTimeoutInBlocks,
|
|
823
|
-
|
|
830
|
+
onBroadcast: () => {
|
|
831
|
+
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
832
|
+
}
|
|
824
833
|
});
|
|
825
834
|
if (response.code !== 0) throw new __injectivelabs_exceptions.TransactionException(new Error(response.rawLog), {
|
|
826
835
|
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
827
836
|
contextCode: response.code,
|
|
828
837
|
contextModule: response.codespace
|
|
829
838
|
});
|
|
839
|
+
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
830
840
|
return response;
|
|
831
841
|
}
|
|
832
842
|
/**
|
|
@@ -838,7 +848,8 @@ var MsgBroadcaster = class {
|
|
|
838
848
|
*/
|
|
839
849
|
async broadcastDirectSignWithFeeDelegation(tx) {
|
|
840
850
|
var _tx$gas7;
|
|
841
|
-
const { options, chainId, endpoints, simulateTx, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation
|
|
851
|
+
const { options, chainId, endpoints, simulateTx, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation } = this;
|
|
852
|
+
const txTimeoutInBlocks = this.resolveTimeoutInBlocks(tx.txTimeoutInBlocks);
|
|
842
853
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
843
854
|
/**
|
|
844
855
|
* We can only use this method when Keplr is connected
|
|
@@ -930,19 +941,11 @@ var MsgBroadcaster = class {
|
|
|
930
941
|
try {
|
|
931
942
|
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
932
943
|
const response = await broadcast();
|
|
933
|
-
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.
|
|
944
|
+
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
934
945
|
if (canDisableCosmosGasCheck && cosmosWallet.enableGasCheck) cosmosWallet.enableGasCheck(chainId);
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
codespace: response.codespace,
|
|
939
|
-
code: response.code,
|
|
940
|
-
rawLog: response.rawLog,
|
|
941
|
-
timestamp: response.timestamp,
|
|
942
|
-
gasWanted: 0,
|
|
943
|
-
gasUsed: 0
|
|
944
|
-
};
|
|
945
|
-
return await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
946
|
+
const confirmedTx = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
947
|
+
walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
948
|
+
return confirmedTx;
|
|
946
949
|
} catch (e) {
|
|
947
950
|
const error = e;
|
|
948
951
|
if ((0, __injectivelabs_exceptions.isThrownException)(error)) {
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -76,12 +76,11 @@ declare class BaseWalletStrategy implements WalletStrategy {
|
|
|
76
76
|
//#region src/broadcaster/types.d.ts
|
|
77
77
|
interface MsgBroadcasterTxOptions {
|
|
78
78
|
memo?: string;
|
|
79
|
+
msgs: Msgs | Msgs[];
|
|
79
80
|
ethereumAddress?: string;
|
|
80
81
|
injectiveAddress?: string;
|
|
81
|
-
msgs: Msgs | Msgs[];
|
|
82
82
|
accountDetails?: AuthBaseAccount;
|
|
83
|
-
|
|
84
|
-
skipPoll?: boolean;
|
|
83
|
+
txTimeoutInBlocks?: number;
|
|
85
84
|
gas?: {
|
|
86
85
|
gasPrice?: string;
|
|
87
86
|
gas?: number; /** gas limit */
|
|
@@ -180,17 +179,18 @@ declare class MsgBroadcaster {
|
|
|
180
179
|
*/
|
|
181
180
|
broadcastWithFeePayerSig({
|
|
182
181
|
tx,
|
|
183
|
-
skipPoll,
|
|
184
182
|
privateKey,
|
|
185
183
|
feePayerSig,
|
|
186
|
-
accountNumber
|
|
184
|
+
accountNumber,
|
|
185
|
+
txTimeoutInBlocks: txTimeoutInBlocksParam
|
|
187
186
|
}: {
|
|
188
187
|
privateKey: string;
|
|
189
|
-
skipPoll?: boolean;
|
|
190
188
|
feePayerSig: string;
|
|
191
189
|
accountNumber: number;
|
|
192
190
|
tx: Uint8Array | string;
|
|
191
|
+
txTimeoutInBlocks?: number;
|
|
193
192
|
}): Promise<TxResponse>;
|
|
193
|
+
private resolveTimeoutInBlocks;
|
|
194
194
|
/**
|
|
195
195
|
* Prepare/sign/broadcast transaction using
|
|
196
196
|
* Ethereum native wallets on the client side.
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -76,12 +76,11 @@ declare class BaseWalletStrategy implements WalletStrategy {
|
|
|
76
76
|
//#region src/broadcaster/types.d.ts
|
|
77
77
|
interface MsgBroadcasterTxOptions {
|
|
78
78
|
memo?: string;
|
|
79
|
+
msgs: Msgs | Msgs[];
|
|
79
80
|
ethereumAddress?: string;
|
|
80
81
|
injectiveAddress?: string;
|
|
81
|
-
msgs: Msgs | Msgs[];
|
|
82
82
|
accountDetails?: AuthBaseAccount;
|
|
83
|
-
|
|
84
|
-
skipPoll?: boolean;
|
|
83
|
+
txTimeoutInBlocks?: number;
|
|
85
84
|
gas?: {
|
|
86
85
|
gasPrice?: string;
|
|
87
86
|
gas?: number; /** gas limit */
|
|
@@ -180,17 +179,18 @@ declare class MsgBroadcaster {
|
|
|
180
179
|
*/
|
|
181
180
|
broadcastWithFeePayerSig({
|
|
182
181
|
tx,
|
|
183
|
-
skipPoll,
|
|
184
182
|
privateKey,
|
|
185
183
|
feePayerSig,
|
|
186
|
-
accountNumber
|
|
184
|
+
accountNumber,
|
|
185
|
+
txTimeoutInBlocks: txTimeoutInBlocksParam
|
|
187
186
|
}: {
|
|
188
187
|
privateKey: string;
|
|
189
|
-
skipPoll?: boolean;
|
|
190
188
|
feePayerSig: string;
|
|
191
189
|
accountNumber: number;
|
|
192
190
|
tx: Uint8Array | string;
|
|
191
|
+
txTimeoutInBlocks?: number;
|
|
193
192
|
}): Promise<TxResponse>;
|
|
193
|
+
private resolveTimeoutInBlocks;
|
|
194
194
|
/**
|
|
195
195
|
* Prepare/sign/broadcast transaction using
|
|
196
196
|
* Ethereum native wallets on the client side.
|
package/dist/esm/index.js
CHANGED
|
@@ -373,8 +373,9 @@ var MsgBroadcaster = class {
|
|
|
373
373
|
* @param privateKey Taker (autosign) private key — hex, with or without `0x`
|
|
374
374
|
* @returns transaction response with txHash
|
|
375
375
|
*/
|
|
376
|
-
async broadcastWithFeePayerSig({ tx,
|
|
377
|
-
const { chainId, endpoints, walletStrategy
|
|
376
|
+
async broadcastWithFeePayerSig({ tx, privateKey, feePayerSig, accountNumber, txTimeoutInBlocks: txTimeoutInBlocksParam }) {
|
|
377
|
+
const { chainId, endpoints, walletStrategy } = this;
|
|
378
|
+
const txTimeoutInBlocks = this.resolveTimeoutInBlocks(txTimeoutInBlocksParam);
|
|
378
379
|
const pk = PrivateKey.fromHex(privateKey);
|
|
379
380
|
if (ofacList.includes(pk.toHex().toLowerCase())) throw new GeneralException(/* @__PURE__ */ new Error("You cannot execute this transaction"));
|
|
380
381
|
const txBytes = typeof tx === "string" ? base64ToUint8Array(tx) : tx;
|
|
@@ -393,8 +394,10 @@ var MsgBroadcaster = class {
|
|
|
393
394
|
txRaw.signatures = [takerSig, feePayerSig.startsWith("0x") ? hexToUint8Array(feePayerSig.slice(2)) : base64ToUint8Array(feePayerSig)];
|
|
394
395
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
395
396
|
const txResponse = await new TxGrpcApi(endpoints.grpc).broadcast(txRaw, {
|
|
396
|
-
|
|
397
|
-
|
|
397
|
+
txTimeout: txTimeoutInBlocks,
|
|
398
|
+
onBroadcast: () => {
|
|
399
|
+
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
400
|
+
}
|
|
398
401
|
});
|
|
399
402
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
400
403
|
if (txResponse.code !== 0) throw new TransactionException(/* @__PURE__ */ new Error(`Transaction failed - ${txResponse.rawLog} - ${txResponse.txHash}`), {
|
|
@@ -410,6 +413,9 @@ var MsgBroadcaster = class {
|
|
|
410
413
|
throw new TransactionException(new Error(error));
|
|
411
414
|
}
|
|
412
415
|
}
|
|
416
|
+
resolveTimeoutInBlocks(override) {
|
|
417
|
+
return typeof override === "number" && Number.isInteger(override) && override > 0 ? override : this.txTimeout;
|
|
418
|
+
}
|
|
413
419
|
/**
|
|
414
420
|
* Prepare/sign/broadcast transaction using
|
|
415
421
|
* Ethereum native wallets on the client side.
|
|
@@ -421,7 +427,8 @@ var MsgBroadcaster = class {
|
|
|
421
427
|
*/
|
|
422
428
|
async broadcastEip712(tx) {
|
|
423
429
|
var _tx$gas, _baseAccount$pubKey;
|
|
424
|
-
const { chainId, endpoints, walletStrategy
|
|
430
|
+
const { chainId, endpoints, walletStrategy } = this;
|
|
431
|
+
const txTimeoutInBlocks = this.resolveTimeoutInBlocks(tx.txTimeoutInBlocks);
|
|
425
432
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
426
433
|
const [evmChainId, { baseAccount, latestHeight }] = await Promise.all([this.getEvmChainId(), this.fetchAccountAndBlockDetails(tx.injectiveAddress, tx.accountDetails)]);
|
|
427
434
|
if (!evmChainId) throw new GeneralException(/* @__PURE__ */ new Error("Please provide evmChainId"));
|
|
@@ -496,9 +503,10 @@ var MsgBroadcaster = class {
|
|
|
496
503
|
txTimeout: txTimeoutInBlocks,
|
|
497
504
|
address: tx.injectiveAddress
|
|
498
505
|
});
|
|
506
|
+
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
507
|
+
const confirmedTx = await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
499
508
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
500
|
-
|
|
501
|
-
return await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
509
|
+
return confirmedTx;
|
|
502
510
|
}
|
|
503
511
|
/**
|
|
504
512
|
* Prepare/sign/broadcast transaction using
|
|
@@ -511,7 +519,8 @@ var MsgBroadcaster = class {
|
|
|
511
519
|
*/
|
|
512
520
|
async broadcastEip712V2(tx) {
|
|
513
521
|
var _tx$gas2, _baseAccount$pubKey2;
|
|
514
|
-
const { chainId, endpoints, walletStrategy
|
|
522
|
+
const { chainId, endpoints, walletStrategy } = this;
|
|
523
|
+
const txTimeoutInBlocks = this.resolveTimeoutInBlocks(tx.txTimeoutInBlocks);
|
|
515
524
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
516
525
|
const [evmChainId, { baseAccount, latestHeight }] = await Promise.all([this.getEvmChainId(), this.fetchAccountAndBlockDetails(tx.injectiveAddress, tx.accountDetails)]);
|
|
517
526
|
if (!evmChainId) throw new GeneralException(/* @__PURE__ */ new Error("Please provide evmChainId"));
|
|
@@ -588,9 +597,10 @@ var MsgBroadcaster = class {
|
|
|
588
597
|
txTimeout: txTimeoutInBlocks,
|
|
589
598
|
address: tx.injectiveAddress
|
|
590
599
|
});
|
|
600
|
+
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
601
|
+
const confirmedTx = await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
591
602
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
592
|
-
|
|
593
|
-
return await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
603
|
+
return confirmedTx;
|
|
594
604
|
}
|
|
595
605
|
/**
|
|
596
606
|
* Prepare/sign/broadcast transaction using
|
|
@@ -600,7 +610,8 @@ var MsgBroadcaster = class {
|
|
|
600
610
|
* @returns transaction hash
|
|
601
611
|
*/
|
|
602
612
|
async broadcastEip712WithFeeDelegation(tx) {
|
|
603
|
-
const { endpoints, simulateTx, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation
|
|
613
|
+
const { endpoints, simulateTx, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation } = this;
|
|
614
|
+
const txTimeoutInBlocks = this.resolveTimeoutInBlocks(tx.txTimeoutInBlocks);
|
|
604
615
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
605
616
|
const web3Msgs = msgs.map((msg) => msg.toWeb3());
|
|
606
617
|
const evmChainId = await this.getEvmChainId();
|
|
@@ -632,18 +643,10 @@ var MsgBroadcaster = class {
|
|
|
632
643
|
try {
|
|
633
644
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
634
645
|
const response = await broadcast();
|
|
646
|
+
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
647
|
+
const confirmedTx = await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
635
648
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
636
|
-
|
|
637
|
-
txHash: response.txHash,
|
|
638
|
-
height: Number(response.height),
|
|
639
|
-
codespace: response.codespace,
|
|
640
|
-
code: response.code,
|
|
641
|
-
rawLog: response.rawLog,
|
|
642
|
-
timestamp: response.timestamp,
|
|
643
|
-
gasWanted: 0,
|
|
644
|
-
gasUsed: 0
|
|
645
|
-
};
|
|
646
|
-
return await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
649
|
+
return confirmedTx;
|
|
647
650
|
} catch (e) {
|
|
648
651
|
const error = e;
|
|
649
652
|
if (isThrownException(error)) {
|
|
@@ -673,7 +676,8 @@ var MsgBroadcaster = class {
|
|
|
673
676
|
*/
|
|
674
677
|
async broadcastDirectSign(tx) {
|
|
675
678
|
var _tx$gas3;
|
|
676
|
-
const { chainId, endpoints, walletStrategy
|
|
679
|
+
const { chainId, endpoints, walletStrategy } = this;
|
|
680
|
+
const txTimeoutInBlocks = this.resolveTimeoutInBlocks(tx.txTimeoutInBlocks);
|
|
677
681
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
678
682
|
/**
|
|
679
683
|
* When using Ledger with Keplr/Leap we have
|
|
@@ -728,9 +732,10 @@ var MsgBroadcaster = class {
|
|
|
728
732
|
address: tx.injectiveAddress,
|
|
729
733
|
txTimeout: txTimeoutInBlocks
|
|
730
734
|
});
|
|
735
|
+
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
736
|
+
const confirmedTx$1 = await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response$1.txHash, txTimeoutTimeInMilliSeconds);
|
|
731
737
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
732
|
-
|
|
733
|
-
return await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response$1.txHash, txTimeoutTimeInMilliSeconds);
|
|
738
|
+
return confirmedTx$1;
|
|
734
739
|
}
|
|
735
740
|
const directSignResponse = await walletStrategy.signCosmosTransaction({
|
|
736
741
|
txRaw,
|
|
@@ -745,9 +750,10 @@ var MsgBroadcaster = class {
|
|
|
745
750
|
txTimeout: txTimeoutInBlocks,
|
|
746
751
|
address: tx.injectiveAddress
|
|
747
752
|
});
|
|
753
|
+
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
754
|
+
const confirmedTx = await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
748
755
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
749
|
-
|
|
750
|
-
return await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
756
|
+
return confirmedTx;
|
|
751
757
|
}
|
|
752
758
|
/**
|
|
753
759
|
* We use this method only when we want to broadcast a transaction using Ledger on Keplr/Leap for Injective
|
|
@@ -757,7 +763,8 @@ var MsgBroadcaster = class {
|
|
|
757
763
|
*/
|
|
758
764
|
async experimentalBroadcastWalletThroughLedger(tx) {
|
|
759
765
|
var _tx$gas5, _tx$gas6;
|
|
760
|
-
const { chainId, endpoints, evmChainId, simulateTx, walletStrategy
|
|
766
|
+
const { chainId, endpoints, evmChainId, simulateTx, walletStrategy } = this;
|
|
767
|
+
const txTimeoutInBlocks = this.resolveTimeoutInBlocks(tx.txTimeoutInBlocks);
|
|
761
768
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
762
769
|
/**
|
|
763
770
|
* We can only use this method
|
|
@@ -820,13 +827,16 @@ var MsgBroadcaster = class {
|
|
|
820
827
|
/** Broadcast the transaction */
|
|
821
828
|
const response = await new TxGrpcApi(endpoints.grpc).broadcast(txRawEip712, {
|
|
822
829
|
txTimeout: txTimeoutInBlocks,
|
|
823
|
-
|
|
830
|
+
onBroadcast: () => {
|
|
831
|
+
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
832
|
+
}
|
|
824
833
|
});
|
|
825
834
|
if (response.code !== 0) throw new TransactionException(new Error(response.rawLog), {
|
|
826
835
|
code: UnspecifiedErrorCode,
|
|
827
836
|
contextCode: response.code,
|
|
828
837
|
contextModule: response.codespace
|
|
829
838
|
});
|
|
839
|
+
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
830
840
|
return response;
|
|
831
841
|
}
|
|
832
842
|
/**
|
|
@@ -838,7 +848,8 @@ var MsgBroadcaster = class {
|
|
|
838
848
|
*/
|
|
839
849
|
async broadcastDirectSignWithFeeDelegation(tx) {
|
|
840
850
|
var _tx$gas7;
|
|
841
|
-
const { options, chainId, endpoints, simulateTx, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation
|
|
851
|
+
const { options, chainId, endpoints, simulateTx, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation } = this;
|
|
852
|
+
const txTimeoutInBlocks = this.resolveTimeoutInBlocks(tx.txTimeoutInBlocks);
|
|
842
853
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
843
854
|
/**
|
|
844
855
|
* We can only use this method when Keplr is connected
|
|
@@ -930,19 +941,11 @@ var MsgBroadcaster = class {
|
|
|
930
941
|
try {
|
|
931
942
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
932
943
|
const response = await broadcast();
|
|
933
|
-
walletStrategy.emit(WalletStrategyEmitterEventType.
|
|
944
|
+
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
|
|
934
945
|
if (canDisableCosmosGasCheck && cosmosWallet.enableGasCheck) cosmosWallet.enableGasCheck(chainId);
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
codespace: response.codespace,
|
|
939
|
-
code: response.code,
|
|
940
|
-
rawLog: response.rawLog,
|
|
941
|
-
timestamp: response.timestamp,
|
|
942
|
-
gasWanted: 0,
|
|
943
|
-
gasUsed: 0
|
|
944
|
-
};
|
|
945
|
-
return await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
946
|
+
const confirmedTx = await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
947
|
+
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
948
|
+
return confirmedTx;
|
|
946
949
|
} catch (e) {
|
|
947
950
|
const error = e;
|
|
948
951
|
if (isThrownException(error)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-core",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.20",
|
|
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/
|
|
49
|
-
"@injectivelabs/
|
|
50
|
-
"@injectivelabs/
|
|
51
|
-
"@injectivelabs/wallet-base": "1.19.
|
|
52
|
-
"@injectivelabs/ts-types": "1.19.
|
|
47
|
+
"@injectivelabs/exceptions": "1.19.20",
|
|
48
|
+
"@injectivelabs/sdk-ts": "1.19.20",
|
|
49
|
+
"@injectivelabs/networks": "1.19.20",
|
|
50
|
+
"@injectivelabs/utils": "1.19.20",
|
|
51
|
+
"@injectivelabs/wallet-base": "1.19.20",
|
|
52
|
+
"@injectivelabs/ts-types": "1.19.20"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|