How to use the fabric-contract-api.Contract._isContract function in fabric-contract-api

To help you get started, we’ve selected a few fabric-contract-api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hyperledger / fabric-chaincode-node / libraries / fabric-shim / lib / contract-spi / chaincodefromcontract.js View on Github external
_resolveContractImplementations(contractClasses) {
        logger.debug('Supplied contract classes', contractClasses);
        this.defaultContractName = Reflect.getMetadata('fabric:default', global);

        const Contract = require('fabric-contract-api').Contract;

        const implementations = {};

        for (const contractClass of contractClasses) {
            const contract = new (contractClass);
            if (!(Contract._isContract(contract))) {
                throw new Error(`invalid contract instance ${JSON.stringify(contract)}`);
            }

            const name = contract.getName();
            if (!this.defaultContractName) {
                this.defaultContractName = name;
                contract.default = true;
            } else if (this.defaultContractName === contract.getName()) {
                contract.default = true;
            }

            implementations[name] = {name, contractInstance: contract};

        }
        return implementations;
    }