src/quorum/quorum.js
/**
     * Query the given chaincode according to the specified options.
     * @param {object} context The Quorum context returned by {getContext}.
     * @param {string} contractID The name of the chaincode.
     * @param {string} contractVer The version of the chaincode.
     * @param {string} key The argument to pass to the chaincode query.
     * @return {Promise<object>} The promise for the result of the execution.
     */
Query the given chaincode according to the specified options.
@param {object} context The Quorum context returned by {getContext}.
@param {string} contractID The name of the chaincode.
@param {string} contractVer The version of the chaincode.
@param {string} key The argument to pass to the chaincode query.
@return {Promise} The promise for the result of the execution.
Query the given chaincode according to the specified options . @param { object } context The Quorum context returned by { getContext } . @param { string } contractID The name of the chaincode . @param { string } contractVer The version of the chaincode . @param { string } key The argument to pass to the chaincode query . @return { Promise } The promise for the result of the execution .
queryState(context, contractID, contractVer, key) {
        let address = contractID[0];
        let abi = contractID[1];
        let promises = [];
        let self = this;
        let func = "query";  
        let txStatus = new TxStatus("00000000000");
        let all_idx = [];
        let num_web3s = context.web3s.length;
        for (var i = 0;i < num_web3s; i++) {all_idx.push(i); }
        let selected_idx = commUtils.shuffle(all_idx).slice(0, 1);
        context.web3s.forEach((web3, idx)=>{
            if (selected_idx.includes(idx)) {
                let query_promise = web3.eth.getAccounts().then((accounts)=>{
                    let from_acc = accounts[0];
                    let contractInstance = new web3.eth.Contract(abi, address);
                    return contractInstance.methods[func](key).call({from: from_acc});
                });
                promises.push(query_promise);
            }
        });
        return Promise.all(promises).then((results)=>{
            txStatus.SetStatusSuccess();
            txStatus.SetResult(results[0]);
            txStatus.SetVerification(true);
            return Promise.resolve(txStatus);
        }).catch( (err) => {
            commUtils.log("Fail to query on key ", key);
            return Promise.reject(err);
        });
    }
queryState ( context , contractID , contractVer , key ) { let address = contractID [ 0 ] ; let abi = contractID [ 1 ] ; let promises = [ ] ; let self = this ; let func = "query" ; let txStatus = new TxStatus ( "00000000000" ) ; let all_idx = [ ] ; let num_web3s = context . web3s . length ; for ( var i = 0 ; i < num_web3s ; i ++ ) { all_idx . push ( i ) ; } let selected_idx = commUtils . shuffle ( all_idx ) . slice ( 0 , 1 ) ; context . web3s . forEach ( ( web3 , idx ) => { if ( selected_idx . includes ( idx ) ) { let query_promise = web3 . eth . getAccounts ( ) . then ( ( accounts ) => { let from_acc = accounts [ 0 ] ; let contractInstance = new web3 . eth . Contract ( abi , address ) ; return contractInstance . methods [ func ] ( key ) . call ( { from : from_acc } ) ; } ) ; promises . push ( query_promise ) ; } } ) ; return Promise . all ( promises ) . then ( ( results ) => { txStatus . SetStatusSuccess ( ) ; txStatus . SetResult ( results [ 0 ] ) ; txStatus . SetVerification ( true ) ; return Promise . resolve ( txStatus ) ; } ) . catch ( ( err ) => { commUtils . log ( "Fail to query on key " , key ) ; return Promise . reject ( err ) ; } ) ; }
Query the given chaincode according to the specified options.
Query the given chaincode according to the specified options .
// Assume each quorum contract has a function named as 'get' // let selected_idx = commUtils.shuffle(all_idx).slice(0, num_web3s / 2 + 1); // return self.callMethod(contractInstance, func, [key], from_acc, endpoint); }); // console.log("Promise len: ", promises.length); // Resolve only all nodes reply // console.log("Query Result: ", results[0]);