@injectivelabs/sdk-ts 1.15.2 → 1.15.4

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.
@@ -7,5 +7,6 @@ export declare class ChainGrpcTendermintApi extends BaseGrpcConsumer {
7
7
  protected module: string;
8
8
  protected client: CosmosBaseTendermintV1Beta1Query.ServiceClientImpl;
9
9
  constructor(endpoint: string);
10
- fetchLatestBlock(): Promise<import("@injectivelabs/core-proto-ts/cjs/tendermint/types/block.js").Block | import("@injectivelabs/core-proto-ts/cjs/cosmos/base/tendermint/v1beta1/types.js").Block | undefined>;
10
+ fetchLatestBlock(): Promise<import("@injectivelabs/core-proto-ts/cjs/cosmos/base/tendermint/v1beta1/types.js").Block | import("@injectivelabs/core-proto-ts/cjs/tendermint/types/block.js").Block | undefined>;
11
+ fetchBlock(height: number | string): Promise<import("@injectivelabs/core-proto-ts/cjs/cosmos/base/tendermint/v1beta1/types.js").Block | import("@injectivelabs/core-proto-ts/cjs/tendermint/types/block.js").Block | undefined>;
11
12
  }
@@ -22,7 +22,7 @@ class ChainGrpcTendermintApi extends BaseGrpcConsumer_js_1.default {
22
22
  const request = core_proto_ts_1.CosmosBaseTendermintV1Beta1Query.GetLatestBlockRequest.create();
23
23
  try {
24
24
  const response = await this.retry(() => this.client.GetLatestBlock(request, this.metadata));
25
- return response.block || response.sdkBlock;
25
+ return response.sdkBlock || response.block;
26
26
  }
27
27
  catch (e) {
28
28
  if (e instanceof core_proto_ts_1.CosmosBaseTendermintV1Beta1Query.GrpcWebError) {
@@ -39,5 +39,27 @@ class ChainGrpcTendermintApi extends BaseGrpcConsumer_js_1.default {
39
39
  });
40
40
  }
41
41
  }
42
+ async fetchBlock(height) {
43
+ const request = core_proto_ts_1.CosmosBaseTendermintV1Beta1Query.GetBlockByHeightRequest.create();
44
+ request.height = height.toString();
45
+ try {
46
+ const response = await this.retry(() => this.client.GetBlockByHeight(request, this.metadata));
47
+ return response.sdkBlock || response.block;
48
+ }
49
+ catch (e) {
50
+ if (e instanceof core_proto_ts_1.CosmosBaseTendermintV1Beta1Query.GrpcWebError) {
51
+ throw new exceptions_1.GrpcUnaryRequestException(new Error(e.toString()), {
52
+ code: (0, exceptions_1.grpcErrorCodeToErrorCode)(e.code),
53
+ context: 'TendermintApi.fetchBlock',
54
+ contextModule: this.module,
55
+ });
56
+ }
57
+ throw new exceptions_1.GrpcUnaryRequestException(e, {
58
+ code: exceptions_1.UnspecifiedErrorCode,
59
+ context: 'TendermintApi.fetchBlock',
60
+ contextModule: this.module,
61
+ });
62
+ }
63
+ }
42
64
  }
43
65
  exports.ChainGrpcTendermintApi = ChainGrpcTendermintApi;
@@ -5,6 +5,7 @@ import { BlockLatestRestResponse, NodeInfoRestResponse } from './../types/tender
5
5
  */
6
6
  export declare class ChainRestTendermintApi extends BaseRestConsumer {
7
7
  fetchLatestBlock(params?: Record<string, any>): Promise<BlockLatestRestResponse['block']>;
8
+ fetchBlock(height: number | string, params?: Record<string, any>): Promise<BlockLatestRestResponse['block']>;
8
9
  fetchNodeInfo(params?: Record<string, any>): Promise<{
9
10
  nodeInfo: NodeInfoRestResponse['default_node_info'];
10
11
  applicationVersion: NodeInfoRestResponse['application_version'];
@@ -15,7 +15,24 @@ class ChainRestTendermintApi extends BaseRestConsumer_js_1.default {
15
15
  const endpoint = `cosmos/base/tendermint/v1beta1/blocks/latest`;
16
16
  try {
17
17
  const response = await this.retry(() => this.get(endpoint, params));
18
- return response.data.block;
18
+ return response.data.sdk_block || response.data.block;
19
+ }
20
+ catch (e) {
21
+ if (e instanceof exceptions_1.HttpRequestException) {
22
+ throw e;
23
+ }
24
+ throw new exceptions_1.HttpRequestException(new Error(e), {
25
+ code: exceptions_1.UnspecifiedErrorCode,
26
+ context: `${this.endpoint}/${endpoint}`,
27
+ contextModule: index_js_1.ChainModule.Tendermint,
28
+ });
29
+ }
30
+ }
31
+ async fetchBlock(height, params = {}) {
32
+ const endpoint = `cosmos/base/tendermint/v1beta1/blocks/${height}`;
33
+ try {
34
+ const response = await this.retry(() => this.get(endpoint, params));
35
+ return response.data.sdk_block || response.data.block;
19
36
  }
20
37
  catch (e) {
21
38
  if (e instanceof exceptions_1.HttpRequestException) {
@@ -33,6 +33,33 @@ export interface BlockLatestRestResponse {
33
33
  proposer_address: string;
34
34
  };
35
35
  };
36
+ sdk_block: {
37
+ header: {
38
+ version: {
39
+ block: string;
40
+ app: string;
41
+ };
42
+ chain_id: string;
43
+ height: string;
44
+ time: Date;
45
+ last_block_id: {
46
+ hash: string;
47
+ part_set_header: {
48
+ total: 0;
49
+ hash: string;
50
+ };
51
+ };
52
+ last_commit_hash: string;
53
+ data_hash: string;
54
+ validators_hash: string;
55
+ next_validators_hash: string;
56
+ consensus_hash: string;
57
+ app_hash: string;
58
+ last_results_hash: string;
59
+ evidence_hash: string;
60
+ proposer_address: string;
61
+ };
62
+ };
36
63
  }
37
64
  export interface NodeInfoRestResponse {
38
65
  default_node_info: {
@@ -1,6 +1,7 @@
1
1
  import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
2
2
  import { InjectiveExchangeRpc } from '@injectivelabs/indexer-proto-ts';
3
3
  import { CosmosTxV1Beta1Tx } from '@injectivelabs/core-proto-ts';
4
+ import BaseGrpcConsumer from '../../base/BaseIndexerGrpcConsumer.js';
4
5
  interface PrepareTxArgs {
5
6
  address: AccountAddress;
6
7
  chainId: EthereumChainId;
@@ -16,7 +17,7 @@ interface PrepareTxArgs {
16
17
  * @category Indexer Grpc API
17
18
  * @deprecated use IndexerGrpcWeb3GwApi
18
19
  */
19
- export declare class IndexerGrpcTransactionApi {
20
+ export declare class IndexerGrpcTransactionApi extends BaseGrpcConsumer {
20
21
  protected module: string;
21
22
  protected client: InjectiveExchangeRpc.InjectiveExchangeRPCClientImpl;
22
23
  constructor(endpoint: string);
@@ -1,22 +1,26 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.IndexerGrpcTransactionApi = void 0;
4
7
  const utils_1 = require("@injectivelabs/utils");
5
8
  const transaction_js_1 = require("../../../utils/transaction.js");
6
9
  const index_js_1 = require("../types/index.js");
7
10
  const exceptions_1 = require("@injectivelabs/exceptions");
8
- const BaseIndexerGrpcWebConsumer_js_1 = require("../../base/BaseIndexerGrpcWebConsumer.js");
9
11
  const indexer_proto_ts_1 = require("@injectivelabs/indexer-proto-ts");
10
12
  const core_proto_ts_1 = require("@injectivelabs/core-proto-ts");
13
+ const BaseIndexerGrpcConsumer_js_1 = __importDefault(require("../../base/BaseIndexerGrpcConsumer.js"));
11
14
  /**
12
15
  * @category Indexer Grpc API
13
16
  * @deprecated use IndexerGrpcWeb3GwApi
14
17
  */
15
- class IndexerGrpcTransactionApi {
18
+ class IndexerGrpcTransactionApi extends BaseIndexerGrpcConsumer_js_1.default {
16
19
  module = index_js_1.IndexerModule.Transaction;
17
20
  client;
18
21
  constructor(endpoint) {
19
- this.client = new indexer_proto_ts_1.InjectiveExchangeRpc.InjectiveExchangeRPCClientImpl((0, BaseIndexerGrpcWebConsumer_js_1.getGrpcIndexerWebImpl)(endpoint));
22
+ super(endpoint);
23
+ this.client = new indexer_proto_ts_1.InjectiveExchangeRpc.InjectiveExchangeRPCClientImpl(this.getGrpcWebImpl(endpoint));
20
24
  }
21
25
  async prepareTxRequest(args) {
22
26
  const { address, chainId, message, memo, estimateGas = true, gasLimit = utils_1.DEFAULT_GAS_LIMIT, feeDenom = utils_1.DEFAULT_BRIDGE_FEE_DENOM, feePrice = utils_1.DEFAULT_BRIDGE_FEE_PRICE, timeoutHeight, } = args;
@@ -42,7 +46,7 @@ class IndexerGrpcTransactionApi {
42
46
  prepareTxRequest.memo = typeof memo === 'number' ? memo.toString() : memo;
43
47
  }
44
48
  try {
45
- const response = await this.client.PrepareTx(prepareTxRequest);
49
+ const response = await this.client.PrepareTx(prepareTxRequest, this.metadata);
46
50
  return response;
47
51
  }
48
52
  catch (e) {
@@ -89,7 +93,7 @@ class IndexerGrpcTransactionApi {
89
93
  prepareTxRequest.memo = typeof memo === 'number' ? memo.toString() : memo;
90
94
  }
91
95
  try {
92
- const response = await this.client.PrepareCosmosTx(prepareTxRequest);
96
+ const response = await this.client.PrepareCosmosTx(prepareTxRequest, this.metadata);
93
97
  return response;
94
98
  }
95
99
  catch (e) {
@@ -133,7 +137,7 @@ class IndexerGrpcTransactionApi {
133
137
  const messagesList = arrayOfMessages.map((message) => Buffer.from(JSON.stringify(message), 'utf8'));
134
138
  broadcastTxRequest.msgs = messagesList;
135
139
  try {
136
- const response = await this.client.BroadcastTx(broadcastTxRequest);
140
+ const response = await this.client.BroadcastTx(broadcastTxRequest, this.metadata);
137
141
  return response;
138
142
  }
139
143
  catch (e) {
@@ -171,7 +175,7 @@ class IndexerGrpcTransactionApi {
171
175
  broadcastTxRequest.signature = `0x${signatureInHex}`;
172
176
  broadcastTxRequest.tx = core_proto_ts_1.CosmosTxV1Beta1Tx.TxRaw.encode(txRaw).finish();
173
177
  try {
174
- const response = await this.client.BroadcastCosmosTx(broadcastTxRequest);
178
+ const response = await this.client.BroadcastCosmosTx(broadcastTxRequest, this.metadata);
175
179
  return response;
176
180
  }
177
181
  catch (e) {
@@ -193,7 +197,7 @@ class IndexerGrpcTransactionApi {
193
197
  async fetchFeePayer() {
194
198
  const request = indexer_proto_ts_1.InjectiveExchangeRpc.GetFeePayerRequest.create();
195
199
  try {
196
- const response = await this.client.GetFeePayer(request);
200
+ const response = await this.client.GetFeePayer(request, this.metadata);
197
201
  return response;
198
202
  }
199
203
  catch (e) {
@@ -47,7 +47,7 @@ class IndexerGrpcWeb3GwApi extends IndexerGrpcTransactionApi_js_1.IndexerGrpcTra
47
47
  prepareTxRequest.sequence = sequence.toString();
48
48
  }
49
49
  try {
50
- const response = await this.client.PrepareEip712(prepareTxRequest);
50
+ const response = await this.client.PrepareEip712(prepareTxRequest, this.metadata);
51
51
  return response;
52
52
  }
53
53
  catch (e) {
@@ -1,10 +1,14 @@
1
1
  import { TxConcreteApi, TxClientBroadcastOptions, TxClientBroadcastResponse } from '../types/tx.js';
2
2
  import { TxResponse } from '../types/tx.js';
3
3
  import { CosmosTxV1Beta1Service, CosmosTxV1Beta1Tx } from '@injectivelabs/core-proto-ts';
4
+ import { grpcPkg } from '../../../utils/grpc.js';
4
5
  export declare class TxGrpcApi implements TxConcreteApi {
5
6
  txService: CosmosTxV1Beta1Service.ServiceClientImpl;
7
+ protected metadata?: grpcPkg.grpc.Metadata;
6
8
  endpoint: string;
7
9
  constructor(endpoint: string);
10
+ setMetadata(map: Record<string, string>): this;
11
+ clearMetadata(): void;
8
12
  fetchTx(hash: string): Promise<TxResponse>;
9
13
  fetchTxPoll(txHash: string, timeout?: number): Promise<TxResponse>;
10
14
  simulate(txRaw: CosmosTxV1Beta1Tx.TxRaw): Promise<{
@@ -8,18 +8,29 @@ const exceptions_1 = require("@injectivelabs/exceptions");
8
8
  const utils_1 = require("@injectivelabs/utils");
9
9
  const BaseGrpcWebConsumer_js_1 = __importDefault(require("../../../client/base/BaseGrpcWebConsumer.js"));
10
10
  const core_proto_ts_1 = require("@injectivelabs/core-proto-ts");
11
+ const grpc_js_1 = require("../../../utils/grpc.js");
11
12
  class TxGrpcApi {
12
13
  txService;
14
+ metadata;
13
15
  endpoint;
14
16
  constructor(endpoint) {
15
17
  this.endpoint = endpoint;
16
18
  this.txService = new core_proto_ts_1.CosmosTxV1Beta1Service.ServiceClientImpl(BaseGrpcWebConsumer_js_1.default.getGrpcWebImpl(endpoint));
17
19
  }
20
+ setMetadata(map) {
21
+ const metadata = new grpc_js_1.grpc.Metadata();
22
+ Object.keys(map).forEach((key) => metadata.set(key, map[key]));
23
+ this.metadata = metadata;
24
+ return this;
25
+ }
26
+ clearMetadata() {
27
+ this.metadata = undefined;
28
+ }
18
29
  async fetchTx(hash) {
19
30
  const request = core_proto_ts_1.CosmosTxV1Beta1Service.GetTxRequest.create();
20
31
  request.hash = hash;
21
32
  try {
22
- const response = await this.txService.GetTx(request);
33
+ const response = await this.txService.GetTx(request, this.metadata);
23
34
  const txResponse = response.txResponse;
24
35
  if (!txResponse) {
25
36
  throw new exceptions_1.GrpcUnaryRequestException(new Error(`The transaction with ${hash} is not found`), {
@@ -92,7 +103,7 @@ class TxGrpcApi {
92
103
  simulateRequest.txBytes =
93
104
  core_proto_ts_1.CosmosTxV1Beta1Tx.TxRaw.encode(txRawClone).finish();
94
105
  try {
95
- const response = await txService.Simulate(simulateRequest);
106
+ const response = await txService.Simulate(simulateRequest, this.metadata);
96
107
  const result = {
97
108
  ...response.result,
98
109
  data: response.result ? response.result.data : '',
@@ -126,7 +137,7 @@ class TxGrpcApi {
126
137
  broadcastTxRequest.txBytes = core_proto_ts_1.CosmosTxV1Beta1Tx.TxRaw.encode(txRaw).finish();
127
138
  broadcastTxRequest.mode = mode;
128
139
  try {
129
- const response = await txService.BroadcastTx(broadcastTxRequest);
140
+ const response = await txService.BroadcastTx(broadcastTxRequest, this.metadata);
130
141
  const txResponse = response.txResponse;
131
142
  if (txResponse.code !== 0) {
132
143
  throw new exceptions_1.TransactionException(new Error(txResponse.rawLog), {
@@ -152,7 +163,7 @@ class TxGrpcApi {
152
163
  broadcastTxRequest.mode =
153
164
  core_proto_ts_1.CosmosTxV1Beta1Service.BroadcastMode.BROADCAST_MODE_BLOCK;
154
165
  try {
155
- const response = await txService.BroadcastTx(broadcastTxRequest);
166
+ const response = await txService.BroadcastTx(broadcastTxRequest, this.metadata);
156
167
  const txResponse = response.txResponse;
157
168
  if (!txResponse) {
158
169
  throw new exceptions_1.GeneralException(new Error('There was an issue broadcasting the transaction'));
@@ -7,5 +7,6 @@ export declare class ChainGrpcTendermintApi extends BaseGrpcConsumer {
7
7
  protected module: string;
8
8
  protected client: CosmosBaseTendermintV1Beta1Query.ServiceClientImpl;
9
9
  constructor(endpoint: string);
10
- fetchLatestBlock(): Promise<import("@injectivelabs/core-proto-ts/cjs/tendermint/types/block.js").Block | import("@injectivelabs/core-proto-ts/cjs/cosmos/base/tendermint/v1beta1/types.js").Block | undefined>;
10
+ fetchLatestBlock(): Promise<import("@injectivelabs/core-proto-ts/cjs/cosmos/base/tendermint/v1beta1/types.js").Block | import("@injectivelabs/core-proto-ts/cjs/tendermint/types/block.js").Block | undefined>;
11
+ fetchBlock(height: number | string): Promise<import("@injectivelabs/core-proto-ts/cjs/cosmos/base/tendermint/v1beta1/types.js").Block | import("@injectivelabs/core-proto-ts/cjs/tendermint/types/block.js").Block | undefined>;
11
12
  }
@@ -16,7 +16,7 @@ export class ChainGrpcTendermintApi extends BaseGrpcConsumer {
16
16
  const request = CosmosBaseTendermintV1Beta1Query.GetLatestBlockRequest.create();
17
17
  try {
18
18
  const response = await this.retry(() => this.client.GetLatestBlock(request, this.metadata));
19
- return response.block || response.sdkBlock;
19
+ return response.sdkBlock || response.block;
20
20
  }
21
21
  catch (e) {
22
22
  if (e instanceof CosmosBaseTendermintV1Beta1Query.GrpcWebError) {
@@ -33,4 +33,26 @@ export class ChainGrpcTendermintApi extends BaseGrpcConsumer {
33
33
  });
34
34
  }
35
35
  }
36
+ async fetchBlock(height) {
37
+ const request = CosmosBaseTendermintV1Beta1Query.GetBlockByHeightRequest.create();
38
+ request.height = height.toString();
39
+ try {
40
+ const response = await this.retry(() => this.client.GetBlockByHeight(request, this.metadata));
41
+ return response.sdkBlock || response.block;
42
+ }
43
+ catch (e) {
44
+ if (e instanceof CosmosBaseTendermintV1Beta1Query.GrpcWebError) {
45
+ throw new GrpcUnaryRequestException(new Error(e.toString()), {
46
+ code: grpcErrorCodeToErrorCode(e.code),
47
+ context: 'TendermintApi.fetchBlock',
48
+ contextModule: this.module,
49
+ });
50
+ }
51
+ throw new GrpcUnaryRequestException(e, {
52
+ code: UnspecifiedErrorCode,
53
+ context: 'TendermintApi.fetchBlock',
54
+ contextModule: this.module,
55
+ });
56
+ }
57
+ }
36
58
  }
@@ -5,6 +5,7 @@ import { BlockLatestRestResponse, NodeInfoRestResponse } from './../types/tender
5
5
  */
6
6
  export declare class ChainRestTendermintApi extends BaseRestConsumer {
7
7
  fetchLatestBlock(params?: Record<string, any>): Promise<BlockLatestRestResponse['block']>;
8
+ fetchBlock(height: number | string, params?: Record<string, any>): Promise<BlockLatestRestResponse['block']>;
8
9
  fetchNodeInfo(params?: Record<string, any>): Promise<{
9
10
  nodeInfo: NodeInfoRestResponse['default_node_info'];
10
11
  applicationVersion: NodeInfoRestResponse['application_version'];
@@ -9,7 +9,24 @@ export class ChainRestTendermintApi extends BaseRestConsumer {
9
9
  const endpoint = `cosmos/base/tendermint/v1beta1/blocks/latest`;
10
10
  try {
11
11
  const response = await this.retry(() => this.get(endpoint, params));
12
- return response.data.block;
12
+ return response.data.sdk_block || response.data.block;
13
+ }
14
+ catch (e) {
15
+ if (e instanceof HttpRequestException) {
16
+ throw e;
17
+ }
18
+ throw new HttpRequestException(new Error(e), {
19
+ code: UnspecifiedErrorCode,
20
+ context: `${this.endpoint}/${endpoint}`,
21
+ contextModule: ChainModule.Tendermint,
22
+ });
23
+ }
24
+ }
25
+ async fetchBlock(height, params = {}) {
26
+ const endpoint = `cosmos/base/tendermint/v1beta1/blocks/${height}`;
27
+ try {
28
+ const response = await this.retry(() => this.get(endpoint, params));
29
+ return response.data.sdk_block || response.data.block;
13
30
  }
14
31
  catch (e) {
15
32
  if (e instanceof HttpRequestException) {
@@ -33,6 +33,33 @@ export interface BlockLatestRestResponse {
33
33
  proposer_address: string;
34
34
  };
35
35
  };
36
+ sdk_block: {
37
+ header: {
38
+ version: {
39
+ block: string;
40
+ app: string;
41
+ };
42
+ chain_id: string;
43
+ height: string;
44
+ time: Date;
45
+ last_block_id: {
46
+ hash: string;
47
+ part_set_header: {
48
+ total: 0;
49
+ hash: string;
50
+ };
51
+ };
52
+ last_commit_hash: string;
53
+ data_hash: string;
54
+ validators_hash: string;
55
+ next_validators_hash: string;
56
+ consensus_hash: string;
57
+ app_hash: string;
58
+ last_results_hash: string;
59
+ evidence_hash: string;
60
+ proposer_address: string;
61
+ };
62
+ };
36
63
  }
37
64
  export interface NodeInfoRestResponse {
38
65
  default_node_info: {
@@ -1,6 +1,7 @@
1
1
  import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
2
2
  import { InjectiveExchangeRpc } from '@injectivelabs/indexer-proto-ts';
3
3
  import { CosmosTxV1Beta1Tx } from '@injectivelabs/core-proto-ts';
4
+ import BaseGrpcConsumer from '../../base/BaseIndexerGrpcConsumer.js';
4
5
  interface PrepareTxArgs {
5
6
  address: AccountAddress;
6
7
  chainId: EthereumChainId;
@@ -16,7 +17,7 @@ interface PrepareTxArgs {
16
17
  * @category Indexer Grpc API
17
18
  * @deprecated use IndexerGrpcWeb3GwApi
18
19
  */
19
- export declare class IndexerGrpcTransactionApi {
20
+ export declare class IndexerGrpcTransactionApi extends BaseGrpcConsumer {
20
21
  protected module: string;
21
22
  protected client: InjectiveExchangeRpc.InjectiveExchangeRPCClientImpl;
22
23
  constructor(endpoint: string);
@@ -2,18 +2,19 @@ import { DEFAULT_GAS_LIMIT, DEFAULT_EXCHANGE_LIMIT, DEFAULT_BRIDGE_FEE_DENOM, DE
2
2
  import { recoverTypedSignaturePubKey } from '../../../utils/transaction.js';
3
3
  import { IndexerModule } from '../types/index.js';
4
4
  import { ErrorType, UnspecifiedErrorCode, TransactionException, grpcErrorCodeToErrorCode, GrpcUnaryRequestException, } from '@injectivelabs/exceptions';
5
- import { getGrpcIndexerWebImpl } from '../../base/BaseIndexerGrpcWebConsumer.js';
6
5
  import { InjectiveExchangeRpc } from '@injectivelabs/indexer-proto-ts';
7
6
  import { CosmosTxV1Beta1Tx, CosmosBaseV1Beta1Coin, } from '@injectivelabs/core-proto-ts';
7
+ import BaseGrpcConsumer from '../../base/BaseIndexerGrpcConsumer.js';
8
8
  /**
9
9
  * @category Indexer Grpc API
10
10
  * @deprecated use IndexerGrpcWeb3GwApi
11
11
  */
12
- export class IndexerGrpcTransactionApi {
12
+ export class IndexerGrpcTransactionApi extends BaseGrpcConsumer {
13
13
  module = IndexerModule.Transaction;
14
14
  client;
15
15
  constructor(endpoint) {
16
- this.client = new InjectiveExchangeRpc.InjectiveExchangeRPCClientImpl(getGrpcIndexerWebImpl(endpoint));
16
+ super(endpoint);
17
+ this.client = new InjectiveExchangeRpc.InjectiveExchangeRPCClientImpl(this.getGrpcWebImpl(endpoint));
17
18
  }
18
19
  async prepareTxRequest(args) {
19
20
  const { address, chainId, message, memo, estimateGas = true, gasLimit = DEFAULT_GAS_LIMIT, feeDenom = DEFAULT_BRIDGE_FEE_DENOM, feePrice = DEFAULT_BRIDGE_FEE_PRICE, timeoutHeight, } = args;
@@ -39,7 +40,7 @@ export class IndexerGrpcTransactionApi {
39
40
  prepareTxRequest.memo = typeof memo === 'number' ? memo.toString() : memo;
40
41
  }
41
42
  try {
42
- const response = await this.client.PrepareTx(prepareTxRequest);
43
+ const response = await this.client.PrepareTx(prepareTxRequest, this.metadata);
43
44
  return response;
44
45
  }
45
46
  catch (e) {
@@ -86,7 +87,7 @@ export class IndexerGrpcTransactionApi {
86
87
  prepareTxRequest.memo = typeof memo === 'number' ? memo.toString() : memo;
87
88
  }
88
89
  try {
89
- const response = await this.client.PrepareCosmosTx(prepareTxRequest);
90
+ const response = await this.client.PrepareCosmosTx(prepareTxRequest, this.metadata);
90
91
  return response;
91
92
  }
92
93
  catch (e) {
@@ -130,7 +131,7 @@ export class IndexerGrpcTransactionApi {
130
131
  const messagesList = arrayOfMessages.map((message) => Buffer.from(JSON.stringify(message), 'utf8'));
131
132
  broadcastTxRequest.msgs = messagesList;
132
133
  try {
133
- const response = await this.client.BroadcastTx(broadcastTxRequest);
134
+ const response = await this.client.BroadcastTx(broadcastTxRequest, this.metadata);
134
135
  return response;
135
136
  }
136
137
  catch (e) {
@@ -168,7 +169,7 @@ export class IndexerGrpcTransactionApi {
168
169
  broadcastTxRequest.signature = `0x${signatureInHex}`;
169
170
  broadcastTxRequest.tx = CosmosTxV1Beta1Tx.TxRaw.encode(txRaw).finish();
170
171
  try {
171
- const response = await this.client.BroadcastCosmosTx(broadcastTxRequest);
172
+ const response = await this.client.BroadcastCosmosTx(broadcastTxRequest, this.metadata);
172
173
  return response;
173
174
  }
174
175
  catch (e) {
@@ -190,7 +191,7 @@ export class IndexerGrpcTransactionApi {
190
191
  async fetchFeePayer() {
191
192
  const request = InjectiveExchangeRpc.GetFeePayerRequest.create();
192
193
  try {
193
- const response = await this.client.GetFeePayer(request);
194
+ const response = await this.client.GetFeePayer(request, this.metadata);
194
195
  return response;
195
196
  }
196
197
  catch (e) {
@@ -44,7 +44,7 @@ export class IndexerGrpcWeb3GwApi extends IndexerGrpcTransactionApi {
44
44
  prepareTxRequest.sequence = sequence.toString();
45
45
  }
46
46
  try {
47
- const response = await this.client.PrepareEip712(prepareTxRequest);
47
+ const response = await this.client.PrepareEip712(prepareTxRequest, this.metadata);
48
48
  return response;
49
49
  }
50
50
  catch (e) {
@@ -1,10 +1,14 @@
1
1
  import { TxConcreteApi, TxClientBroadcastOptions, TxClientBroadcastResponse } from '../types/tx.js';
2
2
  import { TxResponse } from '../types/tx.js';
3
3
  import { CosmosTxV1Beta1Service, CosmosTxV1Beta1Tx } from '@injectivelabs/core-proto-ts';
4
+ import { grpcPkg } from '../../../utils/grpc.js';
4
5
  export declare class TxGrpcApi implements TxConcreteApi {
5
6
  txService: CosmosTxV1Beta1Service.ServiceClientImpl;
7
+ protected metadata?: grpcPkg.grpc.Metadata;
6
8
  endpoint: string;
7
9
  constructor(endpoint: string);
10
+ setMetadata(map: Record<string, string>): this;
11
+ clearMetadata(): void;
8
12
  fetchTx(hash: string): Promise<TxResponse>;
9
13
  fetchTxPoll(txHash: string, timeout?: number): Promise<TxResponse>;
10
14
  simulate(txRaw: CosmosTxV1Beta1Tx.TxRaw): Promise<{
@@ -2,18 +2,29 @@ import { GeneralException, TransactionException, grpcErrorCodeToErrorCode, GrpcU
2
2
  import { BigNumberInBase, DEFAULT_BLOCK_TIME_IN_SECONDS, DEFAULT_BLOCK_TIMEOUT_HEIGHT, DEFAULT_TX_BLOCK_INCLUSION_TIMEOUT_IN_MS, } from '@injectivelabs/utils';
3
3
  import BaseGrpcWebConsumer from '../../../client/base/BaseGrpcWebConsumer.js';
4
4
  import { CosmosTxV1Beta1Service, CosmosTxV1Beta1Tx, } from '@injectivelabs/core-proto-ts';
5
+ import { grpc } from '../../../utils/grpc.js';
5
6
  export class TxGrpcApi {
6
7
  txService;
8
+ metadata;
7
9
  endpoint;
8
10
  constructor(endpoint) {
9
11
  this.endpoint = endpoint;
10
12
  this.txService = new CosmosTxV1Beta1Service.ServiceClientImpl(BaseGrpcWebConsumer.getGrpcWebImpl(endpoint));
11
13
  }
14
+ setMetadata(map) {
15
+ const metadata = new grpc.Metadata();
16
+ Object.keys(map).forEach((key) => metadata.set(key, map[key]));
17
+ this.metadata = metadata;
18
+ return this;
19
+ }
20
+ clearMetadata() {
21
+ this.metadata = undefined;
22
+ }
12
23
  async fetchTx(hash) {
13
24
  const request = CosmosTxV1Beta1Service.GetTxRequest.create();
14
25
  request.hash = hash;
15
26
  try {
16
- const response = await this.txService.GetTx(request);
27
+ const response = await this.txService.GetTx(request, this.metadata);
17
28
  const txResponse = response.txResponse;
18
29
  if (!txResponse) {
19
30
  throw new GrpcUnaryRequestException(new Error(`The transaction with ${hash} is not found`), {
@@ -86,7 +97,7 @@ export class TxGrpcApi {
86
97
  simulateRequest.txBytes =
87
98
  CosmosTxV1Beta1Tx.TxRaw.encode(txRawClone).finish();
88
99
  try {
89
- const response = await txService.Simulate(simulateRequest);
100
+ const response = await txService.Simulate(simulateRequest, this.metadata);
90
101
  const result = {
91
102
  ...response.result,
92
103
  data: response.result ? response.result.data : '',
@@ -120,7 +131,7 @@ export class TxGrpcApi {
120
131
  broadcastTxRequest.txBytes = CosmosTxV1Beta1Tx.TxRaw.encode(txRaw).finish();
121
132
  broadcastTxRequest.mode = mode;
122
133
  try {
123
- const response = await txService.BroadcastTx(broadcastTxRequest);
134
+ const response = await txService.BroadcastTx(broadcastTxRequest, this.metadata);
124
135
  const txResponse = response.txResponse;
125
136
  if (txResponse.code !== 0) {
126
137
  throw new TransactionException(new Error(txResponse.rawLog), {
@@ -146,7 +157,7 @@ export class TxGrpcApi {
146
157
  broadcastTxRequest.mode =
147
158
  CosmosTxV1Beta1Service.BroadcastMode.BROADCAST_MODE_BLOCK;
148
159
  try {
149
- const response = await txService.BroadcastTx(broadcastTxRequest);
160
+ const response = await txService.BroadcastTx(broadcastTxRequest, this.metadata);
150
161
  const txResponse = response.txResponse;
151
162
  if (!txResponse) {
152
163
  throw new GeneralException(new Error('There was an issue broadcasting the transaction'));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@injectivelabs/sdk-ts",
3
3
  "description": "SDK in TypeScript for building Injective applications in a browser, node, and react native environment.",
4
- "version": "1.15.2",
4
+ "version": "1.15.4",
5
5
  "sideEffects": false,
6
6
  "license": "Apache-2.0",
7
7
  "author": {
@@ -152,7 +152,7 @@
152
152
  "shx": "^0.3.4",
153
153
  "snakecase-keys": "^5.4.1"
154
154
  },
155
- "gitHead": "64a57f3115b63114124d0d1fb61f75e520905499",
155
+ "gitHead": "b3c1eea83eec540cbd39b923a430c132014b59b6",
156
156
  "typedoc": {
157
157
  "entryPoint": "./src/index.ts",
158
158
  "readmeFile": "./README.md",