How to have monotonically increasing counter for global unique ID ? #fabric-questions


pham.qtpham@...
 

Hi,

In my app for Supply Chain Management, there is equipmentNumber, which should be a global unique ID. How can I achieve this using Javascript?

E.g. the smart contract in Javascript as below:

...

'use strict';

// Fabric smart contract classes

const { Contract, Context } = require('fabric-contract-api');

 

/**

 * Define smart contract by extending Fabric Contract class

 *

 */

class PharmaLedgerContract extends Contract {

 

    constructor() {

        // Unique namespace pcn - PharmaChainNetwork when multiple contracts per chaincode file

        super('org.pln.PharmaLedgerContract');

    }

    /**

     * Instantiate to set up ledger.

     * @param {Context} ctx the transaction context

     */

    async instantiate(ctx) {

        // No default implementation for this example

        console.log('Instantiate the PharmaLedger contract');

    }

 

    /**

     * Create pharma equipment

     *

     * @param {Context} ctx the transaction context

     * @param {String} equipment manufacturer

     * @param {String} equipmentNumber for this equipment

     * @param {String} equipment name

     * @param {String} equipment commercial name

     * @param {String} equipment composition

     * @param {String} equipment common side effects

     * @param {String} equipment cost

     * @param {String} equipment retailed cost

     * @param {String} equipment quantity

     * @param {String} name of the equipment owner

    */

   async makeEquipment(ctx, manufacturer, equipmentNumber, equipmentName, equipmentCommercialName, equipmentComposition, equipmentCommonSideEffects, equipmentCost, equipmentQuantity, equipmentRetailedCost,ownerName) {

        console.info('============= START : makeEquipment call ===========');

        let dt = new Date().toString();

        const equipment = {

            equipmentNumber,

            manufacturer,

            equipmentName,

            equipmentCommercialName,

            equipmentComposition,

            equipmentCommonSideEffects,

            equipmentCost,

            equipmentQuantity,

            equipmentRetailedCost,

            equipmentTotalCost: '0',

            previousQuantityBalance: '0',

            currentQuantityBalance: '0',

            ownerName,

            previousOwnerType: 'MANUFACTURER',

            currentOwnerType: 'MANUFACTURER',

            createDateTime: dt,

            lastUpdated: dt

        };

        await ctx.stub.putState(equipmentNumber, Buffer.from(JSON.stringify(equipment)));

        console.info('============= END : Create equipment ===========');

   }

 

Join fabric@lists.hyperledger.org to automatically receive all group messages.