How to use the fabric-contract-api.Contract 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 ampretia / fabric-application-examples / contracts / trade-ts / dist / lifecyclecontract.js View on Github external
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
// Fabric smart contract classes
const fabric_contract_api_1 = require("fabric-contract-api");
const commoditymgt_1 = require("./commoditymgt");
/**
 * Additional contract within the 'trade-ts' sample that shows a second use of the contract class
 */
class LifecycleContract extends fabric_contract_api_1.Contract {
    constructor() {
        // Unique namespace when multiple contracts per chaincode file
        super('org.example.lifecycle');
    }
    /**
     * Instantiate to perform any setup of the ledger that might be required.
     * @param {Context} ctx the transaction context
     */
    async instantiate(ctx) {
        console.log('Instantiate the contract');
        const mgt = new commoditymgt_1.CommodityManagementContract();
        await mgt.setCommodityDescription(ctx, 'au', 'GOLD');
        await mgt.setCommodityDescription(ctx, 'ag', 'SILVER');
        await mgt.setCommodityDescription(ctx, 'fe', 'IRON');
        await mgt.setCommodityDescription(ctx, 'al', 'ALUMINIUM');
        // need to call the commodity management to establish the trading symbol description mapping
github ampretia / fabric-application-examples / contracts / trade-ts / dist / trade.js View on Github external
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
// Fabric smart contract classes
const fabric_contract_api_1 = require("fabric-contract-api");
const commodity_1 = require("./commodity");
const tradeContext_1 = require("./tradeContext");
/**
 * Define commercial paper smart contract by extending Fabric Contract class
 *
 */
class TradeContract extends fabric_contract_api_1.Contract {
    constructor() {
        // Unique namespace when multiple contracts per chaincode file
        super('org.example.trade');
    }
    /**
     * A custom context provides easy access to list of all trades
     */
    createContext() {
        return new tradeContext_1.default();
    }
    async addCommodity(ctx, commodity) {
        console.log(commodity);
        // const commodity = new Commodity(JSON.parse(commodityJSON));
        // console.log(commodity);
        const key = ctx.stub.createCompositeKey('Commodity', [commodity.getTradingSymbol(), commodity.getTradeId()]);
        console.log(key);
github hyperledger / fabric-chaincode-node / libraries / fabric-shim / lib / contract-spi / systemcontract.js View on Github external
/*
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
*/
'use strict';

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

/**
 * This is a contract that determines functions that can be invoked to provide general information
 *
 * @class
 * @memberof fabric-contract-api
 */
class SystemContract extends Contract {

    constructor() {
        super('org.hyperledger.fabric');
    }

    /**
	 *
	 * @param {Object} chaincode
github hyperledger / fabric-chaincode-node / libraries / fabric-shim / lib / contract-spi / chaincodefromcontract.js View on Github external
_augmentMetadataFromCode(metadata) {

        if (!metadata.$schema) {
            metadata.$schema = 'https://fabric-shim.github.io/master/contract-schema.json';
        }

        if (!metadata.contracts || Object.keys(metadata.contracts).length === 0) {
            logger.debug('_augmentMetadataFromCode - Contracts not supplied. Generating default');

            const Contract = require('fabric-contract-api').Contract;
            const skipNames = Object.getOwnPropertyNames(Contract.prototype);

            metadata.contracts = JSON.parse(JSON.stringify(this.contractImplementations));

            for (const contractKey in metadata.contracts) {
                const contract = metadata.contracts[contractKey];

                for (const instanceKey in contract.contractInstance) {
                    if (instanceKey.startsWith('_')) {
                        delete contract.contractInstance[instanceKey];
                    }
                }

                const impl = this.contractImplementations[contractKey].contractInstance;

                contract.transactions = this._processContractTransactions(impl, skipNames);
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;
            }