"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PluginLedgerConnectorStub = void 0;
const typescript_optional_1 = require("typescript-optional");
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 {
    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`);
    }
    get className() {
        return PluginLedgerConnectorStub.CLASS_NAME;
    }
    getInstanceId() {
        return this.instanceId;
    }
    getHttpServer() {
        return typescript_optional_1.Optional.empty();
    }
    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 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGx1Z2luLWxlZGdlci1jb25uZWN0b3Itc3R1Yi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3NyYy90ZXN0L3R5cGVzY3JpcHQvZml4dHVyZXMvcGx1Z2luLWxlZGdlci1jb25uZWN0b3Itc3R1Yi9wbHVnaW4tbGVkZ2VyLWNvbm5lY3Rvci1zdHViLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUlBLDZEQUErQztBQUUvQyxrRUFPc0M7QUFFdEMsMERBR2tDO0FBRWxDLDhEQUtvQztBQUVwQyxzRkFBaUY7QUFDakYsc0ZBQWlGO0FBQ2pGLDRGQUF1RjtBQVF2RixNQUFhLHlCQUF5QjtJQWdCcEMsWUFBNEIsT0FBMEM7UUFBMUMsWUFBTyxHQUFQLE9BQU8sQ0FBbUM7UUFDcEUsTUFBTSxLQUFLLE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