"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PluginLedgerConnectorStub = void 0;
const cactus_core_api_1 = require("@hyperledger/cactus-core-api");
const cactus_core_1 = require("@hyperledger/cactus-core");
const cactus_common_1 = require("@hyperledger/cactus-common");
const deploy_contract_endpoint_1 = require("./web-services/deploy-contract-endpoint");
const run_transaction_endpoint_1 = require("./web-services/run-transaction-endpoint");
const unprotected_action_endpoint_1 = require("./web-services/unprotected-action-endpoint");
class PluginLedgerConnectorStub {
    get className() {
        return PluginLedgerConnectorStub.CLASS_NAME;
    }
    constructor(options) {
        this.options = options;
        const fnTag = `${this.className}#constructor()`;
        cactus_common_1.Checks.truthy(options, `${fnTag} arg options`);
        cactus_common_1.Checks.truthy(options.instanceId, `${fnTag} options.instanceId`);
        cactus_common_1.Checks.truthy(options.pluginRegistry, `${fnTag} options.pluginRegistry`);
        const level = this.options.logLevel || "INFO";
        const label = this.className;
        this.log = cactus_common_1.LoggerProvider.getOrCreate({ level, label });
        this.instanceId = options.instanceId;
        this.pluginRegistry = options.pluginRegistry;
        this.log.debug(`Instantiated ${this.className} OK`);
    }
    getOpenApiSpec() {
        return null;
    }
    getInstanceId() {
        return this.instanceId;
    }
    async onPluginInit() {
        return;
    }
    async shutdown() {
        return;
    }
    async registerWebServices(app) {
        const webServices = await this.getOrCreateWebServices();
        await Promise.all(webServices.map((ws) => ws.registerExpress(app)));
        return webServices;
    }
    async getOrCreateWebServices() {
        if (Array.isArray(this.endpoints)) {
            return this.endpoints;
        }
        const endpoints = [];
        {
            const endpoint = new deploy_contract_endpoint_1.DeployContractEndpoint({
                connector: this,
                logLevel: this.options.logLevel,
            });
            endpoints.push(endpoint);
        }
        {
            const endpoint = new run_transaction_endpoint_1.RunTransactionEndpoint({
                connector: this,
                logLevel: this.options.logLevel,
            });
            endpoints.push(endpoint);
        }
        {
            const endpoint = new unprotected_action_endpoint_1.UnprotectedActionEndpoint({
                connector: this,
                logLevel: this.options.logLevel,
            });
            endpoints.push(endpoint);
        }
        this.endpoints = endpoints;
        return endpoints;
    }
    getPackageName() {
        // Note: this package does not exist on npm since this plugin only
        // exists for testing purposes
        return `@hyperledger/cactus-plugin-ledger-connector-stub`;
    }
    async getConsensusAlgorithmFamily() {
        return cactus_core_api_1.ConsensusAlgorithmFamily.Authority;
    }
    async hasTransactionFinality() {
        const currentConsensusAlgorithmFamily = await this.getConsensusAlgorithmFamily();
        return (0, cactus_core_1.consensusHasTransactionFinality)(currentConsensusAlgorithmFamily);
    }
    async transact(req) {
        const fnTag = `${this.className}#transact()`;
        cactus_common_1.Checks.truthy(req, `${fnTag} req`);
        return req;
    }
    async deployContract(req) {
        const fnTag = `${this.className}#deployContract()`;
        cactus_common_1.Checks.truthy(req, `${fnTag} req`);
        return req;
    }
}
exports.PluginLedgerConnectorStub = PluginLedgerConnectorStub;
PluginLedgerConnectorStub.CLASS_NAME = "PluginLedgerConnectorStub";
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGx1Z2luLWxlZGdlci1jb25uZWN0b3Itc3R1Yi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3NyYy90ZXN0L3R5cGVzY3JpcHQvZml4dHVyZXMvcGx1Z2luLWxlZGdlci1jb25uZWN0b3Itc3R1Yi9wbHVnaW4tbGVkZ2VyLWNvbm5lY3Rvci1zdHViLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUVBLGtFQU9zQztBQUV0QywwREFHa0M7QUFFbEMsOERBS29DO0FBRXBDLHNGQUFpRjtBQUNqRixzRkFBaUY7QUFDakYsNEZBQXVGO0FBUXZGLE1BQWEseUJBQXlCO0lBYXBDLElBQVcsU0FBUztRQUNsQixPQUFPLHlCQUF5QixDQUFDLFVBQVUsQ0FBQztJQUM5QyxDQUFDO0lBRUQsWUFBNEIsT0FBMEM7UUFBMUMsWUFBTyxHQUFQLE9BQU8sQ0FBbU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