@exromany/lido-csm-sdk
Version:
[](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [](h
118 lines • 7.44 kB
JavaScript
;
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
var useValue = arguments.length > 2;
for (var i = 0; i < initializers.length; i++) {
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
}
return useValue ? value : void 0;
};
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
var _, done = false;
for (var i = decorators.length - 1; i >= 0; i--) {
var context = {};
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
if (kind === "accessor") {
if (result === void 0) continue;
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
if (_ = accept(result.get)) descriptor.get = _;
if (_ = accept(result.set)) descriptor.set = _;
if (_ = accept(result.init)) initializers.unshift(_);
}
else if (_ = accept(result)) {
if (kind === "field") initializers.unshift(_);
else descriptor[key] = _;
}
}
if (target) Object.defineProperty(target, contextIn.name, descriptor);
done = true;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.StrikesSDK = void 0;
const csm_sdk_module_js_1 = require("../common/class-primitives/csm-sdk-module.js");
const index_js_1 = require("../common/decorators/index.js");
const index_js_2 = require("../common/index.js");
const index_js_3 = require("../common/utils/index.js");
const find_proof_js_1 = require("./find-proof.js");
const parse_tree_js_1 = require("./parse-tree.js");
let StrikesSDK = (() => {
var _a;
let _classSuper = csm_sdk_module_js_1.CsmSDKModule;
let _instanceExtraInitializers = [];
let _getTreeConfig_decorators;
let _getProofTreeUrls_decorators;
let _getProofTree_decorators;
let _getProof_decorators;
let _getStrikes_decorators;
let _getKeysWithStrikes_decorators;
return _a = class StrikesSDK extends _classSuper {
get strikesContract() {
return this.core.getContract(index_js_2.CONTRACT_NAMES.validatorStrikes);
}
async getTreeConfig() {
const [root, cid] = await Promise.all([
this.strikesContract.read.treeRoot(),
this.strikesContract.read.treeCid(),
]).catch(index_js_3.onError);
return { root, cid };
}
getProofTreeUrls(cid) {
return this.core.getIpfsUrls(cid).filter(index_js_3.isDefined);
}
async getProofTree() {
const { root, cid } = await this.getTreeConfig();
if (!root || !cid) {
return null;
}
const urls = this.getProofTreeUrls(cid);
return (0, index_js_3.fetchTree)({ urls, root, parse: parse_tree_js_1.parseStrikesTree });
}
async getProof(pubkey) {
const proofTree = await this.getProofTree();
if (!proofTree)
return null;
return (0, find_proof_js_1.findProof)(proofTree, pubkey);
}
async getStrikes(pubkey) {
const proofTree = await this.getProofTree();
if (!proofTree)
return null;
return (0, find_proof_js_1.findLeaf)(proofTree, pubkey);
}
async getKeysWithStrikes(nodeOperatorId) {
const proofTree = await this.getProofTree();
if (!proofTree)
return [];
return (0, find_proof_js_1.filterLeafsByNodeOperator)(proofTree, nodeOperatorId);
}
constructor() {
super(...arguments);
__runInitializers(this, _instanceExtraInitializers);
}
},
(() => {
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
_getTreeConfig_decorators = [(0, index_js_1.Logger)('Views:'), (0, index_js_1.ErrorHandler)()];
_getProofTreeUrls_decorators = [(0, index_js_1.Logger)('Utils:')];
_getProofTree_decorators = [(0, index_js_1.Logger)('API:'), (0, index_js_1.Cache)(index_js_2.CACHE_LONG)];
_getProof_decorators = [(0, index_js_1.Logger)('Utils:')];
_getStrikes_decorators = [(0, index_js_1.Logger)('Utils:')];
_getKeysWithStrikes_decorators = [(0, index_js_1.Logger)('Utils:')];
__esDecorate(_a, null, _getTreeConfig_decorators, { kind: "method", name: "getTreeConfig", static: false, private: false, access: { has: obj => "getTreeConfig" in obj, get: obj => obj.getTreeConfig }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getProofTreeUrls_decorators, { kind: "method", name: "getProofTreeUrls", static: false, private: false, access: { has: obj => "getProofTreeUrls" in obj, get: obj => obj.getProofTreeUrls }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getProofTree_decorators, { kind: "method", name: "getProofTree", static: false, private: false, access: { has: obj => "getProofTree" in obj, get: obj => obj.getProofTree }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getProof_decorators, { kind: "method", name: "getProof", static: false, private: false, access: { has: obj => "getProof" in obj, get: obj => obj.getProof }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getStrikes_decorators, { kind: "method", name: "getStrikes", static: false, private: false, access: { has: obj => "getStrikes" in obj, get: obj => obj.getStrikes }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getKeysWithStrikes_decorators, { kind: "method", name: "getKeysWithStrikes", static: false, private: false, access: { has: obj => "getKeysWithStrikes" in obj, get: obj => obj.getKeysWithStrikes }, metadata: _metadata }, null, _instanceExtraInitializers);
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
})(),
_a;
})();
exports.StrikesSDK = StrikesSDK;
//# sourceMappingURL=strikes-sdk.js.map