0

Currently I'm working with Hyperledger Fabric chaincode and trying to get the hash of last block but I haven't found any way to get it. I need my chaincode to access this hash to do a security check.

I have tried to invoke qscc from my chaincode, which from a client does return blockchain and hash block information, but in this way access is restricted.

Code

   @Transaction()
   public String getBlockHash(final Context ctx) {
       ChaincodeStub stub = ctx.getStub();
       String[] argsQscc = {"GetChainInfo","mychannel"};
       Response response = stub.invokeChaincodeWithStringArgs("qscc", argsQscc);
       System.out.println("Result"+response.getMessage());
       return response.getMessage();
   }

Error Rejecting invoke of QSCC from another chaincode because of potential for deadlocks, original invocation for 'mychaincode'.

1 Answers1

0

It is not possible to get from within chaincode. I'm not sure you would want to anyways, because different peers may be at different heights and you would get different endorsement results leading to an invalidation of your transaction.

I'd suggest to have client query this information and pass it into the invoked chaincode as an input.

Dave Enyeart
  • 2,523
  • 14
  • 23