UNPKG

@q-dev/q-js-sdk

Version:

Typescript Library to interact with Q System Contracts

95 lines 2.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseParametersInstance = void 0; const BaseContractInstance_1 = require("./BaseContractInstance"); /** * [Abstract Parameters contract](@system-contracts-repo/@network/AParameters/) */ /** * Abstract Parameters instance to interact with Constitution, EPDR and EPQFI Parameters contracts. * See [onchain documentation](@system-contracts-repo/@network/AParameters/) for more details. */ class BaseParametersInstance extends BaseContractInstance_1.BaseContractInstance { async getUintKeys() { return this.getKeys('Uint'); } /** * Get uint value * @param key key of value * @returns value */ async getUint(key) { return this.getParameter('Uint', key); } /** * Get address keys * @returns keys */ async getAddrKeys() { return this.getKeys('Addr'); } /** * Get address value * @param key key of value * @returns value */ async getAddr(key) { return this.getParameter('Addr', key); } /** * Get keys with specific type * @param type type of keys * @returns keys */ async getKeys(type) { switch (type) { case 'Uint': return this.instance.getUintKeys(); case 'String': return this.instance.getStringKeys(); case 'Bool': return this.instance.getBoolKeys(); case 'Addr': return this.instance.getAddrKeys(); case 'Bytes32': return this.instance.getBytes32Keys(); } } /** * Get parameter with specific type and key * @param type parameter type * @param key parameter key * @returns parameter */ async getParameter(type, key) { switch (type) { case 'Uint': return (await this.instance.getUint(key)).toString(); case 'String': return this.instance.getString(key); case 'Bool': return (await this.instance.getBool(key)).toString(); case 'Addr': return this.instance.getAddr(key); case 'Bytes32': return this.instance.getBytes32(key); } } /** * Get all parameters with specific type * @param type specific type * @returns parameters (key-value array) */ async getParameters(type) { const keys = await this.getKeys(type); const valuesPromises = keys.map(key => this.getParameter(type, key)); const values = await Promise.all(valuesPromises); const keyValuePairs = keys.map((key, i) => ({ key, value: values[i] })); return keyValuePairs; } } exports.BaseParametersInstance = BaseParametersInstance; //# sourceMappingURL=BaseParametersInstance.js.map