@injectivelabs/sdk-ts 1.15.15 → 1.15.17
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/client/indexer/grpc/IndexerGrpcExplorerApi.d.ts +42 -0
- package/dist/cjs/client/indexer/grpc/IndexerGrpcExplorerApi.js +146 -0
- package/dist/cjs/client/indexer/grpc_stream/IndexerGrpcTradingStream.d.ts +17 -0
- package/dist/cjs/client/indexer/grpc_stream/IndexerGrpcTradingStream.js +46 -0
- package/dist/cjs/client/indexer/grpc_stream/index.d.ts +1 -0
- package/dist/cjs/client/indexer/grpc_stream/index.js +1 -0
- package/dist/cjs/client/indexer/transformers/IndexerGrpcExplorerTransformer.d.ts +21 -1
- package/dist/cjs/client/indexer/transformers/IndexerGrpcExplorerTransformer.js +190 -0
- package/dist/cjs/client/indexer/types/explorer.d.ts +20 -0
- package/dist/cjs/client/indexer/types/trading.d.ts +1 -0
- package/dist/esm/client/indexer/grpc/IndexerGrpcExplorerApi.d.ts +42 -0
- package/dist/esm/client/indexer/grpc/IndexerGrpcExplorerApi.js +146 -0
- package/dist/esm/client/indexer/grpc_stream/IndexerGrpcTradingStream.d.ts +17 -0
- package/dist/esm/client/indexer/grpc_stream/IndexerGrpcTradingStream.js +42 -0
- package/dist/esm/client/indexer/grpc_stream/index.d.ts +1 -0
- package/dist/esm/client/indexer/grpc_stream/index.js +1 -0
- package/dist/esm/client/indexer/transformers/IndexerGrpcExplorerTransformer.d.ts +21 -1
- package/dist/esm/client/indexer/transformers/IndexerGrpcExplorerTransformer.js +190 -0
- package/dist/esm/client/indexer/types/explorer.d.ts +20 -0
- package/dist/esm/client/indexer/types/trading.d.ts +1 -0
- package/package.json +7 -7
|
@@ -63,4 +63,46 @@ export declare class IndexerGrpcExplorerApi extends BaseGrpcConsumer {
|
|
|
63
63
|
skip?: number;
|
|
64
64
|
}): Promise<import("../types/explorer.js").IBCTransferTx[]>;
|
|
65
65
|
fetchExplorerStats(): Promise<import("../types/explorer.js").ExplorerStats>;
|
|
66
|
+
fetchTxsV2({ type, token, status, perPage, endTime, startTime, blockNumber, }: {
|
|
67
|
+
type?: string;
|
|
68
|
+
token?: string;
|
|
69
|
+
status?: string;
|
|
70
|
+
perPage?: number;
|
|
71
|
+
endTime?: number;
|
|
72
|
+
startTime?: number;
|
|
73
|
+
blockNumber?: number;
|
|
74
|
+
}): Promise<{
|
|
75
|
+
data: import("../types/explorer.js").ExplorerTransaction[];
|
|
76
|
+
paging: InjectiveExplorerRpc.Cursor | undefined;
|
|
77
|
+
}>;
|
|
78
|
+
fetchAccountTxsV2({ type, token, address, endTime, perPage, startTime, }: {
|
|
79
|
+
type?: string;
|
|
80
|
+
token?: string;
|
|
81
|
+
address: string;
|
|
82
|
+
endTime?: number;
|
|
83
|
+
perPage?: number;
|
|
84
|
+
startTime?: number;
|
|
85
|
+
}): Promise<{
|
|
86
|
+
data: import("../types/explorer.js").ExplorerTransaction[];
|
|
87
|
+
paging: InjectiveExplorerRpc.Cursor | undefined;
|
|
88
|
+
}>;
|
|
89
|
+
fetchBlocksV2({ token, perPage, }: {
|
|
90
|
+
token?: string;
|
|
91
|
+
perPage?: number;
|
|
92
|
+
}): Promise<{
|
|
93
|
+
paging: InjectiveExplorerRpc.Cursor | undefined;
|
|
94
|
+
data: import("../types/explorer.js").Block[];
|
|
95
|
+
}>;
|
|
96
|
+
fetchContractTxsV2({ to, from, token, height, status, perPage, contractAddress, }: {
|
|
97
|
+
to?: number;
|
|
98
|
+
from?: number;
|
|
99
|
+
token?: string;
|
|
100
|
+
height?: string;
|
|
101
|
+
status?: string;
|
|
102
|
+
perPage?: number;
|
|
103
|
+
contractAddress: string;
|
|
104
|
+
}): Promise<{
|
|
105
|
+
data: import("../types/explorer.js").ContractTransaction[];
|
|
106
|
+
paging: InjectiveExplorerRpc.Cursor | undefined;
|
|
107
|
+
}>;
|
|
66
108
|
}
|
|
@@ -366,5 +366,151 @@ class IndexerGrpcExplorerApi extends BaseIndexerGrpcConsumer_js_1.default {
|
|
|
366
366
|
});
|
|
367
367
|
}
|
|
368
368
|
}
|
|
369
|
+
async fetchTxsV2({ type, token, status, perPage, endTime, startTime, blockNumber, }) {
|
|
370
|
+
const request = indexer_proto_ts_1.InjectiveExplorerRpc.GetTxsV2Request.create();
|
|
371
|
+
if (token) {
|
|
372
|
+
request.token = token;
|
|
373
|
+
}
|
|
374
|
+
if (blockNumber) {
|
|
375
|
+
request.blockNumber = blockNumber.toString();
|
|
376
|
+
}
|
|
377
|
+
if (endTime) {
|
|
378
|
+
request.endTime = endTime.toString();
|
|
379
|
+
}
|
|
380
|
+
if (startTime) {
|
|
381
|
+
request.startTime = startTime.toString();
|
|
382
|
+
}
|
|
383
|
+
if (perPage) {
|
|
384
|
+
request.perPage = perPage;
|
|
385
|
+
}
|
|
386
|
+
if (status) {
|
|
387
|
+
request.status = status;
|
|
388
|
+
}
|
|
389
|
+
if (type) {
|
|
390
|
+
request.type = type;
|
|
391
|
+
}
|
|
392
|
+
try {
|
|
393
|
+
const response = await this.retry(() => this.client.GetTxsV2(request, this.metadata));
|
|
394
|
+
return index_js_2.IndexerGrpcExplorerTransformer.getTxsV2ResponseToTxs(response);
|
|
395
|
+
}
|
|
396
|
+
catch (e) {
|
|
397
|
+
if (e instanceof indexer_proto_ts_1.InjectiveExplorerRpc.GrpcWebError) {
|
|
398
|
+
throw new exceptions_1.GrpcUnaryRequestException(new Error(e.toString()), {
|
|
399
|
+
code: (0, exceptions_1.grpcErrorCodeToErrorCode)(e.code),
|
|
400
|
+
context: 'GetTxsV2',
|
|
401
|
+
contextModule: this.module,
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
throw new exceptions_1.GrpcUnaryRequestException(e, {
|
|
405
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
406
|
+
context: 'GetTxsV2',
|
|
407
|
+
contextModule: this.module,
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
async fetchAccountTxsV2({ type, token, address, endTime, perPage, startTime, }) {
|
|
412
|
+
const request = indexer_proto_ts_1.InjectiveExplorerRpc.GetAccountTxsV2Request.create();
|
|
413
|
+
request.address = address;
|
|
414
|
+
if (startTime) {
|
|
415
|
+
request.startTime = startTime.toString();
|
|
416
|
+
}
|
|
417
|
+
if (endTime) {
|
|
418
|
+
request.endTime = endTime.toString();
|
|
419
|
+
}
|
|
420
|
+
if (perPage) {
|
|
421
|
+
request.perPage = perPage;
|
|
422
|
+
}
|
|
423
|
+
if (token) {
|
|
424
|
+
request.token = token;
|
|
425
|
+
}
|
|
426
|
+
if (type) {
|
|
427
|
+
request.type = type;
|
|
428
|
+
}
|
|
429
|
+
try {
|
|
430
|
+
const response = await this.retry(() => this.client.GetAccountTxsV2(request, this.metadata));
|
|
431
|
+
return index_js_2.IndexerGrpcExplorerTransformer.getAccountTxsV2ResponseToAccountTxs(response);
|
|
432
|
+
}
|
|
433
|
+
catch (e) {
|
|
434
|
+
if (e instanceof indexer_proto_ts_1.InjectiveExplorerRpc.GrpcWebError) {
|
|
435
|
+
throw new exceptions_1.GrpcUnaryRequestException(new Error(e.toString()), {
|
|
436
|
+
code: (0, exceptions_1.grpcErrorCodeToErrorCode)(e.code),
|
|
437
|
+
context: 'GetAccountTxsV2',
|
|
438
|
+
contextModule: this.module,
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
throw new exceptions_1.GrpcUnaryRequestException(e, {
|
|
442
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
443
|
+
context: 'GetAccountTxsV2',
|
|
444
|
+
contextModule: this.module,
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
async fetchBlocksV2({ token, perPage, }) {
|
|
449
|
+
const request = indexer_proto_ts_1.InjectiveExplorerRpc.GetBlocksV2Request.create({});
|
|
450
|
+
if (perPage) {
|
|
451
|
+
request.perPage = perPage;
|
|
452
|
+
}
|
|
453
|
+
if (token) {
|
|
454
|
+
request.token = token;
|
|
455
|
+
}
|
|
456
|
+
try {
|
|
457
|
+
const response = await this.retry(() => this.client.GetBlocksV2(request, this.metadata));
|
|
458
|
+
return index_js_2.IndexerGrpcExplorerTransformer.getBlocksV2ResponseToBlocks(response);
|
|
459
|
+
}
|
|
460
|
+
catch (e) {
|
|
461
|
+
if (e instanceof indexer_proto_ts_1.InjectiveExplorerRpc.GrpcWebError) {
|
|
462
|
+
throw new exceptions_1.GrpcUnaryRequestException(new Error(e.toString()), {
|
|
463
|
+
code: (0, exceptions_1.grpcErrorCodeToErrorCode)(e.code),
|
|
464
|
+
context: 'GetBlocksV2',
|
|
465
|
+
contextModule: this.module,
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
throw new exceptions_1.GrpcUnaryRequestException(e, {
|
|
469
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
470
|
+
context: 'GetBlocksV2',
|
|
471
|
+
contextModule: this.module,
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
async fetchContractTxsV2({ to, from, token, height, status, perPage, contractAddress, }) {
|
|
476
|
+
const request = indexer_proto_ts_1.InjectiveExplorerRpc.GetContractTxsV2Request.create();
|
|
477
|
+
request.address = contractAddress;
|
|
478
|
+
if (from) {
|
|
479
|
+
request.from = from.toString();
|
|
480
|
+
}
|
|
481
|
+
if (to) {
|
|
482
|
+
request.to = to.toString();
|
|
483
|
+
}
|
|
484
|
+
if (perPage) {
|
|
485
|
+
request.perPage = perPage;
|
|
486
|
+
}
|
|
487
|
+
if (token) {
|
|
488
|
+
request.token = token;
|
|
489
|
+
}
|
|
490
|
+
if (height) {
|
|
491
|
+
request.height = height;
|
|
492
|
+
}
|
|
493
|
+
if (status) {
|
|
494
|
+
request.status = status;
|
|
495
|
+
}
|
|
496
|
+
try {
|
|
497
|
+
const response = await this.retry(() => this.client.GetContractTxsV2(request, this.metadata));
|
|
498
|
+
return index_js_2.IndexerGrpcExplorerTransformer.getContractTxsV2ResponseToContractTxs(response);
|
|
499
|
+
}
|
|
500
|
+
catch (e) {
|
|
501
|
+
if (e instanceof indexer_proto_ts_1.InjectiveExplorerRpc.GrpcWebError) {
|
|
502
|
+
throw new exceptions_1.GrpcUnaryRequestException(new Error(e.toString()), {
|
|
503
|
+
code: (0, exceptions_1.grpcErrorCodeToErrorCode)(e.code),
|
|
504
|
+
context: 'GetContractTxsV2',
|
|
505
|
+
contextModule: this.module,
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
throw new exceptions_1.GrpcUnaryRequestException(e, {
|
|
509
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
510
|
+
context: 'GetContractTxsV2',
|
|
511
|
+
contextModule: this.module,
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
}
|
|
369
515
|
}
|
|
370
516
|
exports.IndexerGrpcExplorerApi = IndexerGrpcExplorerApi;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Subscription } from 'rxjs';
|
|
2
|
+
import { InjectiveTradingRpc } from '@injectivelabs/indexer-proto-ts';
|
|
3
|
+
import { StreamStatusResponse } from '../types/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* @category Indexer Grid Strategy Grpc Stream
|
|
6
|
+
*/
|
|
7
|
+
export declare class IndexerGrpcTradingStream {
|
|
8
|
+
protected client: InjectiveTradingRpc.InjectiveTradingRPCClientImpl;
|
|
9
|
+
constructor(endpoint: string);
|
|
10
|
+
streamGridStrategies({ marketId, callback, onEndCallback, accountAddresses, onStatusCallback, }: {
|
|
11
|
+
marketId?: string;
|
|
12
|
+
accountAddresses?: string[];
|
|
13
|
+
onEndCallback?: (status?: StreamStatusResponse) => void;
|
|
14
|
+
onStatusCallback?: (status: StreamStatusResponse) => void;
|
|
15
|
+
callback: (response: InjectiveTradingRpc.StreamStrategyResponse) => void;
|
|
16
|
+
}): Subscription;
|
|
17
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IndexerGrpcTradingStream = void 0;
|
|
4
|
+
const indexer_proto_ts_1 = require("@injectivelabs/indexer-proto-ts");
|
|
5
|
+
const BaseIndexerGrpcWebConsumer_js_1 = require("../../base/BaseIndexerGrpcWebConsumer.js");
|
|
6
|
+
/**
|
|
7
|
+
* @category Indexer Grid Strategy Grpc Stream
|
|
8
|
+
*/
|
|
9
|
+
class IndexerGrpcTradingStream {
|
|
10
|
+
client;
|
|
11
|
+
constructor(endpoint) {
|
|
12
|
+
this.client = new indexer_proto_ts_1.InjectiveTradingRpc.InjectiveTradingRPCClientImpl((0, BaseIndexerGrpcWebConsumer_js_1.getGrpcIndexerWebImpl)(endpoint));
|
|
13
|
+
}
|
|
14
|
+
streamGridStrategies({ marketId, callback, onEndCallback, accountAddresses, onStatusCallback, }) {
|
|
15
|
+
const request = indexer_proto_ts_1.InjectiveTradingRpc.StreamStrategyRequest.create();
|
|
16
|
+
if ((!accountAddresses || accountAddresses.length === 0) && !marketId) {
|
|
17
|
+
throw new Error('accountAddresses or marketId is required');
|
|
18
|
+
}
|
|
19
|
+
if (typeof callback !== 'function') {
|
|
20
|
+
throw new Error('callback must be a function');
|
|
21
|
+
}
|
|
22
|
+
if (accountAddresses) {
|
|
23
|
+
request.accountAddresses = accountAddresses;
|
|
24
|
+
}
|
|
25
|
+
if (marketId) {
|
|
26
|
+
request.marketId = marketId;
|
|
27
|
+
}
|
|
28
|
+
const subscription = this.client.StreamStrategy(request).subscribe({
|
|
29
|
+
next(response) {
|
|
30
|
+
callback(response);
|
|
31
|
+
},
|
|
32
|
+
error(err) {
|
|
33
|
+
if (onStatusCallback) {
|
|
34
|
+
onStatusCallback(err);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
complete() {
|
|
38
|
+
if (onEndCallback) {
|
|
39
|
+
onEndCallback();
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
return subscription;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.IndexerGrpcTradingStream = IndexerGrpcTradingStream;
|
|
@@ -3,6 +3,7 @@ export * from './IndexerGrpcMitoStream.js';
|
|
|
3
3
|
export * from './IndexerGrpcOracleStream.js';
|
|
4
4
|
export * from './IndexerGrpcAccountStream.js';
|
|
5
5
|
export * from './IndexerGrpcAuctionStream.js';
|
|
6
|
+
export * from './IndexerGrpcTradingStream.js';
|
|
6
7
|
export * from './IndexerGrpcExplorerStream.js';
|
|
7
8
|
export * from './IndexerGrpcDerivativesStream.js';
|
|
8
9
|
export * from './IndexerGrpcAccountPortfolioStream.js';
|
|
@@ -19,6 +19,7 @@ __exportStar(require("./IndexerGrpcMitoStream.js"), exports);
|
|
|
19
19
|
__exportStar(require("./IndexerGrpcOracleStream.js"), exports);
|
|
20
20
|
__exportStar(require("./IndexerGrpcAccountStream.js"), exports);
|
|
21
21
|
__exportStar(require("./IndexerGrpcAuctionStream.js"), exports);
|
|
22
|
+
__exportStar(require("./IndexerGrpcTradingStream.js"), exports);
|
|
22
23
|
__exportStar(require("./IndexerGrpcExplorerStream.js"), exports);
|
|
23
24
|
__exportStar(require("./IndexerGrpcDerivativesStream.js"), exports);
|
|
24
25
|
__exportStar(require("./IndexerGrpcAccountPortfolioStream.js"), exports);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Block, GasFee, GrpcGasFee, Transaction, BlockWithTxs, IBCTransferTx, ExplorerStats, PeggyDepositTx, ValidatorUptime, ExplorerValidator, PeggyWithdrawalTx, GrpcIBCTransferTx, GrpcPeggyDepositTx, GrpcValidatorUptime, GrpcPeggyWithdrawalTx, BankMsgSendTransaction, ValidatorSlashingEvent, IndexerStreamTransaction, GrpcValidatorSlashingEvent, ExplorerValidatorDescription, GrpcIndexerValidatorDescription } from '../types/explorer.js';
|
|
1
|
+
import { Block, GasFee, GrpcGasFee, Transaction, BlockWithTxs, IBCTransferTx, ExplorerStats, PeggyDepositTx, ValidatorUptime, ExplorerValidator, PeggyWithdrawalTx, GrpcIBCTransferTx, GrpcPeggyDepositTx, GrpcValidatorUptime, GrpcPeggyWithdrawalTx, BankMsgSendTransaction, ValidatorSlashingEvent, IndexerStreamTransaction, GrpcValidatorSlashingEvent, ExplorerValidatorDescription, GrpcIndexerValidatorDescription, ExplorerTransaction, ContractTransaction } from '../types/explorer.js';
|
|
2
2
|
import { InjectiveExplorerRpc } from '@injectivelabs/indexer-proto-ts';
|
|
3
3
|
/**
|
|
4
4
|
* @category Indexer Grpc Transformer
|
|
@@ -32,4 +32,24 @@ export declare class IndexerGrpcExplorerTransformer {
|
|
|
32
32
|
static grpcPeggyDepositTx(grpcPeggyDepositTx: GrpcPeggyDepositTx): PeggyDepositTx;
|
|
33
33
|
static grpcPeggyWithdrawalTx(grpcPeggyWithdrawalTx: GrpcPeggyWithdrawalTx): PeggyWithdrawalTx;
|
|
34
34
|
static getExplorerStatsResponseToExplorerStats(response: InjectiveExplorerRpc.GetStatsResponse): ExplorerStats;
|
|
35
|
+
static getTxsV2ResponseToTxs(response: InjectiveExplorerRpc.GetTxsV2Response): {
|
|
36
|
+
data: ExplorerTransaction[];
|
|
37
|
+
paging: InjectiveExplorerRpc.Cursor | undefined;
|
|
38
|
+
};
|
|
39
|
+
static grpcTxV2ToTransaction(tx: InjectiveExplorerRpc.TxData): ExplorerTransaction;
|
|
40
|
+
static getAccountTxsV2ResponseToAccountTxs(response: InjectiveExplorerRpc.GetAccountTxsV2Response): {
|
|
41
|
+
data: ExplorerTransaction[];
|
|
42
|
+
paging: InjectiveExplorerRpc.Cursor | undefined;
|
|
43
|
+
};
|
|
44
|
+
static grpcAccountTxV2ToTransaction(tx: InjectiveExplorerRpc.TxDetailData): ExplorerTransaction;
|
|
45
|
+
static getBlocksV2ResponseToBlocks(response: InjectiveExplorerRpc.GetBlocksV2Response): {
|
|
46
|
+
paging: InjectiveExplorerRpc.Cursor | undefined;
|
|
47
|
+
data: Block[];
|
|
48
|
+
};
|
|
49
|
+
static grpcBlockV2ToBlock(block: InjectiveExplorerRpc.BlockInfo): Block;
|
|
50
|
+
static getContractTxsV2ResponseToContractTxs(response: InjectiveExplorerRpc.GetContractTxsV2Response): {
|
|
51
|
+
data: ContractTransaction[];
|
|
52
|
+
paging: InjectiveExplorerRpc.Cursor | undefined;
|
|
53
|
+
};
|
|
54
|
+
static grpcContractTxV2ToTransaction(tx: InjectiveExplorerRpc.TxDetailData): ContractTransaction;
|
|
35
55
|
}
|
|
@@ -1,7 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IndexerGrpcExplorerTransformer = void 0;
|
|
4
|
+
const helpers_js_1 = require("../../../utils/helpers.js");
|
|
5
|
+
const utils_1 = require("@injectivelabs/utils");
|
|
4
6
|
const index_js_1 = require("../../../utils/index.js");
|
|
7
|
+
const ZERO_IN_BASE = new utils_1.BigNumberInBase(0);
|
|
8
|
+
const getContractTransactionV2Amount = (ApiTransaction) => {
|
|
9
|
+
const messages = JSON.parse(Buffer.from(ApiTransaction.messages).toString('utf8'));
|
|
10
|
+
const { type, value } = messages[0];
|
|
11
|
+
const { msg } = value;
|
|
12
|
+
if (!type.includes('MsgExecuteContract')) {
|
|
13
|
+
return ZERO_IN_BASE;
|
|
14
|
+
}
|
|
15
|
+
if (typeof msg === 'string' && !(0, helpers_js_1.isJsonString)(msg)) {
|
|
16
|
+
return ZERO_IN_BASE;
|
|
17
|
+
}
|
|
18
|
+
const msgObj = typeof msg === 'string' ? JSON.parse(msg) : msg;
|
|
19
|
+
if (!msgObj.transfer) {
|
|
20
|
+
return ZERO_IN_BASE;
|
|
21
|
+
}
|
|
22
|
+
return new utils_1.BigNumberInWei(msgObj.transfer.amount).toBase();
|
|
23
|
+
};
|
|
24
|
+
const transactionV2MessagesToMessages = (messages) => {
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(Buffer.from(messages).toString('utf8')).map((msg) => ({
|
|
27
|
+
type: msg.type,
|
|
28
|
+
message: msg.value,
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
console.error('Error parsing transaction messages:', error);
|
|
33
|
+
return []; // Return an empty array in case of error
|
|
34
|
+
}
|
|
35
|
+
};
|
|
5
36
|
/**
|
|
6
37
|
* @category Indexer Grpc Transformer
|
|
7
38
|
*/
|
|
@@ -283,5 +314,164 @@ class IndexerGrpcExplorerTransformer {
|
|
|
283
314
|
txsPerSecondInPast100Blocks: response.txsPs100B,
|
|
284
315
|
};
|
|
285
316
|
}
|
|
317
|
+
static getTxsV2ResponseToTxs(response) {
|
|
318
|
+
return {
|
|
319
|
+
data: response.data.map((tx) => IndexerGrpcExplorerTransformer.grpcTxV2ToTransaction(tx)),
|
|
320
|
+
paging: response.paging,
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
static grpcTxV2ToTransaction(tx) {
|
|
324
|
+
let logs = [];
|
|
325
|
+
try {
|
|
326
|
+
const rawLogs = Buffer.from(tx.logs).toString('utf8');
|
|
327
|
+
logs = JSON.parse(rawLogs || '[]');
|
|
328
|
+
}
|
|
329
|
+
catch (e) {
|
|
330
|
+
console.error('Failed to parse logs');
|
|
331
|
+
logs = [];
|
|
332
|
+
}
|
|
333
|
+
const txType = JSON.parse(Buffer.from(tx.txMsgTypes).toString('utf8'));
|
|
334
|
+
const signatures = tx.signatures.map((signature) => ({
|
|
335
|
+
address: signature.address,
|
|
336
|
+
pubkey: signature.pubkey,
|
|
337
|
+
signature: signature.signature,
|
|
338
|
+
sequence: (() => {
|
|
339
|
+
try {
|
|
340
|
+
return parseInt(signature.sequence, 10);
|
|
341
|
+
}
|
|
342
|
+
catch (e) {
|
|
343
|
+
console.error('Failed to parse signature sequence:', e);
|
|
344
|
+
return 0;
|
|
345
|
+
}
|
|
346
|
+
})(),
|
|
347
|
+
}));
|
|
348
|
+
const claimIds = tx.claimIds.map((claimId) => {
|
|
349
|
+
try {
|
|
350
|
+
return parseInt(claimId, 10);
|
|
351
|
+
}
|
|
352
|
+
catch (e) {
|
|
353
|
+
console.error('Failed to parse claimId:', e);
|
|
354
|
+
return 0;
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
let messages = [];
|
|
358
|
+
try {
|
|
359
|
+
messages = transactionV2MessagesToMessages(tx.messages);
|
|
360
|
+
}
|
|
361
|
+
catch (e) {
|
|
362
|
+
console.error('Failed to parse messages:', e);
|
|
363
|
+
messages = [];
|
|
364
|
+
}
|
|
365
|
+
const blockNumber = parseInt(tx.blockNumber);
|
|
366
|
+
return {
|
|
367
|
+
logs,
|
|
368
|
+
info: '',
|
|
369
|
+
memo: '',
|
|
370
|
+
txType,
|
|
371
|
+
claimIds,
|
|
372
|
+
messages,
|
|
373
|
+
id: tx.id,
|
|
374
|
+
signatures,
|
|
375
|
+
blockNumber,
|
|
376
|
+
gasUsed: 0,
|
|
377
|
+
gasWanted: 0,
|
|
378
|
+
hash: tx.hash,
|
|
379
|
+
code: tx.code,
|
|
380
|
+
errorLog: tx.errorLog,
|
|
381
|
+
codespace: tx.codespace,
|
|
382
|
+
blockTimestamp: tx.blockTimestamp,
|
|
383
|
+
gasFee: { amounts: [], gasLimit: 0, granter: '', payer: '' },
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
static getAccountTxsV2ResponseToAccountTxs(response) {
|
|
387
|
+
return {
|
|
388
|
+
data: response.data.map((tx) => IndexerGrpcExplorerTransformer.grpcAccountTxV2ToTransaction(tx)),
|
|
389
|
+
paging: response.paging,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
static grpcAccountTxV2ToTransaction(tx) {
|
|
393
|
+
return {
|
|
394
|
+
id: tx.id,
|
|
395
|
+
hash: tx.hash,
|
|
396
|
+
code: tx.code,
|
|
397
|
+
info: tx.info,
|
|
398
|
+
memo: tx.memo,
|
|
399
|
+
txType: tx.txType,
|
|
400
|
+
gasFee: {
|
|
401
|
+
amounts: (tx.gasFee?.amount || []).map((amount) => ({
|
|
402
|
+
amount: amount.amount,
|
|
403
|
+
denom: amount.denom,
|
|
404
|
+
})),
|
|
405
|
+
gasLimit: parseInt(tx.gasFee?.gasLimit ?? '0', 10),
|
|
406
|
+
granter: tx.gasFee?.granter ?? '',
|
|
407
|
+
payer: tx.gasFee?.payer ?? '',
|
|
408
|
+
},
|
|
409
|
+
events: tx.events,
|
|
410
|
+
errorLog: tx.errorLog,
|
|
411
|
+
codespace: tx.codespace,
|
|
412
|
+
gasUsed: parseInt(tx.gasUsed, 10),
|
|
413
|
+
blockTimestamp: tx.blockTimestamp,
|
|
414
|
+
gasWanted: parseInt(tx.gasWanted, 10),
|
|
415
|
+
blockNumber: parseInt(tx.blockNumber, 10),
|
|
416
|
+
signatures: tx.signatures.map((signature) => ({
|
|
417
|
+
address: signature.address,
|
|
418
|
+
pubkey: signature.pubkey,
|
|
419
|
+
signature: signature.signature,
|
|
420
|
+
sequence: parseInt(signature.sequence, 10),
|
|
421
|
+
})),
|
|
422
|
+
messages: transactionV2MessagesToMessages(tx.messages),
|
|
423
|
+
logs: JSON.parse(Buffer.from(tx.logs).toString('utf8')),
|
|
424
|
+
data: '/' + Buffer.from(tx.data).toString('utf8').split('/').pop(),
|
|
425
|
+
claimIds: tx.claimIds.map((claimId) => parseInt(claimId, 10)),
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
static getBlocksV2ResponseToBlocks(response) {
|
|
429
|
+
return {
|
|
430
|
+
paging: response.paging,
|
|
431
|
+
data: response.data.map((block) => IndexerGrpcExplorerTransformer.grpcBlockV2ToBlock(block)),
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
static grpcBlockV2ToBlock(block) {
|
|
435
|
+
return {
|
|
436
|
+
moniker: block.moniker,
|
|
437
|
+
proposer: block.proposer,
|
|
438
|
+
blockHash: block.blockHash,
|
|
439
|
+
timestamp: block.timestamp,
|
|
440
|
+
parentHash: block.parentHash,
|
|
441
|
+
height: parseInt(block.height, 10),
|
|
442
|
+
numTxs: parseInt(block.numTxs, 10),
|
|
443
|
+
numPreCommits: parseInt(block.numPreCommits, 10),
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
static getContractTxsV2ResponseToContractTxs(response) {
|
|
447
|
+
return {
|
|
448
|
+
data: response.data.map((tx) => IndexerGrpcExplorerTransformer.grpcContractTxV2ToTransaction(tx)),
|
|
449
|
+
paging: response.paging,
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
static grpcContractTxV2ToTransaction(tx) {
|
|
453
|
+
const messages = transactionV2MessagesToMessages(tx.messages);
|
|
454
|
+
return {
|
|
455
|
+
messages,
|
|
456
|
+
code: tx.code,
|
|
457
|
+
memo: tx.memo,
|
|
458
|
+
type: tx.txType,
|
|
459
|
+
txHash: tx.hash,
|
|
460
|
+
error_log: tx.errorLog,
|
|
461
|
+
height: parseInt(tx.blockNumber, 10),
|
|
462
|
+
tx_number: parseInt(tx.txNumber, 10),
|
|
463
|
+
time: parseInt(tx.blockTimestamp, 10),
|
|
464
|
+
amount: getContractTransactionV2Amount(tx),
|
|
465
|
+
logs: JSON.parse(Buffer.from(tx.logs).toString('utf8')),
|
|
466
|
+
data: '/' + Buffer.from(tx.data).toString('utf8').split('/').pop(),
|
|
467
|
+
fee: new utils_1.BigNumberInWei(tx.gasFee?.amount[0]?.amount || '0').toBase(),
|
|
468
|
+
signatures: tx.signatures.map((signature) => ({
|
|
469
|
+
address: signature.address,
|
|
470
|
+
pubkey: signature.pubkey,
|
|
471
|
+
signature: signature.signature,
|
|
472
|
+
sequence: parseInt(signature.sequence, 10),
|
|
473
|
+
})),
|
|
474
|
+
};
|
|
475
|
+
}
|
|
286
476
|
}
|
|
287
477
|
exports.IndexerGrpcExplorerTransformer = IndexerGrpcExplorerTransformer;
|
|
@@ -352,6 +352,26 @@ export interface ExplorerStats {
|
|
|
352
352
|
txsPerSecondInPast24Hours: string;
|
|
353
353
|
txsPerSecondInPast100Blocks: string;
|
|
354
354
|
}
|
|
355
|
+
export interface ExplorerTxsV2Response {
|
|
356
|
+
data: ExplorerTransactionV2[];
|
|
357
|
+
paging?: InjectiveExplorerRpc.Cursor;
|
|
358
|
+
}
|
|
359
|
+
export interface ExplorerTransactionV2 {
|
|
360
|
+
logs: any;
|
|
361
|
+
id: string;
|
|
362
|
+
code: number;
|
|
363
|
+
hash: string;
|
|
364
|
+
messages: any;
|
|
365
|
+
txNumber: number;
|
|
366
|
+
errorLog?: string;
|
|
367
|
+
codespace: string;
|
|
368
|
+
claimIds: string[];
|
|
369
|
+
blockNumber: number;
|
|
370
|
+
txMsgTypes: string[];
|
|
371
|
+
blockTimestamp: number;
|
|
372
|
+
blockUnixTimestamp: number;
|
|
373
|
+
signatures: InjectiveExplorerRpc.Signature[];
|
|
374
|
+
}
|
|
355
375
|
export type GrpcIBCTransferTx = InjectiveExplorerRpc.IBCTransferTx;
|
|
356
376
|
export type GrpcPeggyDepositTx = InjectiveExplorerRpc.PeggyDepositTx;
|
|
357
377
|
export type GrpcPeggyWithdrawalTx = InjectiveExplorerRpc.PeggyWithdrawalTx;
|
|
@@ -63,4 +63,46 @@ export declare class IndexerGrpcExplorerApi extends BaseGrpcConsumer {
|
|
|
63
63
|
skip?: number;
|
|
64
64
|
}): Promise<import("../types/explorer.js").IBCTransferTx[]>;
|
|
65
65
|
fetchExplorerStats(): Promise<import("../types/explorer.js").ExplorerStats>;
|
|
66
|
+
fetchTxsV2({ type, token, status, perPage, endTime, startTime, blockNumber, }: {
|
|
67
|
+
type?: string;
|
|
68
|
+
token?: string;
|
|
69
|
+
status?: string;
|
|
70
|
+
perPage?: number;
|
|
71
|
+
endTime?: number;
|
|
72
|
+
startTime?: number;
|
|
73
|
+
blockNumber?: number;
|
|
74
|
+
}): Promise<{
|
|
75
|
+
data: import("../types/explorer.js").ExplorerTransaction[];
|
|
76
|
+
paging: InjectiveExplorerRpc.Cursor | undefined;
|
|
77
|
+
}>;
|
|
78
|
+
fetchAccountTxsV2({ type, token, address, endTime, perPage, startTime, }: {
|
|
79
|
+
type?: string;
|
|
80
|
+
token?: string;
|
|
81
|
+
address: string;
|
|
82
|
+
endTime?: number;
|
|
83
|
+
perPage?: number;
|
|
84
|
+
startTime?: number;
|
|
85
|
+
}): Promise<{
|
|
86
|
+
data: import("../types/explorer.js").ExplorerTransaction[];
|
|
87
|
+
paging: InjectiveExplorerRpc.Cursor | undefined;
|
|
88
|
+
}>;
|
|
89
|
+
fetchBlocksV2({ token, perPage, }: {
|
|
90
|
+
token?: string;
|
|
91
|
+
perPage?: number;
|
|
92
|
+
}): Promise<{
|
|
93
|
+
paging: InjectiveExplorerRpc.Cursor | undefined;
|
|
94
|
+
data: import("../types/explorer.js").Block[];
|
|
95
|
+
}>;
|
|
96
|
+
fetchContractTxsV2({ to, from, token, height, status, perPage, contractAddress, }: {
|
|
97
|
+
to?: number;
|
|
98
|
+
from?: number;
|
|
99
|
+
token?: string;
|
|
100
|
+
height?: string;
|
|
101
|
+
status?: string;
|
|
102
|
+
perPage?: number;
|
|
103
|
+
contractAddress: string;
|
|
104
|
+
}): Promise<{
|
|
105
|
+
data: import("../types/explorer.js").ContractTransaction[];
|
|
106
|
+
paging: InjectiveExplorerRpc.Cursor | undefined;
|
|
107
|
+
}>;
|
|
66
108
|
}
|
|
@@ -360,4 +360,150 @@ export class IndexerGrpcExplorerApi extends BaseGrpcConsumer {
|
|
|
360
360
|
});
|
|
361
361
|
}
|
|
362
362
|
}
|
|
363
|
+
async fetchTxsV2({ type, token, status, perPage, endTime, startTime, blockNumber, }) {
|
|
364
|
+
const request = InjectiveExplorerRpc.GetTxsV2Request.create();
|
|
365
|
+
if (token) {
|
|
366
|
+
request.token = token;
|
|
367
|
+
}
|
|
368
|
+
if (blockNumber) {
|
|
369
|
+
request.blockNumber = blockNumber.toString();
|
|
370
|
+
}
|
|
371
|
+
if (endTime) {
|
|
372
|
+
request.endTime = endTime.toString();
|
|
373
|
+
}
|
|
374
|
+
if (startTime) {
|
|
375
|
+
request.startTime = startTime.toString();
|
|
376
|
+
}
|
|
377
|
+
if (perPage) {
|
|
378
|
+
request.perPage = perPage;
|
|
379
|
+
}
|
|
380
|
+
if (status) {
|
|
381
|
+
request.status = status;
|
|
382
|
+
}
|
|
383
|
+
if (type) {
|
|
384
|
+
request.type = type;
|
|
385
|
+
}
|
|
386
|
+
try {
|
|
387
|
+
const response = await this.retry(() => this.client.GetTxsV2(request, this.metadata));
|
|
388
|
+
return IndexerGrpcExplorerTransformer.getTxsV2ResponseToTxs(response);
|
|
389
|
+
}
|
|
390
|
+
catch (e) {
|
|
391
|
+
if (e instanceof InjectiveExplorerRpc.GrpcWebError) {
|
|
392
|
+
throw new GrpcUnaryRequestException(new Error(e.toString()), {
|
|
393
|
+
code: grpcErrorCodeToErrorCode(e.code),
|
|
394
|
+
context: 'GetTxsV2',
|
|
395
|
+
contextModule: this.module,
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
throw new GrpcUnaryRequestException(e, {
|
|
399
|
+
code: UnspecifiedErrorCode,
|
|
400
|
+
context: 'GetTxsV2',
|
|
401
|
+
contextModule: this.module,
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
async fetchAccountTxsV2({ type, token, address, endTime, perPage, startTime, }) {
|
|
406
|
+
const request = InjectiveExplorerRpc.GetAccountTxsV2Request.create();
|
|
407
|
+
request.address = address;
|
|
408
|
+
if (startTime) {
|
|
409
|
+
request.startTime = startTime.toString();
|
|
410
|
+
}
|
|
411
|
+
if (endTime) {
|
|
412
|
+
request.endTime = endTime.toString();
|
|
413
|
+
}
|
|
414
|
+
if (perPage) {
|
|
415
|
+
request.perPage = perPage;
|
|
416
|
+
}
|
|
417
|
+
if (token) {
|
|
418
|
+
request.token = token;
|
|
419
|
+
}
|
|
420
|
+
if (type) {
|
|
421
|
+
request.type = type;
|
|
422
|
+
}
|
|
423
|
+
try {
|
|
424
|
+
const response = await this.retry(() => this.client.GetAccountTxsV2(request, this.metadata));
|
|
425
|
+
return IndexerGrpcExplorerTransformer.getAccountTxsV2ResponseToAccountTxs(response);
|
|
426
|
+
}
|
|
427
|
+
catch (e) {
|
|
428
|
+
if (e instanceof InjectiveExplorerRpc.GrpcWebError) {
|
|
429
|
+
throw new GrpcUnaryRequestException(new Error(e.toString()), {
|
|
430
|
+
code: grpcErrorCodeToErrorCode(e.code),
|
|
431
|
+
context: 'GetAccountTxsV2',
|
|
432
|
+
contextModule: this.module,
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
throw new GrpcUnaryRequestException(e, {
|
|
436
|
+
code: UnspecifiedErrorCode,
|
|
437
|
+
context: 'GetAccountTxsV2',
|
|
438
|
+
contextModule: this.module,
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
async fetchBlocksV2({ token, perPage, }) {
|
|
443
|
+
const request = InjectiveExplorerRpc.GetBlocksV2Request.create({});
|
|
444
|
+
if (perPage) {
|
|
445
|
+
request.perPage = perPage;
|
|
446
|
+
}
|
|
447
|
+
if (token) {
|
|
448
|
+
request.token = token;
|
|
449
|
+
}
|
|
450
|
+
try {
|
|
451
|
+
const response = await this.retry(() => this.client.GetBlocksV2(request, this.metadata));
|
|
452
|
+
return IndexerGrpcExplorerTransformer.getBlocksV2ResponseToBlocks(response);
|
|
453
|
+
}
|
|
454
|
+
catch (e) {
|
|
455
|
+
if (e instanceof InjectiveExplorerRpc.GrpcWebError) {
|
|
456
|
+
throw new GrpcUnaryRequestException(new Error(e.toString()), {
|
|
457
|
+
code: grpcErrorCodeToErrorCode(e.code),
|
|
458
|
+
context: 'GetBlocksV2',
|
|
459
|
+
contextModule: this.module,
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
throw new GrpcUnaryRequestException(e, {
|
|
463
|
+
code: UnspecifiedErrorCode,
|
|
464
|
+
context: 'GetBlocksV2',
|
|
465
|
+
contextModule: this.module,
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
async fetchContractTxsV2({ to, from, token, height, status, perPage, contractAddress, }) {
|
|
470
|
+
const request = InjectiveExplorerRpc.GetContractTxsV2Request.create();
|
|
471
|
+
request.address = contractAddress;
|
|
472
|
+
if (from) {
|
|
473
|
+
request.from = from.toString();
|
|
474
|
+
}
|
|
475
|
+
if (to) {
|
|
476
|
+
request.to = to.toString();
|
|
477
|
+
}
|
|
478
|
+
if (perPage) {
|
|
479
|
+
request.perPage = perPage;
|
|
480
|
+
}
|
|
481
|
+
if (token) {
|
|
482
|
+
request.token = token;
|
|
483
|
+
}
|
|
484
|
+
if (height) {
|
|
485
|
+
request.height = height;
|
|
486
|
+
}
|
|
487
|
+
if (status) {
|
|
488
|
+
request.status = status;
|
|
489
|
+
}
|
|
490
|
+
try {
|
|
491
|
+
const response = await this.retry(() => this.client.GetContractTxsV2(request, this.metadata));
|
|
492
|
+
return IndexerGrpcExplorerTransformer.getContractTxsV2ResponseToContractTxs(response);
|
|
493
|
+
}
|
|
494
|
+
catch (e) {
|
|
495
|
+
if (e instanceof InjectiveExplorerRpc.GrpcWebError) {
|
|
496
|
+
throw new GrpcUnaryRequestException(new Error(e.toString()), {
|
|
497
|
+
code: grpcErrorCodeToErrorCode(e.code),
|
|
498
|
+
context: 'GetContractTxsV2',
|
|
499
|
+
contextModule: this.module,
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
throw new GrpcUnaryRequestException(e, {
|
|
503
|
+
code: UnspecifiedErrorCode,
|
|
504
|
+
context: 'GetContractTxsV2',
|
|
505
|
+
contextModule: this.module,
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
}
|
|
363
509
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Subscription } from 'rxjs';
|
|
2
|
+
import { InjectiveTradingRpc } from '@injectivelabs/indexer-proto-ts';
|
|
3
|
+
import { StreamStatusResponse } from '../types/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* @category Indexer Grid Strategy Grpc Stream
|
|
6
|
+
*/
|
|
7
|
+
export declare class IndexerGrpcTradingStream {
|
|
8
|
+
protected client: InjectiveTradingRpc.InjectiveTradingRPCClientImpl;
|
|
9
|
+
constructor(endpoint: string);
|
|
10
|
+
streamGridStrategies({ marketId, callback, onEndCallback, accountAddresses, onStatusCallback, }: {
|
|
11
|
+
marketId?: string;
|
|
12
|
+
accountAddresses?: string[];
|
|
13
|
+
onEndCallback?: (status?: StreamStatusResponse) => void;
|
|
14
|
+
onStatusCallback?: (status: StreamStatusResponse) => void;
|
|
15
|
+
callback: (response: InjectiveTradingRpc.StreamStrategyResponse) => void;
|
|
16
|
+
}): Subscription;
|
|
17
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { InjectiveTradingRpc } from '@injectivelabs/indexer-proto-ts';
|
|
2
|
+
import { getGrpcIndexerWebImpl } from '../../base/BaseIndexerGrpcWebConsumer.js';
|
|
3
|
+
/**
|
|
4
|
+
* @category Indexer Grid Strategy Grpc Stream
|
|
5
|
+
*/
|
|
6
|
+
export class IndexerGrpcTradingStream {
|
|
7
|
+
client;
|
|
8
|
+
constructor(endpoint) {
|
|
9
|
+
this.client = new InjectiveTradingRpc.InjectiveTradingRPCClientImpl(getGrpcIndexerWebImpl(endpoint));
|
|
10
|
+
}
|
|
11
|
+
streamGridStrategies({ marketId, callback, onEndCallback, accountAddresses, onStatusCallback, }) {
|
|
12
|
+
const request = InjectiveTradingRpc.StreamStrategyRequest.create();
|
|
13
|
+
if ((!accountAddresses || accountAddresses.length === 0) && !marketId) {
|
|
14
|
+
throw new Error('accountAddresses or marketId is required');
|
|
15
|
+
}
|
|
16
|
+
if (typeof callback !== 'function') {
|
|
17
|
+
throw new Error('callback must be a function');
|
|
18
|
+
}
|
|
19
|
+
if (accountAddresses) {
|
|
20
|
+
request.accountAddresses = accountAddresses;
|
|
21
|
+
}
|
|
22
|
+
if (marketId) {
|
|
23
|
+
request.marketId = marketId;
|
|
24
|
+
}
|
|
25
|
+
const subscription = this.client.StreamStrategy(request).subscribe({
|
|
26
|
+
next(response) {
|
|
27
|
+
callback(response);
|
|
28
|
+
},
|
|
29
|
+
error(err) {
|
|
30
|
+
if (onStatusCallback) {
|
|
31
|
+
onStatusCallback(err);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
complete() {
|
|
35
|
+
if (onEndCallback) {
|
|
36
|
+
onEndCallback();
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
return subscription;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -3,6 +3,7 @@ export * from './IndexerGrpcMitoStream.js';
|
|
|
3
3
|
export * from './IndexerGrpcOracleStream.js';
|
|
4
4
|
export * from './IndexerGrpcAccountStream.js';
|
|
5
5
|
export * from './IndexerGrpcAuctionStream.js';
|
|
6
|
+
export * from './IndexerGrpcTradingStream.js';
|
|
6
7
|
export * from './IndexerGrpcExplorerStream.js';
|
|
7
8
|
export * from './IndexerGrpcDerivativesStream.js';
|
|
8
9
|
export * from './IndexerGrpcAccountPortfolioStream.js';
|
|
@@ -3,6 +3,7 @@ export * from './IndexerGrpcMitoStream.js';
|
|
|
3
3
|
export * from './IndexerGrpcOracleStream.js';
|
|
4
4
|
export * from './IndexerGrpcAccountStream.js';
|
|
5
5
|
export * from './IndexerGrpcAuctionStream.js';
|
|
6
|
+
export * from './IndexerGrpcTradingStream.js';
|
|
6
7
|
export * from './IndexerGrpcExplorerStream.js';
|
|
7
8
|
export * from './IndexerGrpcDerivativesStream.js';
|
|
8
9
|
export * from './IndexerGrpcAccountPortfolioStream.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Block, GasFee, GrpcGasFee, Transaction, BlockWithTxs, IBCTransferTx, ExplorerStats, PeggyDepositTx, ValidatorUptime, ExplorerValidator, PeggyWithdrawalTx, GrpcIBCTransferTx, GrpcPeggyDepositTx, GrpcValidatorUptime, GrpcPeggyWithdrawalTx, BankMsgSendTransaction, ValidatorSlashingEvent, IndexerStreamTransaction, GrpcValidatorSlashingEvent, ExplorerValidatorDescription, GrpcIndexerValidatorDescription } from '../types/explorer.js';
|
|
1
|
+
import { Block, GasFee, GrpcGasFee, Transaction, BlockWithTxs, IBCTransferTx, ExplorerStats, PeggyDepositTx, ValidatorUptime, ExplorerValidator, PeggyWithdrawalTx, GrpcIBCTransferTx, GrpcPeggyDepositTx, GrpcValidatorUptime, GrpcPeggyWithdrawalTx, BankMsgSendTransaction, ValidatorSlashingEvent, IndexerStreamTransaction, GrpcValidatorSlashingEvent, ExplorerValidatorDescription, GrpcIndexerValidatorDescription, ExplorerTransaction, ContractTransaction } from '../types/explorer.js';
|
|
2
2
|
import { InjectiveExplorerRpc } from '@injectivelabs/indexer-proto-ts';
|
|
3
3
|
/**
|
|
4
4
|
* @category Indexer Grpc Transformer
|
|
@@ -32,4 +32,24 @@ export declare class IndexerGrpcExplorerTransformer {
|
|
|
32
32
|
static grpcPeggyDepositTx(grpcPeggyDepositTx: GrpcPeggyDepositTx): PeggyDepositTx;
|
|
33
33
|
static grpcPeggyWithdrawalTx(grpcPeggyWithdrawalTx: GrpcPeggyWithdrawalTx): PeggyWithdrawalTx;
|
|
34
34
|
static getExplorerStatsResponseToExplorerStats(response: InjectiveExplorerRpc.GetStatsResponse): ExplorerStats;
|
|
35
|
+
static getTxsV2ResponseToTxs(response: InjectiveExplorerRpc.GetTxsV2Response): {
|
|
36
|
+
data: ExplorerTransaction[];
|
|
37
|
+
paging: InjectiveExplorerRpc.Cursor | undefined;
|
|
38
|
+
};
|
|
39
|
+
static grpcTxV2ToTransaction(tx: InjectiveExplorerRpc.TxData): ExplorerTransaction;
|
|
40
|
+
static getAccountTxsV2ResponseToAccountTxs(response: InjectiveExplorerRpc.GetAccountTxsV2Response): {
|
|
41
|
+
data: ExplorerTransaction[];
|
|
42
|
+
paging: InjectiveExplorerRpc.Cursor | undefined;
|
|
43
|
+
};
|
|
44
|
+
static grpcAccountTxV2ToTransaction(tx: InjectiveExplorerRpc.TxDetailData): ExplorerTransaction;
|
|
45
|
+
static getBlocksV2ResponseToBlocks(response: InjectiveExplorerRpc.GetBlocksV2Response): {
|
|
46
|
+
paging: InjectiveExplorerRpc.Cursor | undefined;
|
|
47
|
+
data: Block[];
|
|
48
|
+
};
|
|
49
|
+
static grpcBlockV2ToBlock(block: InjectiveExplorerRpc.BlockInfo): Block;
|
|
50
|
+
static getContractTxsV2ResponseToContractTxs(response: InjectiveExplorerRpc.GetContractTxsV2Response): {
|
|
51
|
+
data: ContractTransaction[];
|
|
52
|
+
paging: InjectiveExplorerRpc.Cursor | undefined;
|
|
53
|
+
};
|
|
54
|
+
static grpcContractTxV2ToTransaction(tx: InjectiveExplorerRpc.TxDetailData): ContractTransaction;
|
|
35
55
|
}
|
|
@@ -1,4 +1,35 @@
|
|
|
1
|
+
import { isJsonString } from '../../../utils/helpers.js';
|
|
2
|
+
import { BigNumberInWei, BigNumberInBase } from '@injectivelabs/utils';
|
|
1
3
|
import { grpcPagingToPaging } from '../../../utils/index.js';
|
|
4
|
+
const ZERO_IN_BASE = new BigNumberInBase(0);
|
|
5
|
+
const getContractTransactionV2Amount = (ApiTransaction) => {
|
|
6
|
+
const messages = JSON.parse(Buffer.from(ApiTransaction.messages).toString('utf8'));
|
|
7
|
+
const { type, value } = messages[0];
|
|
8
|
+
const { msg } = value;
|
|
9
|
+
if (!type.includes('MsgExecuteContract')) {
|
|
10
|
+
return ZERO_IN_BASE;
|
|
11
|
+
}
|
|
12
|
+
if (typeof msg === 'string' && !isJsonString(msg)) {
|
|
13
|
+
return ZERO_IN_BASE;
|
|
14
|
+
}
|
|
15
|
+
const msgObj = typeof msg === 'string' ? JSON.parse(msg) : msg;
|
|
16
|
+
if (!msgObj.transfer) {
|
|
17
|
+
return ZERO_IN_BASE;
|
|
18
|
+
}
|
|
19
|
+
return new BigNumberInWei(msgObj.transfer.amount).toBase();
|
|
20
|
+
};
|
|
21
|
+
const transactionV2MessagesToMessages = (messages) => {
|
|
22
|
+
try {
|
|
23
|
+
return JSON.parse(Buffer.from(messages).toString('utf8')).map((msg) => ({
|
|
24
|
+
type: msg.type,
|
|
25
|
+
message: msg.value,
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error('Error parsing transaction messages:', error);
|
|
30
|
+
return []; // Return an empty array in case of error
|
|
31
|
+
}
|
|
32
|
+
};
|
|
2
33
|
/**
|
|
3
34
|
* @category Indexer Grpc Transformer
|
|
4
35
|
*/
|
|
@@ -280,4 +311,163 @@ export class IndexerGrpcExplorerTransformer {
|
|
|
280
311
|
txsPerSecondInPast100Blocks: response.txsPs100B,
|
|
281
312
|
};
|
|
282
313
|
}
|
|
314
|
+
static getTxsV2ResponseToTxs(response) {
|
|
315
|
+
return {
|
|
316
|
+
data: response.data.map((tx) => IndexerGrpcExplorerTransformer.grpcTxV2ToTransaction(tx)),
|
|
317
|
+
paging: response.paging,
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
static grpcTxV2ToTransaction(tx) {
|
|
321
|
+
let logs = [];
|
|
322
|
+
try {
|
|
323
|
+
const rawLogs = Buffer.from(tx.logs).toString('utf8');
|
|
324
|
+
logs = JSON.parse(rawLogs || '[]');
|
|
325
|
+
}
|
|
326
|
+
catch (e) {
|
|
327
|
+
console.error('Failed to parse logs');
|
|
328
|
+
logs = [];
|
|
329
|
+
}
|
|
330
|
+
const txType = JSON.parse(Buffer.from(tx.txMsgTypes).toString('utf8'));
|
|
331
|
+
const signatures = tx.signatures.map((signature) => ({
|
|
332
|
+
address: signature.address,
|
|
333
|
+
pubkey: signature.pubkey,
|
|
334
|
+
signature: signature.signature,
|
|
335
|
+
sequence: (() => {
|
|
336
|
+
try {
|
|
337
|
+
return parseInt(signature.sequence, 10);
|
|
338
|
+
}
|
|
339
|
+
catch (e) {
|
|
340
|
+
console.error('Failed to parse signature sequence:', e);
|
|
341
|
+
return 0;
|
|
342
|
+
}
|
|
343
|
+
})(),
|
|
344
|
+
}));
|
|
345
|
+
const claimIds = tx.claimIds.map((claimId) => {
|
|
346
|
+
try {
|
|
347
|
+
return parseInt(claimId, 10);
|
|
348
|
+
}
|
|
349
|
+
catch (e) {
|
|
350
|
+
console.error('Failed to parse claimId:', e);
|
|
351
|
+
return 0;
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
let messages = [];
|
|
355
|
+
try {
|
|
356
|
+
messages = transactionV2MessagesToMessages(tx.messages);
|
|
357
|
+
}
|
|
358
|
+
catch (e) {
|
|
359
|
+
console.error('Failed to parse messages:', e);
|
|
360
|
+
messages = [];
|
|
361
|
+
}
|
|
362
|
+
const blockNumber = parseInt(tx.blockNumber);
|
|
363
|
+
return {
|
|
364
|
+
logs,
|
|
365
|
+
info: '',
|
|
366
|
+
memo: '',
|
|
367
|
+
txType,
|
|
368
|
+
claimIds,
|
|
369
|
+
messages,
|
|
370
|
+
id: tx.id,
|
|
371
|
+
signatures,
|
|
372
|
+
blockNumber,
|
|
373
|
+
gasUsed: 0,
|
|
374
|
+
gasWanted: 0,
|
|
375
|
+
hash: tx.hash,
|
|
376
|
+
code: tx.code,
|
|
377
|
+
errorLog: tx.errorLog,
|
|
378
|
+
codespace: tx.codespace,
|
|
379
|
+
blockTimestamp: tx.blockTimestamp,
|
|
380
|
+
gasFee: { amounts: [], gasLimit: 0, granter: '', payer: '' },
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
static getAccountTxsV2ResponseToAccountTxs(response) {
|
|
384
|
+
return {
|
|
385
|
+
data: response.data.map((tx) => IndexerGrpcExplorerTransformer.grpcAccountTxV2ToTransaction(tx)),
|
|
386
|
+
paging: response.paging,
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
static grpcAccountTxV2ToTransaction(tx) {
|
|
390
|
+
return {
|
|
391
|
+
id: tx.id,
|
|
392
|
+
hash: tx.hash,
|
|
393
|
+
code: tx.code,
|
|
394
|
+
info: tx.info,
|
|
395
|
+
memo: tx.memo,
|
|
396
|
+
txType: tx.txType,
|
|
397
|
+
gasFee: {
|
|
398
|
+
amounts: (tx.gasFee?.amount || []).map((amount) => ({
|
|
399
|
+
amount: amount.amount,
|
|
400
|
+
denom: amount.denom,
|
|
401
|
+
})),
|
|
402
|
+
gasLimit: parseInt(tx.gasFee?.gasLimit ?? '0', 10),
|
|
403
|
+
granter: tx.gasFee?.granter ?? '',
|
|
404
|
+
payer: tx.gasFee?.payer ?? '',
|
|
405
|
+
},
|
|
406
|
+
events: tx.events,
|
|
407
|
+
errorLog: tx.errorLog,
|
|
408
|
+
codespace: tx.codespace,
|
|
409
|
+
gasUsed: parseInt(tx.gasUsed, 10),
|
|
410
|
+
blockTimestamp: tx.blockTimestamp,
|
|
411
|
+
gasWanted: parseInt(tx.gasWanted, 10),
|
|
412
|
+
blockNumber: parseInt(tx.blockNumber, 10),
|
|
413
|
+
signatures: tx.signatures.map((signature) => ({
|
|
414
|
+
address: signature.address,
|
|
415
|
+
pubkey: signature.pubkey,
|
|
416
|
+
signature: signature.signature,
|
|
417
|
+
sequence: parseInt(signature.sequence, 10),
|
|
418
|
+
})),
|
|
419
|
+
messages: transactionV2MessagesToMessages(tx.messages),
|
|
420
|
+
logs: JSON.parse(Buffer.from(tx.logs).toString('utf8')),
|
|
421
|
+
data: '/' + Buffer.from(tx.data).toString('utf8').split('/').pop(),
|
|
422
|
+
claimIds: tx.claimIds.map((claimId) => parseInt(claimId, 10)),
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
static getBlocksV2ResponseToBlocks(response) {
|
|
426
|
+
return {
|
|
427
|
+
paging: response.paging,
|
|
428
|
+
data: response.data.map((block) => IndexerGrpcExplorerTransformer.grpcBlockV2ToBlock(block)),
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
static grpcBlockV2ToBlock(block) {
|
|
432
|
+
return {
|
|
433
|
+
moniker: block.moniker,
|
|
434
|
+
proposer: block.proposer,
|
|
435
|
+
blockHash: block.blockHash,
|
|
436
|
+
timestamp: block.timestamp,
|
|
437
|
+
parentHash: block.parentHash,
|
|
438
|
+
height: parseInt(block.height, 10),
|
|
439
|
+
numTxs: parseInt(block.numTxs, 10),
|
|
440
|
+
numPreCommits: parseInt(block.numPreCommits, 10),
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
static getContractTxsV2ResponseToContractTxs(response) {
|
|
444
|
+
return {
|
|
445
|
+
data: response.data.map((tx) => IndexerGrpcExplorerTransformer.grpcContractTxV2ToTransaction(tx)),
|
|
446
|
+
paging: response.paging,
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
static grpcContractTxV2ToTransaction(tx) {
|
|
450
|
+
const messages = transactionV2MessagesToMessages(tx.messages);
|
|
451
|
+
return {
|
|
452
|
+
messages,
|
|
453
|
+
code: tx.code,
|
|
454
|
+
memo: tx.memo,
|
|
455
|
+
type: tx.txType,
|
|
456
|
+
txHash: tx.hash,
|
|
457
|
+
error_log: tx.errorLog,
|
|
458
|
+
height: parseInt(tx.blockNumber, 10),
|
|
459
|
+
tx_number: parseInt(tx.txNumber, 10),
|
|
460
|
+
time: parseInt(tx.blockTimestamp, 10),
|
|
461
|
+
amount: getContractTransactionV2Amount(tx),
|
|
462
|
+
logs: JSON.parse(Buffer.from(tx.logs).toString('utf8')),
|
|
463
|
+
data: '/' + Buffer.from(tx.data).toString('utf8').split('/').pop(),
|
|
464
|
+
fee: new BigNumberInWei(tx.gasFee?.amount[0]?.amount || '0').toBase(),
|
|
465
|
+
signatures: tx.signatures.map((signature) => ({
|
|
466
|
+
address: signature.address,
|
|
467
|
+
pubkey: signature.pubkey,
|
|
468
|
+
signature: signature.signature,
|
|
469
|
+
sequence: parseInt(signature.sequence, 10),
|
|
470
|
+
})),
|
|
471
|
+
};
|
|
472
|
+
}
|
|
283
473
|
}
|
|
@@ -352,6 +352,26 @@ export interface ExplorerStats {
|
|
|
352
352
|
txsPerSecondInPast24Hours: string;
|
|
353
353
|
txsPerSecondInPast100Blocks: string;
|
|
354
354
|
}
|
|
355
|
+
export interface ExplorerTxsV2Response {
|
|
356
|
+
data: ExplorerTransactionV2[];
|
|
357
|
+
paging?: InjectiveExplorerRpc.Cursor;
|
|
358
|
+
}
|
|
359
|
+
export interface ExplorerTransactionV2 {
|
|
360
|
+
logs: any;
|
|
361
|
+
id: string;
|
|
362
|
+
code: number;
|
|
363
|
+
hash: string;
|
|
364
|
+
messages: any;
|
|
365
|
+
txNumber: number;
|
|
366
|
+
errorLog?: string;
|
|
367
|
+
codespace: string;
|
|
368
|
+
claimIds: string[];
|
|
369
|
+
blockNumber: number;
|
|
370
|
+
txMsgTypes: string[];
|
|
371
|
+
blockTimestamp: number;
|
|
372
|
+
blockUnixTimestamp: number;
|
|
373
|
+
signatures: InjectiveExplorerRpc.Signature[];
|
|
374
|
+
}
|
|
355
375
|
export type GrpcIBCTransferTx = InjectiveExplorerRpc.IBCTransferTx;
|
|
356
376
|
export type GrpcPeggyDepositTx = InjectiveExplorerRpc.PeggyDepositTx;
|
|
357
377
|
export type GrpcPeggyWithdrawalTx = InjectiveExplorerRpc.PeggyWithdrawalTx;
|
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.
|
|
4
|
+
"version": "1.15.17",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"author": {
|
|
@@ -124,16 +124,16 @@
|
|
|
124
124
|
"@ethersproject/bytes": "^5.8.0",
|
|
125
125
|
"@injectivelabs/abacus-proto-ts": "1.14.0",
|
|
126
126
|
"@injectivelabs/core-proto-ts": "1.14.3",
|
|
127
|
-
"@injectivelabs/exceptions": "^1.15.
|
|
127
|
+
"@injectivelabs/exceptions": "^1.15.14",
|
|
128
128
|
"@injectivelabs/grpc-web": "^0.0.1",
|
|
129
129
|
"@injectivelabs/grpc-web-node-http-transport": "^0.0.2",
|
|
130
130
|
"@injectivelabs/grpc-web-react-native-transport": "^0.0.2",
|
|
131
|
-
"@injectivelabs/indexer-proto-ts": "1.13.
|
|
131
|
+
"@injectivelabs/indexer-proto-ts": "1.13.12",
|
|
132
132
|
"@injectivelabs/mito-proto-ts": "1.13.2",
|
|
133
|
-
"@injectivelabs/networks": "^1.15.
|
|
133
|
+
"@injectivelabs/networks": "^1.15.15",
|
|
134
134
|
"@injectivelabs/olp-proto-ts": "1.13.4",
|
|
135
|
-
"@injectivelabs/ts-types": "^1.15.
|
|
136
|
-
"@injectivelabs/utils": "^1.15.
|
|
135
|
+
"@injectivelabs/ts-types": "^1.15.15",
|
|
136
|
+
"@injectivelabs/utils": "^1.15.15",
|
|
137
137
|
"@metamask/eth-sig-util": "^8.2.0",
|
|
138
138
|
"@noble/curves": "^1.8.1",
|
|
139
139
|
"@noble/hashes": "^1.7.1",
|
|
@@ -152,7 +152,7 @@
|
|
|
152
152
|
"shx": "^0.3.4",
|
|
153
153
|
"snakecase-keys": "^5.4.1"
|
|
154
154
|
},
|
|
155
|
-
"gitHead": "
|
|
155
|
+
"gitHead": "2f3036b124dd1d178fd354b0b37352700f9b060c",
|
|
156
156
|
"typedoc": {
|
|
157
157
|
"entryPoint": "./src/index.ts",
|
|
158
158
|
"readmeFile": "./README.md",
|