@firmachain/firma-js 0.4.0-beta1 → 0.4.0-beta2
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.
|
@@ -32,6 +32,10 @@ export declare class FirmaStakingService {
|
|
|
32
32
|
getDelegationInfoFromValidator(address: string, validatorAddress: string): Promise<DelegationInfo>;
|
|
33
33
|
getTotalUndelegateInfo(address: string): Promise<UndelegationInfo[]>;
|
|
34
34
|
getTotalRedelegationInfo(address: string): Promise<RedelegationInfo[]>;
|
|
35
|
+
getRedelegationListFromValidator(valoperAddress: string, paginationKey?: string): Promise<{
|
|
36
|
+
dataList: RedelegationInfo[];
|
|
37
|
+
pagination: Pagination;
|
|
38
|
+
}>;
|
|
35
39
|
getUndelegationListFromValidator(valoperAddress: string, paginationKey?: string): Promise<{
|
|
36
40
|
dataList: UndelegationInfo[];
|
|
37
41
|
pagination: Pagination;
|
|
@@ -465,7 +465,7 @@ var FirmaStakingService = /** @class */ (function () {
|
|
|
465
465
|
});
|
|
466
466
|
});
|
|
467
467
|
};
|
|
468
|
-
FirmaStakingService.prototype.
|
|
468
|
+
FirmaStakingService.prototype.getRedelegationListFromValidator = function (valoperAddress, paginationKey) {
|
|
469
469
|
if (paginationKey === void 0) { paginationKey = ""; }
|
|
470
470
|
return __awaiter(this, void 0, void 0, function () {
|
|
471
471
|
var queryClient, result, error_18;
|
|
@@ -474,7 +474,7 @@ var FirmaStakingService = /** @class */ (function () {
|
|
|
474
474
|
case 0:
|
|
475
475
|
_a.trys.push([0, 2, , 3]);
|
|
476
476
|
queryClient = new staking_1.StakingQueryClient(this.config.restApiAddress);
|
|
477
|
-
return [4 /*yield*/, queryClient.
|
|
477
|
+
return [4 /*yield*/, queryClient.queryGetRedelegationListFromValidator(valoperAddress, paginationKey)];
|
|
478
478
|
case 1:
|
|
479
479
|
result = _a.sent();
|
|
480
480
|
return [2 /*return*/, result];
|
|
@@ -487,7 +487,7 @@ var FirmaStakingService = /** @class */ (function () {
|
|
|
487
487
|
});
|
|
488
488
|
});
|
|
489
489
|
};
|
|
490
|
-
FirmaStakingService.prototype.
|
|
490
|
+
FirmaStakingService.prototype.getUndelegationListFromValidator = function (valoperAddress, paginationKey) {
|
|
491
491
|
if (paginationKey === void 0) { paginationKey = ""; }
|
|
492
492
|
return __awaiter(this, void 0, void 0, function () {
|
|
493
493
|
var queryClient, result, error_19;
|
|
@@ -496,7 +496,7 @@ var FirmaStakingService = /** @class */ (function () {
|
|
|
496
496
|
case 0:
|
|
497
497
|
_a.trys.push([0, 2, , 3]);
|
|
498
498
|
queryClient = new staking_1.StakingQueryClient(this.config.restApiAddress);
|
|
499
|
-
return [4 /*yield*/, queryClient.
|
|
499
|
+
return [4 /*yield*/, queryClient.queryGetUndelegationListFromValidator(valoperAddress, paginationKey)];
|
|
500
500
|
case 1:
|
|
501
501
|
result = _a.sent();
|
|
502
502
|
return [2 /*return*/, result];
|
|
@@ -509,7 +509,7 @@ var FirmaStakingService = /** @class */ (function () {
|
|
|
509
509
|
});
|
|
510
510
|
});
|
|
511
511
|
};
|
|
512
|
-
FirmaStakingService.prototype.
|
|
512
|
+
FirmaStakingService.prototype.getDelegationListFromValidator = function (valoperAddress, paginationKey) {
|
|
513
513
|
if (paginationKey === void 0) { paginationKey = ""; }
|
|
514
514
|
return __awaiter(this, void 0, void 0, function () {
|
|
515
515
|
var queryClient, result, error_20;
|
|
@@ -518,7 +518,7 @@ var FirmaStakingService = /** @class */ (function () {
|
|
|
518
518
|
case 0:
|
|
519
519
|
_a.trys.push([0, 2, , 3]);
|
|
520
520
|
queryClient = new staking_1.StakingQueryClient(this.config.restApiAddress);
|
|
521
|
-
return [4 /*yield*/, queryClient.
|
|
521
|
+
return [4 /*yield*/, queryClient.queryGetDelegateListFromValidator(valoperAddress, paginationKey)];
|
|
522
522
|
case 1:
|
|
523
523
|
result = _a.sent();
|
|
524
524
|
return [2 /*return*/, result];
|
|
@@ -531,7 +531,8 @@ var FirmaStakingService = /** @class */ (function () {
|
|
|
531
531
|
});
|
|
532
532
|
});
|
|
533
533
|
};
|
|
534
|
-
FirmaStakingService.prototype.
|
|
534
|
+
FirmaStakingService.prototype.getTotalDelegationInfo = function (address, paginationKey) {
|
|
535
|
+
if (paginationKey === void 0) { paginationKey = ""; }
|
|
535
536
|
return __awaiter(this, void 0, void 0, function () {
|
|
536
537
|
var queryClient, result, error_21;
|
|
537
538
|
return __generator(this, function (_a) {
|
|
@@ -539,7 +540,7 @@ var FirmaStakingService = /** @class */ (function () {
|
|
|
539
540
|
case 0:
|
|
540
541
|
_a.trys.push([0, 2, , 3]);
|
|
541
542
|
queryClient = new staking_1.StakingQueryClient(this.config.restApiAddress);
|
|
542
|
-
return [4 /*yield*/, queryClient.
|
|
543
|
+
return [4 /*yield*/, queryClient.queryGetTotalDelegationInfo(address, paginationKey)];
|
|
543
544
|
case 1:
|
|
544
545
|
result = _a.sent();
|
|
545
546
|
return [2 /*return*/, result];
|
|
@@ -552,9 +553,30 @@ var FirmaStakingService = /** @class */ (function () {
|
|
|
552
553
|
});
|
|
553
554
|
});
|
|
554
555
|
};
|
|
555
|
-
FirmaStakingService.prototype.
|
|
556
|
+
FirmaStakingService.prototype.getParams = function () {
|
|
556
557
|
return __awaiter(this, void 0, void 0, function () {
|
|
557
558
|
var queryClient, result, error_22;
|
|
559
|
+
return __generator(this, function (_a) {
|
|
560
|
+
switch (_a.label) {
|
|
561
|
+
case 0:
|
|
562
|
+
_a.trys.push([0, 2, , 3]);
|
|
563
|
+
queryClient = new staking_1.StakingQueryClient(this.config.restApiAddress);
|
|
564
|
+
return [4 /*yield*/, queryClient.queryGetParams()];
|
|
565
|
+
case 1:
|
|
566
|
+
result = _a.sent();
|
|
567
|
+
return [2 /*return*/, result];
|
|
568
|
+
case 2:
|
|
569
|
+
error_22 = _a.sent();
|
|
570
|
+
FirmaUtil_1.FirmaUtil.printLog(error_22);
|
|
571
|
+
throw error_22;
|
|
572
|
+
case 3: return [2 /*return*/];
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
});
|
|
576
|
+
};
|
|
577
|
+
FirmaStakingService.prototype.getParamsAsStakingParams = function () {
|
|
578
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
579
|
+
var queryClient, result, error_23;
|
|
558
580
|
return __generator(this, function (_a) {
|
|
559
581
|
switch (_a.label) {
|
|
560
582
|
case 0:
|
|
@@ -572,9 +594,9 @@ var FirmaStakingService = /** @class */ (function () {
|
|
|
572
594
|
minCommissionRate: result.min_commission_rate
|
|
573
595
|
}];
|
|
574
596
|
case 2:
|
|
575
|
-
|
|
576
|
-
FirmaUtil_1.FirmaUtil.printLog(
|
|
577
|
-
throw
|
|
597
|
+
error_23 = _a.sent();
|
|
598
|
+
FirmaUtil_1.FirmaUtil.printLog(error_23);
|
|
599
|
+
throw error_23;
|
|
578
600
|
case 3: return [2 /*return*/];
|
|
579
601
|
}
|
|
580
602
|
});
|
|
@@ -582,7 +604,7 @@ var FirmaStakingService = /** @class */ (function () {
|
|
|
582
604
|
};
|
|
583
605
|
FirmaStakingService.prototype.getPool = function () {
|
|
584
606
|
return __awaiter(this, void 0, void 0, function () {
|
|
585
|
-
var queryClient, result,
|
|
607
|
+
var queryClient, result, error_24;
|
|
586
608
|
return __generator(this, function (_a) {
|
|
587
609
|
switch (_a.label) {
|
|
588
610
|
case 0:
|
|
@@ -593,9 +615,9 @@ var FirmaStakingService = /** @class */ (function () {
|
|
|
593
615
|
result = _a.sent();
|
|
594
616
|
return [2 /*return*/, result];
|
|
595
617
|
case 2:
|
|
596
|
-
|
|
597
|
-
FirmaUtil_1.FirmaUtil.printLog(
|
|
598
|
-
throw
|
|
618
|
+
error_24 = _a.sent();
|
|
619
|
+
FirmaUtil_1.FirmaUtil.printLog(error_24);
|
|
620
|
+
throw error_24;
|
|
599
621
|
case 3: return [2 /*return*/];
|
|
600
622
|
}
|
|
601
623
|
});
|
|
@@ -603,7 +625,7 @@ var FirmaStakingService = /** @class */ (function () {
|
|
|
603
625
|
};
|
|
604
626
|
FirmaStakingService.prototype.getValidator = function (valoperAddress) {
|
|
605
627
|
return __awaiter(this, void 0, void 0, function () {
|
|
606
|
-
var queryClient, result,
|
|
628
|
+
var queryClient, result, error_25;
|
|
607
629
|
return __generator(this, function (_a) {
|
|
608
630
|
switch (_a.label) {
|
|
609
631
|
case 0:
|
|
@@ -614,9 +636,9 @@ var FirmaStakingService = /** @class */ (function () {
|
|
|
614
636
|
result = _a.sent();
|
|
615
637
|
return [2 /*return*/, result];
|
|
616
638
|
case 2:
|
|
617
|
-
|
|
618
|
-
FirmaUtil_1.FirmaUtil.printLog(
|
|
619
|
-
throw
|
|
639
|
+
error_25 = _a.sent();
|
|
640
|
+
FirmaUtil_1.FirmaUtil.printLog(error_25);
|
|
641
|
+
throw error_25;
|
|
620
642
|
case 3: return [2 /*return*/];
|
|
621
643
|
}
|
|
622
644
|
});
|
|
@@ -626,7 +648,7 @@ var FirmaStakingService = /** @class */ (function () {
|
|
|
626
648
|
if (status === void 0) { status = StakingValidatorStatus.ALL; }
|
|
627
649
|
if (paginationKey === void 0) { paginationKey = ""; }
|
|
628
650
|
return __awaiter(this, void 0, void 0, function () {
|
|
629
|
-
var queryClient, result,
|
|
651
|
+
var queryClient, result, error_26;
|
|
630
652
|
return __generator(this, function (_a) {
|
|
631
653
|
switch (_a.label) {
|
|
632
654
|
case 0:
|
|
@@ -637,9 +659,9 @@ var FirmaStakingService = /** @class */ (function () {
|
|
|
637
659
|
result = _a.sent();
|
|
638
660
|
return [2 /*return*/, result];
|
|
639
661
|
case 2:
|
|
640
|
-
|
|
641
|
-
FirmaUtil_1.FirmaUtil.printLog(
|
|
642
|
-
throw
|
|
662
|
+
error_26 = _a.sent();
|
|
663
|
+
FirmaUtil_1.FirmaUtil.printLog(error_26);
|
|
664
|
+
throw error_26;
|
|
643
665
|
case 3: return [2 /*return*/];
|
|
644
666
|
}
|
|
645
667
|
});
|
|
@@ -85,6 +85,21 @@ export declare class StakingQueryClient {
|
|
|
85
85
|
queryGetDelegationInfoFromValidator(address: string, validatorAddress: string): Promise<DelegationInfo>;
|
|
86
86
|
queryGetTotalUndelegateInfo(address: string): Promise<UndelegationInfo[]>;
|
|
87
87
|
querygetTotalRedelegationInfo(address: string): Promise<RedelegationInfo[]>;
|
|
88
|
+
/**
|
|
89
|
+
* Returns redelegations involving the given validator (as src or dst), aggregated
|
|
90
|
+
* across all delegators. The Cosmos SDK's gRPC `Redelegations` query accepts an
|
|
91
|
+
* empty `delegator_addr` together with `src_validator_addr` (or
|
|
92
|
+
* `dst_validator_addr`) to fetch chain-wide redelegations from / to a validator;
|
|
93
|
+
* this method exposes that capability through the standard REST URL with an
|
|
94
|
+
* empty delegator path segment.
|
|
95
|
+
*
|
|
96
|
+
* Two requests are issued (src filter + dst filter) and the results are merged
|
|
97
|
+
* with deduplication.
|
|
98
|
+
*/
|
|
99
|
+
queryGetRedelegationListFromValidator(valoperAddress: string, paginationKey?: string): Promise<{
|
|
100
|
+
dataList: RedelegationInfo[];
|
|
101
|
+
pagination: Pagination;
|
|
102
|
+
}>;
|
|
88
103
|
queryGetUndelegationListFromValidator(valoperAddress: string, paginationKey?: string): Promise<{
|
|
89
104
|
dataList: UndelegationInfo[];
|
|
90
105
|
pagination: Pagination;
|
|
@@ -35,6 +35,42 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
39
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
40
|
+
if (!m) return o;
|
|
41
|
+
var i = m.call(o), r, ar = [], e;
|
|
42
|
+
try {
|
|
43
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
44
|
+
}
|
|
45
|
+
catch (error) { e = { error: error }; }
|
|
46
|
+
finally {
|
|
47
|
+
try {
|
|
48
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
49
|
+
}
|
|
50
|
+
finally { if (e) throw e.error; }
|
|
51
|
+
}
|
|
52
|
+
return ar;
|
|
53
|
+
};
|
|
54
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
55
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
56
|
+
if (ar || !(i in from)) {
|
|
57
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
58
|
+
ar[i] = from[i];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
62
|
+
};
|
|
63
|
+
var __values = (this && this.__values) || function(o) {
|
|
64
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
65
|
+
if (m) return m.call(o);
|
|
66
|
+
if (o && typeof o.length === "number") return {
|
|
67
|
+
next: function () {
|
|
68
|
+
if (o && i >= o.length) o = void 0;
|
|
69
|
+
return { value: o && o[i++], done: !o };
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
73
|
+
};
|
|
38
74
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
75
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
76
|
};
|
|
@@ -113,6 +149,79 @@ var StakingQueryClient = /** @class */ (function () {
|
|
|
113
149
|
});
|
|
114
150
|
});
|
|
115
151
|
};
|
|
152
|
+
/**
|
|
153
|
+
* Returns redelegations involving the given validator (as src or dst), aggregated
|
|
154
|
+
* across all delegators. The Cosmos SDK's gRPC `Redelegations` query accepts an
|
|
155
|
+
* empty `delegator_addr` together with `src_validator_addr` (or
|
|
156
|
+
* `dst_validator_addr`) to fetch chain-wide redelegations from / to a validator;
|
|
157
|
+
* this method exposes that capability through the standard REST URL with an
|
|
158
|
+
* empty delegator path segment.
|
|
159
|
+
*
|
|
160
|
+
* Two requests are issued (src filter + dst filter) and the results are merged
|
|
161
|
+
* with deduplication.
|
|
162
|
+
*/
|
|
163
|
+
StakingQueryClient.prototype.queryGetRedelegationListFromValidator = function (valoperAddress, paginationKey) {
|
|
164
|
+
if (paginationKey === void 0) { paginationKey = ""; }
|
|
165
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
166
|
+
var path, fetchByFilter, _a, fromList, toList, seen, merged, _b, _c, r, k;
|
|
167
|
+
var e_1, _d;
|
|
168
|
+
var _this = this;
|
|
169
|
+
return __generator(this, function (_e) {
|
|
170
|
+
switch (_e.label) {
|
|
171
|
+
case 0:
|
|
172
|
+
path = "/cosmos/staking/v1beta1/delegators//redelegations";
|
|
173
|
+
fetchByFilter = function (filterKey) { return __awaiter(_this, void 0, void 0, function () {
|
|
174
|
+
var params, result;
|
|
175
|
+
var _a;
|
|
176
|
+
return __generator(this, function (_b) {
|
|
177
|
+
switch (_b.label) {
|
|
178
|
+
case 0:
|
|
179
|
+
params = (_a = {},
|
|
180
|
+
_a[filterKey] = valoperAddress,
|
|
181
|
+
_a["pagination.limit"] = 1000,
|
|
182
|
+
_a);
|
|
183
|
+
if (paginationKey)
|
|
184
|
+
params["pagination.key"] = paginationKey;
|
|
185
|
+
return [4 /*yield*/, this.axios.get(path, { params: params })];
|
|
186
|
+
case 1:
|
|
187
|
+
result = _b.sent();
|
|
188
|
+
return [2 /*return*/, result.data.redelegation_responses || []];
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}); };
|
|
192
|
+
return [4 /*yield*/, Promise.all([
|
|
193
|
+
fetchByFilter('src_validator_addr'),
|
|
194
|
+
fetchByFilter('dst_validator_addr'),
|
|
195
|
+
])];
|
|
196
|
+
case 1:
|
|
197
|
+
_a = __read.apply(void 0, [_e.sent(), 2]), fromList = _a[0], toList = _a[1];
|
|
198
|
+
seen = new Set();
|
|
199
|
+
merged = [];
|
|
200
|
+
try {
|
|
201
|
+
for (_b = __values(__spreadArray(__spreadArray([], __read(fromList), false), __read(toList), false)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
202
|
+
r = _c.value;
|
|
203
|
+
k = "".concat(r.redelegation.delegator_address, "|").concat(r.redelegation.validator_src_address, "|").concat(r.redelegation.validator_dst_address);
|
|
204
|
+
if (seen.has(k))
|
|
205
|
+
continue;
|
|
206
|
+
seen.add(k);
|
|
207
|
+
merged.push(r);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
211
|
+
finally {
|
|
212
|
+
try {
|
|
213
|
+
if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
|
|
214
|
+
}
|
|
215
|
+
finally { if (e_1) throw e_1.error; }
|
|
216
|
+
}
|
|
217
|
+
return [2 /*return*/, {
|
|
218
|
+
dataList: merged,
|
|
219
|
+
pagination: { next_key: '', total: merged.length },
|
|
220
|
+
}];
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
};
|
|
116
225
|
StakingQueryClient.prototype.queryGetUndelegationListFromValidator = function (valoperAddress, paginationKey) {
|
|
117
226
|
if (paginationKey === void 0) { paginationKey = ""; }
|
|
118
227
|
return __awaiter(this, void 0, void 0, function () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firmachain/firma-js",
|
|
3
|
-
"version": "0.4.0-
|
|
3
|
+
"version": "0.4.0-beta2",
|
|
4
4
|
"description": "The Official FirmaChain Javascript SDK written in Typescript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"nodemon": "nodemon",
|
|
15
15
|
"dev": "ts-node ./test/test_index.ts",
|
|
16
16
|
"clean": "rm -rf dist",
|
|
17
|
-
"build": "npm run clean && tsc --module commonjs"
|
|
17
|
+
"build": "npm run clean && tsc --module commonjs",
|
|
18
|
+
"prepare": "npm run build"
|
|
18
19
|
},
|
|
19
20
|
"repository": {
|
|
20
21
|
"type": "git",
|