in src/main/java/com/lambdajavablockchain/controller/ApiController.java [110:141]
public ResponseEntity<?> invoke(@RequestBody @Valid InvokeRequest invokeRequest) {
try {
log.debug("Invoking chaincode with payload:" + invokeRequest.toString());
service.setupClient();
// First retrieve LambdaUser's credentials and set user context
service.setUser(AMBConfig.LAMBDAUSER);
service.initChannel();
// build arguments list required by the chaincode
String[] arguments = invokeRequest.getArgList().stream().toArray(String[]::new);
service.invokeChaincode(service.getClient(), service.getChannel(),
invokeRequest.getChaincodeName(),
invokeRequest.getFunctionName(),
arguments);
return new ResponseEntity<>("Invoke successful", HttpStatus.ACCEPTED);
} catch (EnrollmentNotFoundException | AppException e){
log.error("Error while invoking chaincode - " + e.getMessage());
return new ResponseEntity<>("Error while invoking chaincode - " + e.getMessage(), HttpStatus.BAD_REQUEST);
} catch (ManagedBlockchainServiceException e) {
log.error("Error while invoking chaincode, ManagedBlockchainService startup failed - " + e.getMessage());
return new ResponseEntity<>("Error while invoking chaincode, ManagedBlockchainService startup failed - "
+ e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
} catch (Exception e) {
log.error("Error while invoking - function:" + invokeRequest.getFunctionName() +
"chaincode:" + invokeRequest.getFunctionName());
e.printStackTrace();
return new ResponseEntity<>("Error while invoking chaincode", HttpStatus.INTERNAL_SERVER_ERROR);
}
}