hyperledger / fabric-gateway

Go, Node and Java client API for Hyperledger Fabric v2.4+
https://hyperledger.github.io/fabric-gateway/
Apache License 2.0
154 stars 91 forks source link

invoking qscc contract function from another contract #536

Closed sami96h closed 1 year ago

sami96h commented 1 year ago

Im trying to retrieve transaction details using the GetTransactionByID function , but im getting this error => "Rejecting invoke of QSCC from another chaincode because of potential for deadlocks, original invocation for 'demo-contract'"

Here is the code : async GetAllResults(ctx, iterator) { let allResults = []; let res = { done: false, value: null };

    while (true) {
        res = await iterator.next();
        let jsonRes = {};
        if (res.value && res.value.value.toString()) {

            jsonRes.TxId = res.value.txId;
            const response= await ctx.stub.invokeChaincode('qscc',['GetTransactionByID',res.value.txId])
            jsonRes.test=response
            jsonRes.Timestamp = res.value.timestamp;
            jsonRes.Timestamp = new Date((res.value.timestamp.seconds.low * 1000));
            let ms = res.value.timestamp.nanos / 1000000;
            jsonRes.Timestamp.setMilliseconds(ms);
            if (res.value.is_delete) {
                jsonRes.IsDelete = res.value.is_delete.toString();
            } else {
                try {
                    jsonRes.Value = JSON.parse(res.value.value.toString('utf8'));

                } catch (err) {
                    console.log(err);
                    jsonRes.Value = res.value.value.toString('utf8');
                }
            }

            allResults.push(jsonRes);
        }
        if (res.done) {

            await iterator.close();
            return allResults;
        }

    }  
}
bestbeforetoday commented 1 year ago

Issues related to Node chaincode should be addressed to the fabric-chaincode-node repository. However...

Cross chaincode calls to the qscc (and cscc) system chaincode do seem to be explicitly disallowed. Perhaps you will need to return the transaction IDs of interest from your smart contract, and then have the client separately evaluate the qscc chaincode's GetTransactionByID transaction function.