@substrate/api-sidecar 14.2.2 → 14.3.0
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/README.md +9 -5
- package/build/package.json +20 -22
- package/build/src/SidecarConfig.js +4 -0
- package/build/src/SidecarConfig.js.map +1 -1
- package/build/src/Specs.js +26 -0
- package/build/src/Specs.js.map +1 -1
- package/build/src/chains-config/astarControllers.js +1 -0
- package/build/src/chains-config/astarControllers.js.map +1 -1
- package/build/src/chains-config/defaultControllers.js +1 -0
- package/build/src/chains-config/defaultControllers.js.map +1 -1
- package/build/src/chains-config/kusamaControllers.js +3 -0
- package/build/src/chains-config/kusamaControllers.js.map +1 -1
- package/build/src/chains-config/polkadotControllers.js +3 -0
- package/build/src/chains-config/polkadotControllers.js.map +1 -1
- package/build/src/chains-config/statemineControllers.js +1 -0
- package/build/src/chains-config/statemineControllers.js.map +1 -1
- package/build/src/chains-config/statemintControllers.js +1 -0
- package/build/src/chains-config/statemintControllers.js.map +1 -1
- package/build/src/chains-config/westendControllers.js +3 -0
- package/build/src/chains-config/westendControllers.js.map +1 -1
- package/build/src/controllers/AbstractController.d.ts +1 -1
- package/build/src/controllers/AbstractController.js.map +1 -1
- package/build/src/controllers/index.d.ts +4 -1
- package/build/src/controllers/index.js +3 -0
- package/build/src/controllers/index.js.map +1 -1
- package/build/src/controllers/pallets/PalletsErrorsController.d.ts +20 -0
- package/build/src/controllers/pallets/PalletsErrorsController.js +70 -0
- package/build/src/controllers/pallets/PalletsErrorsController.js.map +1 -0
- package/build/src/controllers/pallets/PalletsNominationPoolsController.d.ts +9 -0
- package/build/src/controllers/pallets/PalletsNominationPoolsController.js +50 -0
- package/build/src/controllers/pallets/PalletsNominationPoolsController.js.map +1 -0
- package/build/src/controllers/pallets/PalletsStakingValidatorsController.d.ts +14 -0
- package/build/src/controllers/pallets/PalletsStakingValidatorsController.js +43 -0
- package/build/src/controllers/pallets/PalletsStakingValidatorsController.js.map +1 -0
- package/build/src/controllers/pallets/index.d.ts +3 -0
- package/build/src/controllers/pallets/index.js +7 -1
- package/build/src/controllers/pallets/index.js.map +1 -1
- package/build/src/controllers/paras/ParasController.d.ts +2 -0
- package/build/src/controllers/paras/ParasController.js +10 -0
- package/build/src/controllers/paras/ParasController.js.map +1 -1
- package/build/src/controllers/transaction/TransactionMaterialController.d.ts +1 -1
- package/build/src/logging/Log.js +7 -1
- package/build/src/logging/Log.js.map +1 -1
- package/build/src/logging/transports/fileTransport.d.ts +2 -0
- package/build/src/logging/transports/fileTransport.js +16 -0
- package/build/src/logging/transports/fileTransport.js.map +1 -0
- package/build/src/logging/transports/index.d.ts +1 -0
- package/build/src/logging/transports/index.js +1 -0
- package/build/src/logging/transports/index.js.map +1 -1
- package/build/src/services/AbstractPalletsService.d.ts +33 -0
- package/build/src/services/AbstractPalletsService.js +176 -0
- package/build/src/services/AbstractPalletsService.js.map +1 -0
- package/build/src/services/accounts/AccountsStakingPayoutsService.d.ts +1 -1
- package/build/src/services/blocks/trace/Trace.d.ts +1 -1
- package/build/src/services/blocks/trace/types.d.ts +2 -2
- package/build/src/services/node/NodeTransactionPoolService.js +12 -4
- package/build/src/services/node/NodeTransactionPoolService.js.map +1 -1
- package/build/src/services/node/NodeTransactionPoolService.spec.js +0 -2
- package/build/src/services/node/NodeTransactionPoolService.spec.js.map +1 -1
- package/build/src/services/pallets/PalletsErrorsService.d.ts +19 -0
- package/build/src/services/pallets/PalletsErrorsService.js +78 -0
- package/build/src/services/pallets/PalletsErrorsService.js.map +1 -0
- package/build/src/services/pallets/PalletsErrorsService.spec.d.ts +1 -0
- package/build/src/services/pallets/PalletsErrorsService.spec.js +95 -0
- package/build/src/services/pallets/PalletsErrorsService.spec.js.map +1 -0
- package/build/src/services/pallets/PalletsNominationPoolsService.d.ts +21 -0
- package/build/src/services/pallets/PalletsNominationPoolsService.js +108 -0
- package/build/src/services/pallets/PalletsNominationPoolsService.js.map +1 -0
- package/build/src/services/pallets/PalletsNominationPoolsService.spec.d.ts +1 -0
- package/build/src/services/pallets/PalletsNominationPoolsService.spec.js +138 -0
- package/build/src/services/pallets/PalletsNominationPoolsService.spec.js.map +1 -0
- package/build/src/services/pallets/PalletsStakingValidatorsService.d.ts +14 -0
- package/build/src/services/pallets/PalletsStakingValidatorsService.js +55 -0
- package/build/src/services/pallets/PalletsStakingValidatorsService.js.map +1 -0
- package/build/src/services/pallets/PalletsStorageService.d.ts +2 -23
- package/build/src/services/pallets/PalletsStorageService.js +8 -108
- package/build/src/services/pallets/PalletsStorageService.js.map +1 -1
- package/build/src/services/pallets/index.d.ts +3 -0
- package/build/src/services/pallets/index.js +3 -0
- package/build/src/services/pallets/index.js.map +1 -1
- package/build/src/services/paras/ParasService.d.ts +8 -1
- package/build/src/services/paras/ParasService.js +35 -0
- package/build/src/services/paras/ParasService.js.map +1 -1
- package/build/src/services/paras/ParasService.spec.js +20 -0
- package/build/src/services/paras/ParasService.spec.js.map +1 -1
- package/build/src/services/transaction/TransactionFeeEstimateService.spec.js +1 -1
- package/build/src/services/transaction/TransactionFeeEstimateService.spec.js.map +1 -1
- package/build/src/types/requests.d.ts +6 -2
- package/build/src/types/responses/PalletErrors.d.ts +10 -0
- package/build/src/types/responses/PalletErrors.js +18 -0
- package/build/src/types/responses/PalletErrors.js.map +1 -0
- package/build/src/types/responses/PalletErrorsItem.d.ts +6 -0
- package/build/src/types/responses/PalletErrorsItem.js +18 -0
- package/build/src/types/responses/PalletErrorsItem.js.map +1 -0
- package/build/src/types/responses/PalletNominationPools.d.ts +25 -0
- package/build/src/types/responses/PalletNominationPools.js +18 -0
- package/build/src/types/responses/PalletNominationPools.js.map +1 -0
- package/build/src/types/responses/PalletStakingValidators.d.ts +15 -0
- package/build/src/types/responses/PalletStakingValidators.js +18 -0
- package/build/src/types/responses/PalletStakingValidators.js.map +1 -0
- package/build/src/types/responses/Paras.d.ts +33 -4
- package/build/src/types/responses/SanitizedErrorItemMetadata.d.ts +7 -0
- package/build/src/types/responses/SanitizedErrorItemMetadata.js +18 -0
- package/build/src/types/responses/SanitizedErrorItemMetadata.js.map +1 -0
- package/build/src/types/responses/TransactionDryRun.d.ts +1 -1
- package/build/src/types/responses/index.d.ts +5 -0
- package/build/src/types/responses/index.js +5 -0
- package/build/src/types/responses/index.js.map +1 -1
- package/build/src/types/sidecar-config/CONFIG.d.ts +5 -1
- package/build/src/types/sidecar-config/CONFIG.js +4 -0
- package/build/src/types/sidecar-config/CONFIG.js.map +1 -1
- package/build/src/types/sidecar-config/SidecarConfig.d.ts +4 -0
- package/build/src/types/util/Option.d.ts +1 -1
- package/package.json +20 -22
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
|
|
3
|
+
// This file is part of Substrate API Sidecar.
|
|
4
|
+
//
|
|
5
|
+
// Substrate API Sidecar is free software: you can redistribute it and/or modify
|
|
6
|
+
// it under the terms of the GNU General Public License as published by
|
|
7
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
// (at your option) any later version.
|
|
9
|
+
//
|
|
10
|
+
// This program is distributed in the hope that it will be useful,
|
|
11
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
// GNU General Public License for more details.
|
|
14
|
+
//
|
|
15
|
+
// You should have received a copy of the GNU General Public License
|
|
16
|
+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.PalletsErrorsService = void 0;
|
|
19
|
+
const util_1 = require("@polkadot/util");
|
|
20
|
+
const AbstractPalletsService_1 = require("../AbstractPalletsService");
|
|
21
|
+
class PalletsErrorsService extends AbstractPalletsService_1.AbstractPalletsService {
|
|
22
|
+
async fetchErrorItem(historicApi, { hash, palletId, errorItemId, metadata }) {
|
|
23
|
+
const metadataFieldType = 'errors';
|
|
24
|
+
const palletMetadata = historicApi.registry.metadata;
|
|
25
|
+
const [palletMeta, palletMetaIdx] = this.findPalletMeta(palletMetadata, historicApi, palletId, metadataFieldType);
|
|
26
|
+
// Even if `errorItemMeta` is not used, we call this function to ensure it exists. The side effects
|
|
27
|
+
// of the error item not existing are that `findErrorItemMeta` will throw.
|
|
28
|
+
const errorItemMetadata = this.findPalletFieldItemMeta(historicApi, palletMeta, errorItemId, metadataFieldType);
|
|
29
|
+
let palletErrorMetadata;
|
|
30
|
+
if (metadata) {
|
|
31
|
+
palletErrorMetadata = errorItemMetadata[1].meta;
|
|
32
|
+
}
|
|
33
|
+
const { number } = await this.api.rpc.chain.getHeader(hash);
|
|
34
|
+
return {
|
|
35
|
+
at: {
|
|
36
|
+
hash: hash,
|
|
37
|
+
height: number.unwrap().toString(10),
|
|
38
|
+
},
|
|
39
|
+
pallet: (0, util_1.stringCamelCase)(palletMeta.name),
|
|
40
|
+
palletIndex: palletMetaIdx,
|
|
41
|
+
errorItem: errorItemId,
|
|
42
|
+
metadata: palletErrorMetadata,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
async fetchErrors(historicApi, { hash, palletId, onlyIds }) {
|
|
46
|
+
const metadataFieldType = 'errors';
|
|
47
|
+
const metadata = historicApi.registry.metadata;
|
|
48
|
+
const [palletMeta, palletMetaIdx] = this.findPalletMeta(metadata, historicApi, palletId, metadataFieldType);
|
|
49
|
+
const { number } = await this.api.rpc.chain.getHeader(hash);
|
|
50
|
+
const parsedPalletName = (0, util_1.stringCamelCase)(palletMeta.name.toString());
|
|
51
|
+
const errors = historicApi.errors[parsedPalletName];
|
|
52
|
+
let items;
|
|
53
|
+
if (palletMeta.errors.isEmpty) {
|
|
54
|
+
items = [];
|
|
55
|
+
}
|
|
56
|
+
else if (onlyIds) {
|
|
57
|
+
items = Object.entries(errors).map((errorItem) => errorItem[0]);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
items = [];
|
|
61
|
+
for (const [, value] of Object.entries(errors)) {
|
|
62
|
+
const item = value.meta;
|
|
63
|
+
items.push(item);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
at: {
|
|
68
|
+
hash: hash,
|
|
69
|
+
height: number.unwrap().toString(10),
|
|
70
|
+
},
|
|
71
|
+
pallet: (0, util_1.stringCamelCase)(palletMeta.name),
|
|
72
|
+
palletIndex: palletMetaIdx,
|
|
73
|
+
items,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.PalletsErrorsService = PalletsErrorsService;
|
|
78
|
+
//# sourceMappingURL=PalletsErrorsService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PalletsErrorsService.js","sourceRoot":"","sources":["../../../../src/services/pallets/PalletsErrorsService.ts"],"names":[],"mappings":";AAAA,oDAAoD;AACpD,8CAA8C;AAC9C,EAAE;AACF,gFAAgF;AAChF,uEAAuE;AACvE,oEAAoE;AACpE,sCAAsC;AACtC,EAAE;AACF,kEAAkE;AAClE,iEAAiE;AACjE,gEAAgE;AAChE,+CAA+C;AAC/C,EAAE;AACF,oEAAoE;AACpE,wEAAwE;;;AAUxE,yCAAiD;AAGjD,sEAAmE;AAYnE,MAAa,oBAAqB,SAAQ,+CAAsB;IAC/D,KAAK,CAAC,cAAc,CACnB,WAAqC,EACrC,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAuB;QAE9D,MAAM,iBAAiB,GAAG,QAAQ,CAAC;QACnC,MAAM,cAAc,GAAG,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAErD,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,IAAI,CAAC,cAAc,CACtD,cAAc,EACd,WAAW,EACX,QAAQ,EACR,iBAAiB,CACjB,CAAC;QAEF,mGAAmG;QACnG,0EAA0E;QAC1E,MAAM,iBAAiB,GAAG,IAAI,CAAC,uBAAuB,CACrD,WAAW,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U,CAAC,MAA4C,CAAC,OAAO,EAAE;YACrE,KAAK,GAAG,EAAE,CAAC;SACX;aAAM,IAAI,OAAO,EAAE;YACnB,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CACjC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,CAAoB,CAC9C,CAAC;SACF;aAAM;YACN,KAAK,GAAG,EAA2B,CAAC;YACpC,KAAK,MAAM,CAAC,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;gBAC/C,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;gBACxB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aACjB;SACD;QAED,OAAO;YACN,EAAE,EAAE;gBACH,IAAI,EAAE,IAAI;gBACV,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC;aACpC;YACD,MAAM,EAAE,IAAA,sBAAe,EAAC,UAAU,CAAC,IAAI,CAAC;YACxC,WAAW,EAAE,aAAa;YAC1B,KAAK;SACL,CAAC;IACH,CAAC;CACD;AArFD,oDAqFC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
|
|
3
|
+
// This file is part of Substrate API Sidecar.
|
|
4
|
+
//
|
|
5
|
+
// Substrate API Sidecar is free software: you can redistribute it and/or modify
|
|
6
|
+
// it under the terms of the GNU General Public License as published by
|
|
7
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
// (at your option) any later version.
|
|
9
|
+
//
|
|
10
|
+
// This program is distributed in the hope that it will be useful,
|
|
11
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
// GNU General Public License for more details.
|
|
14
|
+
//
|
|
15
|
+
// You should have received a copy of the GNU General Public License
|
|
16
|
+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
const sanitize_1 = require("../../sanitize");
|
|
22
|
+
const registries_1 = require("../../test-helpers/registries");
|
|
23
|
+
const mock_1 = require("../test-helpers/mock");
|
|
24
|
+
const mockErrorData_1 = require("../test-helpers/mock/data/mockErrorData");
|
|
25
|
+
const fetchErrorsOnlyIdsRes_json_1 = __importDefault(require("../test-helpers/responses/pallets/fetchErrorsOnlyIdsRes.json"));
|
|
26
|
+
const fetchErrorsRes_json_1 = __importDefault(require("../test-helpers/responses/pallets/fetchErrorsRes.json"));
|
|
27
|
+
const fetchInsufficientFundsErrorItem13641356_json_1 = __importDefault(require("../test-helpers/responses/pallets/fetchInsufficientFundsErrorItem13641356.json"));
|
|
28
|
+
const fetchProposalMissingErrorItem13641102_json_1 = __importDefault(require("../test-helpers/responses/pallets/fetchProposalMissingErrorItem13641102.json"));
|
|
29
|
+
const fetchValueLowErrorItem13641102_json_1 = __importDefault(require("../test-helpers/responses/pallets/fetchValueLowErrorItem13641102.json"));
|
|
30
|
+
const PalletsErrorsService_1 = require("./PalletsErrorsService");
|
|
31
|
+
const referendumInfoOfAt = () => Promise.resolve().then(() => {
|
|
32
|
+
registries_1.polkadotRegistryV9300.createType('ReferendumInfo');
|
|
33
|
+
});
|
|
34
|
+
const mockHistoricApi = {
|
|
35
|
+
registry: registries_1.polkadotRegistryV9300,
|
|
36
|
+
errors: mockErrorData_1.getPalletErrors,
|
|
37
|
+
query: {
|
|
38
|
+
democracy: {
|
|
39
|
+
referendumInfoOf: referendumInfoOfAt,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
const mockApi = {
|
|
44
|
+
...mock_1.defaultMockApi,
|
|
45
|
+
at: (_hash) => mockHistoricApi,
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Mock PalletsErrorsService instance.
|
|
49
|
+
*/
|
|
50
|
+
const palletsErrorsService = new PalletsErrorsService_1.PalletsErrorsService(mockApi);
|
|
51
|
+
describe('PalletErrorService', () => {
|
|
52
|
+
describe('fetchErrorItem', () => {
|
|
53
|
+
it('works with a query to a single error item id', async () => {
|
|
54
|
+
expect((0, sanitize_1.sanitizeNumbers)(await palletsErrorsService.fetchErrorItem(mockHistoricApi, {
|
|
55
|
+
hash: mock_1.blockHash13641102,
|
|
56
|
+
palletId: 'democracy',
|
|
57
|
+
errorItemId: 'ValueLow',
|
|
58
|
+
metadata: false,
|
|
59
|
+
}))).toMatchObject(fetchValueLowErrorItem13641102_json_1.default);
|
|
60
|
+
});
|
|
61
|
+
it('works with an index identifier', async () => {
|
|
62
|
+
expect((0, sanitize_1.sanitizeNumbers)(await palletsErrorsService.fetchErrorItem(mockHistoricApi, {
|
|
63
|
+
hash: mock_1.blockHash13641102,
|
|
64
|
+
palletId: '14',
|
|
65
|
+
errorItemId: 'InsufficientFunds',
|
|
66
|
+
metadata: false,
|
|
67
|
+
}))).toMatchObject(fetchInsufficientFundsErrorItem13641356_json_1.default);
|
|
68
|
+
});
|
|
69
|
+
it('appropriately uses metadata params', async () => {
|
|
70
|
+
expect((0, sanitize_1.sanitizeNumbers)(await palletsErrorsService.fetchErrorItem(mockHistoricApi, {
|
|
71
|
+
hash: mock_1.blockHash13641102,
|
|
72
|
+
palletId: 'democracy',
|
|
73
|
+
errorItemId: 'ProposalMissing',
|
|
74
|
+
metadata: true,
|
|
75
|
+
}))).toMatchObject(fetchProposalMissingErrorItem13641102_json_1.default);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
describe('fetchErrors', () => {
|
|
79
|
+
it('work with a index identifier', async () => {
|
|
80
|
+
expect((0, sanitize_1.sanitizeNumbers)(await palletsErrorsService.fetchErrors(mockHistoricApi, {
|
|
81
|
+
hash: mock_1.blockHash13641102,
|
|
82
|
+
palletId: '14',
|
|
83
|
+
onlyIds: false,
|
|
84
|
+
}))).toStrictEqual(fetchErrorsRes_json_1.default);
|
|
85
|
+
});
|
|
86
|
+
it('only list error item ids when onlyIds is true', async () => {
|
|
87
|
+
expect((0, sanitize_1.sanitizeNumbers)(await palletsErrorsService.fetchErrors(mockHistoricApi, {
|
|
88
|
+
hash: mock_1.blockHash13641102,
|
|
89
|
+
palletId: 'democracy',
|
|
90
|
+
onlyIds: true,
|
|
91
|
+
}))).toStrictEqual(fetchErrorsOnlyIdsRes_json_1.default);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
//# sourceMappingURL=PalletsErrorsService.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PalletsErrorsService.spec.js","sourceRoot":"","sources":["../../../../src/services/pallets/PalletsErrorsService.spec.ts"],"names":[],"mappings":";AAAA,oDAAoD;AACpD,8CAA8C;AAC9C,EAAE;AACF,gFAAgF;AAChF,uEAAuE;AACvE,oEAAoE;AACpE,sCAAsC;AACtC,EAAE;AACF,kEAAkE;AAClE,iEAAiE;AACjE,gEAAgE;AAChE,+CAA+C;AAC/C,EAAE;AACF,oEAAoE;AACpE,wEAAwE;;;;;AAMxE,6CAAiD;AACjD,8DAAsE;AACtE,+CAAyE;AACzE,2EAA0E;AAC1E,8HAAgG;AAChG,gHAAkF;AAClF,kKAAuH;AACvH,8JAAmH;AACnH,gJAAqG;AACrG,iEAA8D;AAE9D,MAAM,kBAAkB,GAAG,GAAG,EAAE,CAC/B,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;IAC3B,kCAAqB,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC;AACpD,CAAC,CAAC,CAAC;AAEJ,MAAM,eAAe,GAAG;IACv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,EAAE,WAAW;gBACrB,WAAW,EAAE,iBAAiB;gBAC9B,QAAQ,EAAE,IAAI;aACd,CAAC,CACF,CACD,CAAC,aAAa,CAAC,oDAAuB,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;QAC5B,EAAE,CAAC,8BAA8B,EAAE,KAAK,IAAI,EAAE;YAC7C,MAAM,CACL,IAAA,0BAAe,EACd,MAAM,oBAAoB,CAAC,WAAW,CAAC,eAAe,EAAE;gBACvD,IAAI,EAAE,wBAAiB;gBACvB,QAAQ,EAAE,IAAI;gBACd,OAAO,EAAE,KAAK;aACd,CAAC,CACF,CACD,CAAC,aAAa,CAAC,6BAAa,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,+CAA+C,EAAE,KAAK,IAAI,EAAE;YAC9D,MAAM,CACL,IAAA,0BAAe,EACd,MAAM,oBAAoB,CAAC,WAAW,CAAC,eAAe,EAAE;gBACvD,IAAI,EAAE,wBAAiB;gBACvB,QAAQ,EAAE,WAAW;gBACrB,OAAO,EAAE,IAAI;aACb,CAAC,CACF,CACD,CAAC,aAAa,CAAC,oCAAoB,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ApiPromise } from '@polkadot/api';
|
|
2
|
+
import { BlockHash } from '@polkadot/types/interfaces';
|
|
3
|
+
import { IPalletNominationPool, IPalletNominationPoolInfo } from '../../types/responses/';
|
|
4
|
+
import { AbstractService } from '../AbstractService';
|
|
5
|
+
export declare class PalletsNominationPoolService extends AbstractService {
|
|
6
|
+
constructor(api: ApiPromise);
|
|
7
|
+
/**
|
|
8
|
+
* Fetch nomination pool information at a given block and pool Id.
|
|
9
|
+
*
|
|
10
|
+
* @param poolId `Id` of the pool being queried
|
|
11
|
+
* @param hash `BlockHash` to make call at
|
|
12
|
+
* @param getMetaData boolean determining whether to query pool metadata
|
|
13
|
+
*/
|
|
14
|
+
fetchNominationPoolById(poolId: number, hash: BlockHash, getMetaData: boolean): Promise<IPalletNominationPool>;
|
|
15
|
+
/**
|
|
16
|
+
* Fetch generalized nomination pool information at a given block.
|
|
17
|
+
*
|
|
18
|
+
* @param hash `BlockHash` to make call at
|
|
19
|
+
*/
|
|
20
|
+
fetchNominationPoolInfo(hash: BlockHash): Promise<IPalletNominationPoolInfo>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
|
|
3
|
+
// This file is part of Substrate API Sidecar.
|
|
4
|
+
//
|
|
5
|
+
// Substrate API Sidecar is free software: you can redistribute it and/or modify
|
|
6
|
+
// it under the terms of the GNU General Public License as published by
|
|
7
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
// (at your option) any later version.
|
|
9
|
+
//
|
|
10
|
+
// This program is distributed in the hope that it will be useful,
|
|
11
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
// GNU General Public License for more details.
|
|
14
|
+
//
|
|
15
|
+
// You should have received a copy of the GNU General Public License
|
|
16
|
+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.PalletsNominationPoolService = void 0;
|
|
19
|
+
const AbstractService_1 = require("../AbstractService");
|
|
20
|
+
class PalletsNominationPoolService extends AbstractService_1.AbstractService {
|
|
21
|
+
constructor(api) {
|
|
22
|
+
super(api);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Fetch nomination pool information at a given block and pool Id.
|
|
26
|
+
*
|
|
27
|
+
* @param poolId `Id` of the pool being queried
|
|
28
|
+
* @param hash `BlockHash` to make call at
|
|
29
|
+
* @param getMetaData boolean determining whether to query pool metadata
|
|
30
|
+
*/
|
|
31
|
+
async fetchNominationPoolById(poolId, hash, getMetaData) {
|
|
32
|
+
const { api } = this;
|
|
33
|
+
const historicApi = await api.at(hash);
|
|
34
|
+
let metadata = '';
|
|
35
|
+
const [{ number }, bondedPool, rewardPool] = await Promise.all([
|
|
36
|
+
api.rpc.chain.getHeader(hash),
|
|
37
|
+
historicApi.query.nominationPools.bondedPools(poolId),
|
|
38
|
+
historicApi.query.nominationPools.rewardPools(poolId),
|
|
39
|
+
]);
|
|
40
|
+
const at = {
|
|
41
|
+
hash,
|
|
42
|
+
height: number.unwrap().toString(10),
|
|
43
|
+
};
|
|
44
|
+
// get metadata if user requested
|
|
45
|
+
if (getMetaData) {
|
|
46
|
+
const data = await api.query.nominationPools.metadata(poolId);
|
|
47
|
+
metadata = data.toString();
|
|
48
|
+
}
|
|
49
|
+
const response = getMetaData
|
|
50
|
+
? {
|
|
51
|
+
at,
|
|
52
|
+
bondedPool,
|
|
53
|
+
rewardPool,
|
|
54
|
+
metadata,
|
|
55
|
+
}
|
|
56
|
+
: {
|
|
57
|
+
at,
|
|
58
|
+
bondedPool,
|
|
59
|
+
rewardPool,
|
|
60
|
+
};
|
|
61
|
+
return response;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Fetch generalized nomination pool information at a given block.
|
|
65
|
+
*
|
|
66
|
+
* @param hash `BlockHash` to make call at
|
|
67
|
+
*/
|
|
68
|
+
async fetchNominationPoolInfo(hash) {
|
|
69
|
+
const { api } = this;
|
|
70
|
+
const historicApi = await api.at(hash);
|
|
71
|
+
const [{ number }, counterForBondedPools, counterForMetadata, counterForPoolMembers, counterForReversePoolIdLookup, counterForRewardPools, counterForSubPoolsStorage, lastPoolId, maxPoolMembers, maxPoolMembersPerPool, maxPools, minCreateBond, minJoinBond,] = await Promise.all([
|
|
72
|
+
api.rpc.chain.getHeader(hash),
|
|
73
|
+
historicApi.query.nominationPools.counterForBondedPools(),
|
|
74
|
+
historicApi.query.nominationPools.counterForMetadata(),
|
|
75
|
+
historicApi.query.nominationPools.counterForPoolMembers(),
|
|
76
|
+
historicApi.query.nominationPools.counterForReversePoolIdLookup(),
|
|
77
|
+
historicApi.query.nominationPools.counterForRewardPools(),
|
|
78
|
+
historicApi.query.nominationPools.counterForSubPoolsStorage(),
|
|
79
|
+
historicApi.query.nominationPools.lastPoolId(),
|
|
80
|
+
historicApi.query.nominationPools.maxPoolMembers(),
|
|
81
|
+
historicApi.query.nominationPools.maxPoolMembersPerPool(),
|
|
82
|
+
historicApi.query.nominationPools.maxPools(),
|
|
83
|
+
historicApi.query.nominationPools.minCreateBond(),
|
|
84
|
+
historicApi.query.nominationPools.minJoinBond(),
|
|
85
|
+
]);
|
|
86
|
+
const at = {
|
|
87
|
+
hash,
|
|
88
|
+
height: number.unwrap().toString(10),
|
|
89
|
+
};
|
|
90
|
+
return {
|
|
91
|
+
at,
|
|
92
|
+
counterForBondedPools,
|
|
93
|
+
counterForMetadata,
|
|
94
|
+
counterForPoolMembers,
|
|
95
|
+
counterForReversePoolIdLookup,
|
|
96
|
+
counterForRewardPools,
|
|
97
|
+
counterForSubPoolsStorage,
|
|
98
|
+
lastPoolId,
|
|
99
|
+
maxPoolMembers,
|
|
100
|
+
maxPoolMembersPerPool,
|
|
101
|
+
maxPools,
|
|
102
|
+
minCreateBond,
|
|
103
|
+
minJoinBond,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.PalletsNominationPoolService = PalletsNominationPoolService;
|
|
108
|
+
//# sourceMappingURL=PalletsNominationPoolsService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PalletsNominationPoolsService.js","sourceRoot":"","sources":["../../../../src/services/pallets/PalletsNominationPoolsService.ts"],"names":[],"mappings":";AAAA,oDAAoD;AACpD,8CAA8C;AAC9C,EAAE;AACF,gFAAgF;AAChF,u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,eAAe,CAAC,WAAW,EAAE;SAC/C,CAAC,CAAC;QAEH,MAAM,EAAE,GAAG;YACV,IAAI;YACJ,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC;SACpC,CAAC;QAEF,OAAO;YACN,EAAE;YACF,qBAAqB;YACrB,kBAAkB;YAClB,qBAAqB;YACrB,6BAA6B;YAC7B,qBAAqB;YACrB,yBAAyB;YACzB,UAAU;YACV,cAAc;YACd,qBAAqB;YACrB,QAAQ;YACR,aAAa;YACb,WAAW;SACX,CAAC;IACH,CAAC;CACD;AAnHD,oEAmHC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
|
|
3
|
+
// This file is part of Substrate API Sidecar.
|
|
4
|
+
//
|
|
5
|
+
// Substrate API Sidecar is free software: you can redistribute it and/or modify
|
|
6
|
+
// it under the terms of the GNU General Public License as published by
|
|
7
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
// (at your option) any later version.
|
|
9
|
+
//
|
|
10
|
+
// This program is distributed in the hope that it will be useful,
|
|
11
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
// GNU General Public License for more details.
|
|
14
|
+
//
|
|
15
|
+
// You should have received a copy of the GNU General Public License
|
|
16
|
+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const sanitizeNumbers_1 = require("../../sanitize/sanitizeNumbers");
|
|
19
|
+
const registries_1 = require("../../test-helpers/registries");
|
|
20
|
+
const mock_1 = require("../test-helpers/mock");
|
|
21
|
+
const mockNonimationPoolResponseData_1 = require("../test-helpers/mock/data/mockNonimationPoolResponseData");
|
|
22
|
+
const PalletsNominationPoolsService_1 = require("./PalletsNominationPoolsService");
|
|
23
|
+
const referendumInfoOfAt = () => Promise.resolve().then(() => {
|
|
24
|
+
registries_1.polkadotRegistry.createType('ReferendumInfo');
|
|
25
|
+
});
|
|
26
|
+
const mockHistoricApi = {
|
|
27
|
+
registry: registries_1.polkadotRegistry,
|
|
28
|
+
query: {
|
|
29
|
+
democracy: {
|
|
30
|
+
referendumInfoOf: referendumInfoOfAt,
|
|
31
|
+
},
|
|
32
|
+
nominationPools: {
|
|
33
|
+
bondedPools: mockNonimationPoolResponseData_1.getBondedPools,
|
|
34
|
+
rewardPools: mockNonimationPoolResponseData_1.getRewardPools,
|
|
35
|
+
counterForBondedPools: mockNonimationPoolResponseData_1.counterForBondedPools,
|
|
36
|
+
counterForMetadata: mockNonimationPoolResponseData_1.counterForMetadata,
|
|
37
|
+
counterForPoolMembers: mockNonimationPoolResponseData_1.counterForPoolMembers,
|
|
38
|
+
counterForReversePoolIdLookup: mockNonimationPoolResponseData_1.counterForReversePoolIdLookup,
|
|
39
|
+
counterForSubPoolsStorage: mockNonimationPoolResponseData_1.counterForSubPoolsStorage,
|
|
40
|
+
counterForRewardPools: mockNonimationPoolResponseData_1.counterForRewardPools,
|
|
41
|
+
lastPoolId: mockNonimationPoolResponseData_1.lastPoolId,
|
|
42
|
+
maxPoolMembers: mockNonimationPoolResponseData_1.maxPoolMembers,
|
|
43
|
+
maxPoolMembersPerPool: mockNonimationPoolResponseData_1.maxPoolMembersPerPool,
|
|
44
|
+
maxPools: mockNonimationPoolResponseData_1.maxPools,
|
|
45
|
+
minCreateBond: mockNonimationPoolResponseData_1.minCreateBond,
|
|
46
|
+
minJoinBond: mockNonimationPoolResponseData_1.minJoinBond,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
const mockApi = {
|
|
51
|
+
...mock_1.defaultMockApi,
|
|
52
|
+
at: (_hash) => mockHistoricApi,
|
|
53
|
+
};
|
|
54
|
+
const palletsNominationPoolService = new PalletsNominationPoolsService_1.PalletsNominationPoolService(mockApi);
|
|
55
|
+
describe('palletsNominationPoolService', () => {
|
|
56
|
+
describe('palletsNominationPoolService.fetchNominationPoolById', () => {
|
|
57
|
+
it('Should return the correct response for a nomination pool without metadata', async () => {
|
|
58
|
+
const expectedResponse = {
|
|
59
|
+
at: {
|
|
60
|
+
hash: '0x7b713de604a99857f6c25eacc115a4f28d2611a23d9ddff99ab0e4f1c17a8578',
|
|
61
|
+
height: '789629',
|
|
62
|
+
},
|
|
63
|
+
bondedPool: {
|
|
64
|
+
points: '2000000000000',
|
|
65
|
+
state: 'Destroying',
|
|
66
|
+
memberCounter: '1',
|
|
67
|
+
roles: {
|
|
68
|
+
depositor: '15uHYQkvPf3iBQn7mLYbdrf1fYFpE77zVR5hsKGSGYKm5rU9',
|
|
69
|
+
root: '15LkJX3hcxnHkaTdzq3n3HfKKgRcPJZA7VMNEqtMSfm8xgjR',
|
|
70
|
+
nominator: '15LkJX3hcxnHkaTdzq3n3HfKKgRcPJZA7VMNEqtMSfm8xgjR',
|
|
71
|
+
stateToggler: '15LkJX3hcxnHkaTdzq3n3HfKKgRcPJZA7VMNEqtMSfm8xgjR',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
rewardPool: {
|
|
75
|
+
lastRecordedRewardCounter: '0',
|
|
76
|
+
lastRecordedTotalPayouts: '0',
|
|
77
|
+
totalRewardsClaimed: '0',
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
const response = await palletsNominationPoolService.fetchNominationPoolById(122, mock_1.blockHash789629, false);
|
|
81
|
+
expect((0, sanitizeNumbers_1.sanitizeNumbers)(response)).toStrictEqual(expectedResponse);
|
|
82
|
+
});
|
|
83
|
+
it('Should return the correct response for a nomination pool with metadata', async () => {
|
|
84
|
+
const expectedResponse = {
|
|
85
|
+
at: {
|
|
86
|
+
hash: '0x64c6d3db75e33e5ef617bc9851078a4c387fcff7ca0eada54e46293d532e3c84',
|
|
87
|
+
height: '789629',
|
|
88
|
+
},
|
|
89
|
+
bondedPool: {
|
|
90
|
+
points: '2000000000000',
|
|
91
|
+
state: 'Destroying',
|
|
92
|
+
memberCounter: '1',
|
|
93
|
+
roles: {
|
|
94
|
+
depositor: '15uHYQkvPf3iBQn7mLYbdrf1fYFpE77zVR5hsKGSGYKm5rU9',
|
|
95
|
+
root: '15LkJX3hcxnHkaTdzq3n3HfKKgRcPJZA7VMNEqtMSfm8xgjR',
|
|
96
|
+
nominator: '15LkJX3hcxnHkaTdzq3n3HfKKgRcPJZA7VMNEqtMSfm8xgjR',
|
|
97
|
+
stateToggler: '15LkJX3hcxnHkaTdzq3n3HfKKgRcPJZA7VMNEqtMSfm8xgjR',
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
rewardPool: {
|
|
101
|
+
lastRecordedRewardCounter: '0',
|
|
102
|
+
lastRecordedTotalPayouts: '0',
|
|
103
|
+
totalRewardsClaimed: '0',
|
|
104
|
+
},
|
|
105
|
+
metadata: '0x4a757374204174652053746f6d61636861636865',
|
|
106
|
+
};
|
|
107
|
+
const blockHashAt = registries_1.polkadotRegistry.createType('BlockHash', '0x64c6d3db75e33e5ef617bc9851078a4c387fcff7ca0eada54e46293d532e3c84');
|
|
108
|
+
const response = await palletsNominationPoolService.fetchNominationPoolById(122, blockHashAt, true);
|
|
109
|
+
expect((0, sanitizeNumbers_1.sanitizeNumbers)(response)).toStrictEqual(expectedResponse);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
describe('palletsNominationPoolService.fetchNominationPoolInfo', () => {
|
|
113
|
+
it('Should return the correct response for nomination pools info', async () => {
|
|
114
|
+
const expectedResponse = {
|
|
115
|
+
at: {
|
|
116
|
+
hash: '0x64c6d3db75e33e5ef617bc9851078a4c387fcff7ca0eada54e46293d532e3c84',
|
|
117
|
+
height: '789629',
|
|
118
|
+
},
|
|
119
|
+
counterForBondedPools: '96',
|
|
120
|
+
counterForMetadata: '93',
|
|
121
|
+
counterForPoolMembers: '228',
|
|
122
|
+
counterForReversePoolIdLookup: '96',
|
|
123
|
+
counterForRewardPools: '96',
|
|
124
|
+
counterForSubPoolsStorage: '39',
|
|
125
|
+
lastPoolId: '122',
|
|
126
|
+
maxPoolMembers: '524288',
|
|
127
|
+
maxPoolMembersPerPool: null,
|
|
128
|
+
maxPools: '512',
|
|
129
|
+
minCreateBond: '1000000000000',
|
|
130
|
+
minJoinBond: '100000000000',
|
|
131
|
+
};
|
|
132
|
+
const blockHashAt = registries_1.polkadotRegistry.createType('BlockHash', '0x64c6d3db75e33e5ef617bc9851078a4c387fcff7ca0eada54e46293d532e3c84');
|
|
133
|
+
const response = await palletsNominationPoolService.fetchNominationPoolInfo(blockHashAt);
|
|
134
|
+
expect((0, sanitizeNumbers_1.sanitizeNumbers)(response)).toStrictEqual(expectedResponse);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
//# sourceMappingURL=PalletsNominationPoolsService.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PalletsNominationPoolsService.spec.js","sourceRoot":"","sources":["../../../../src/services/pallets/PalletsNominationPoolsService.spec.ts"],"names":[],"mappings":";AAAA,oDAAoD;AACpD,8CAA8C;AAC9C,EAAE;AACF,gFAAgF;AAChF,uEAAuE;AACvE,oEAAoE;AACpE,sCAAsC;AACtC,EAAE;AACF,kEAAkE;AAClE,iEAAiE;AACjE,gEAAgE;AAChE,+CAA+C;AAC/C,EAAE;AACF,oEAAoE;AACpE,wEAAwE;;AAMxE,oEAAiE;AACjE,8DAAiE;AACjE,+CAAuE;AACvE,6GAekE;AAClE,mFAA+E;AAE/E,MAAM,kBAAkB,GAAG,GAAG,EAAE,CAC/B,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;IAC3B,6BAAgB,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC;AAC/C,CAAC,CAAC,CAAC;AAEJ,MAAM,eAAe,GAA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,EAAE,KAAK,IAAI,EAAE;YAC7E,MAAM,gBAAgB,GAAG;gBACxB,EAAE,EAAE;oBACH,IAAI,EAAE,oEAAoE;oBAC1E,MAAM,EAAE,QAAQ;iBAChB;gBACD,qBAAqB,EAAE,IAAI;gBAC3B,kBAAkB,EAAE,IAAI;gBACxB,qBAAqB,EAAE,KAAK;gBAC5B,6BAA6B,EAAE,IAAI;gBACnC,qBAAqB,EAAE,IAAI;gBAC3B,yBAAyB,EAAE,IAAI;gBAC/B,UAAU,EAAE,KAAK;gBACjB,cAAc,EAAE,QAAQ;gBACxB,qBAAqB,EAAE,IAAI;gBAC3B,QAAQ,EAAE,KAAK;gBACf,aAAa,EAAE,eAAe;gBAC9B,WAAW,EAAE,cAAc;aAC3B,CAAC;YACF,MAAM,WAAW,GAAG,6BAAgB,CAAC,UAAU,CAC9C,WAAW,EACX,oEAAoE,CACpE,CAAC;YAEF,MAAM,QAAQ,GACb,MAAM,4BAA4B,CAAC,uBAAuB,CAAC,WAAW,CAAC,CAAC;YAEzE,MAAM,CAAC,IAAA,iCAAe,EAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;QACnE,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BlockHash } from '@polkadot/types/interfaces';
|
|
2
|
+
import { IPalletStakingValidator } from 'src/types/responses';
|
|
3
|
+
import { AbstractService } from '../AbstractService';
|
|
4
|
+
export declare class PalletsStakingValidatorsService extends AbstractService {
|
|
5
|
+
/**
|
|
6
|
+
* Fetch all validators addresses and their status at a given block.
|
|
7
|
+
* The status of the validator can be either:
|
|
8
|
+
* - `active` (validator is part of the active set) or
|
|
9
|
+
* - `waiting` (validator did not get into the active set this era)
|
|
10
|
+
*
|
|
11
|
+
* @param hash `BlockHash` to make call at
|
|
12
|
+
*/
|
|
13
|
+
derivePalletStakingValidators(hash: BlockHash): Promise<IPalletStakingValidator>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
|
|
3
|
+
// This file is part of Substrate API Sidecar.
|
|
4
|
+
//
|
|
5
|
+
// Substrate API Sidecar is free software: you can redistribute it and/or modify
|
|
6
|
+
// it under the terms of the GNU General Public License as published by
|
|
7
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
// (at your option) any later version.
|
|
9
|
+
//
|
|
10
|
+
// This program is distributed in the hope that it will be useful,
|
|
11
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
// GNU General Public License for more details.
|
|
14
|
+
//
|
|
15
|
+
// You should have received a copy of the GNU General Public License
|
|
16
|
+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.PalletsStakingValidatorsService = void 0;
|
|
19
|
+
const AbstractService_1 = require("../AbstractService");
|
|
20
|
+
class PalletsStakingValidatorsService extends AbstractService_1.AbstractService {
|
|
21
|
+
/**
|
|
22
|
+
* Fetch all validators addresses and their status at a given block.
|
|
23
|
+
* The status of the validator can be either:
|
|
24
|
+
* - `active` (validator is part of the active set) or
|
|
25
|
+
* - `waiting` (validator did not get into the active set this era)
|
|
26
|
+
*
|
|
27
|
+
* @param hash `BlockHash` to make call at
|
|
28
|
+
*/
|
|
29
|
+
async derivePalletStakingValidators(hash) {
|
|
30
|
+
const { api } = this;
|
|
31
|
+
const historicApi = await api.at(hash);
|
|
32
|
+
const validatorSession = await historicApi.query.session.validators();
|
|
33
|
+
const validatorsActiveSet = new Set();
|
|
34
|
+
for (const address of validatorSession) {
|
|
35
|
+
validatorsActiveSet.add(address.toString());
|
|
36
|
+
}
|
|
37
|
+
// Populating the returned array with the Validator address and its
|
|
38
|
+
// status. If the address is found in the `validatorsActiveSet` then
|
|
39
|
+
// status is `active` otherwise is set to `waiting`
|
|
40
|
+
const validators = [];
|
|
41
|
+
const validatorsEntries = await historicApi.query.staking.validators.entries();
|
|
42
|
+
validatorsEntries.map(([key]) => {
|
|
43
|
+
const address = key.args.map((k) => k.toHuman())[0];
|
|
44
|
+
const status = validatorsActiveSet.has(address)
|
|
45
|
+
? 'active'
|
|
46
|
+
: 'waiting';
|
|
47
|
+
validators.push({ address, status });
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
validators,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.PalletsStakingValidatorsService = PalletsStakingValidatorsService;
|
|
55
|
+
//# sourceMappingURL=PalletsStakingValidatorsService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PalletsStakingValidatorsService.js","sourceRoot":"","sources":["../../../../src/services/pallets/PalletsStakingValidatorsService.ts"],"names":[],"mappings":";AAAA,oDAAoD;AACpD,8CAA8C;AAC9C,EAAE;AACF,gFAAgF;AAChF,uEAAuE;AACvE,oEAAoE;AACpE,sCAAsC;AACtC,EAAE;AACF,kEAAkE;AAClE,iEAAiE;AACjE,gEAAgE;AAChE,+CAA+C;AAC/C,EAAE;AACF,oEAAoE;AACpE,wEAAwE;;;AAKxE,wDAAqD;AAErD,MAAa,+BAAgC,SAAQ,iCAAe;IACnE;;;;;;;OAOG;IACH,KAAK,CAAC,6BAA6B,CAClC,IAAe;QAEf,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QACrB,MAAM,WAAW,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;QAEvC,MAAM,gBAAgB,GAAG,MAAM,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;QACtE,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAU,CAAC;QAC9C,KAAK,MAAM,OAAO,IAAI,gBAAgB,EAAE;YACvC,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;SAC5C;QAED,mEAAmE;QACnE,oEAAoE;QACpE,mDAAmD;QACnD,MAAM,UAAU,GAAiB,EAAE,CAAC;QACpC,MAAM,iBAAiB,GACtB,MAAM,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QACtD,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE;YAC/B,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YACpD,MAAM,MAAM,GAAW,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC;gBACtD,CAAC,CAAC,QAAQ;gBACV,CAAC,CAAC,SAAS,CAAC;YACb,UAAU,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;QAEH,OAAO;YACN,UAAU;SACV,CAAC;IACH,CAAC;CACD;AAvCD,0EAuCC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ApiDecoration } from '@polkadot/api/types';
|
|
2
2
|
import { BlockHash } from '@polkadot/types/interfaces';
|
|
3
3
|
import { IPalletStorage, IPalletStorageItem } from 'src/types/responses';
|
|
4
|
-
import {
|
|
4
|
+
import { AbstractPalletsService } from '../AbstractPalletsService';
|
|
5
5
|
interface IFetchPalletArgs {
|
|
6
6
|
hash: BlockHash;
|
|
7
7
|
palletId: string;
|
|
@@ -13,7 +13,7 @@ interface IFetchStorageItemArgs extends IFetchPalletArgs {
|
|
|
13
13
|
metadata: boolean;
|
|
14
14
|
adjustMetadataV13Arg: boolean;
|
|
15
15
|
}
|
|
16
|
-
export declare class PalletsStorageService extends
|
|
16
|
+
export declare class PalletsStorageService extends AbstractPalletsService {
|
|
17
17
|
fetchStorageItem(historicApi: ApiDecoration<'promise'>, { hash, palletId, storageItemId, keys, metadata, adjustMetadataV13Arg, }: IFetchStorageItemArgs): Promise<IPalletStorageItem>;
|
|
18
18
|
fetchStorage(historicApi: ApiDecoration<'promise'>, { hash, palletId, onlyIds, adjustMetadataV13Arg, }: IFetchPalletArgs & {
|
|
19
19
|
onlyIds: boolean;
|
|
@@ -35,26 +35,5 @@ export declare class PalletsStorageService extends AbstractService {
|
|
|
35
35
|
* @param storageItemMeta polkadot-js StorageEntryMetadataV12
|
|
36
36
|
*/
|
|
37
37
|
private normalizeStorageItemMeta;
|
|
38
|
-
/**
|
|
39
|
-
* Find the storage item's metadata within the pallets's metadata.
|
|
40
|
-
*
|
|
41
|
-
* @param palletMeta the metadata of the pallet that contains the storage item
|
|
42
|
-
* @param storageId name of the storage item in camel or pascal case
|
|
43
|
-
*/
|
|
44
|
-
private findStorageItemMeta;
|
|
45
|
-
/**
|
|
46
|
-
* Find a pallet's metadata info.
|
|
47
|
-
*
|
|
48
|
-
* @param palletId identifier for a FRAME pallet as a pallet name or index.
|
|
49
|
-
*/
|
|
50
|
-
private findPalletMeta;
|
|
51
|
-
private validPalletId;
|
|
52
|
-
/**
|
|
53
|
-
* Identify if a pallet Identifier should be an index or a string. If it should
|
|
54
|
-
* be an index return a number and if it should be a name return a string.
|
|
55
|
-
*
|
|
56
|
-
* @param palletId FRAME pallet identifier as a pallet name or index
|
|
57
|
-
*/
|
|
58
|
-
private static palletIdxOrName;
|
|
59
38
|
}
|
|
60
39
|
export {};
|