cello icon indicating copy to clipboard operation
cello copied to clipboard

[#672] Implement chaincode invoke demo functionality with comprehensive TLS integration

Open sangwaboi opened this issue 6 months ago • 1 comments

Summary

Implements chaincode invoke demo functionality for issue #672. Adds a REST API endpoint to enable programmatic chaincode invocation on Hyperledger Fabric networks managed by Cello.

Problem Addressed

Users needed a way to invoke chaincode functions through Cello's API without requiring manual Fabric CLI commands, enabling better integration with applications and automated testing workflows.

Solution Implemented

  • New REST Endpoint: POST /api/v1/chaincodes/invoke
  • Input Validation: ChainCodeInvokeBody serializer with comprehensive field validation
  • Authentication: JWT token-based authentication with organization context
  • TLS Security: Integration with existing Fabric peer certificate infrastructure
  • Error Handling: Detailed error responses with proper HTTP status codes

API Usage

POST /api/v1/chaincodes/invoke
Content-Type: application/json
Authorization: Bearer <jwt_token>

{
  "channel_name": "mychannel",
  "chaincode_name": "basic",
  "args": ["CreateAsset", "asset1", "blue", "35", "tom", "1000"],
  "init": false
}

Technical Implementation

Core Components:

  • ChainCodeInvokeBody serializer for request validation
  • Invoke action method in ChainCodeViewSet with proper error handling
  • TLS certificate resolution for orderer and peer communication
  • JSON argument formatting for Fabric peer CLI integration

Integration Points:

  • Uses existing PeerChainCode.invoke() method
  • Leverages current authentication and organization management
  • Follows established patterns from other chaincode lifecycle endpoints

Files Modified

  • src/api-engine/api/routes/chaincode/serializers.py - Request validation logic
  • src/api-engine/api/routes/chaincode/views.py - Main endpoint implementation
  • src/agent/docker-rest-agent/server.py - Enhanced node creation handling
  • src/api-engine/api/lib/agent/docker/handler.py - Improved error logging
  • src/api-engine/api/routes/node/views.py - Better resource validation messages
  • bootup/docker-compose-files/docker-compose.dev.yml - Development environment improvements

Testing Status

  • Code compiles and imports successfully
  • Serializer validation implemented and tested
  • Authentication integration verified
  • TLS certificate handling implemented
  • Error responses properly formatted
  • No breaking changes to existing functionality
  • Swagger documentation auto-generated

Security and Compatibility

  • All invoke operations require valid JWT authentication
  • Users can only access their organization's peer nodes
  • TLS encryption for all Fabric network communication
  • Comprehensive input validation to prevent injection attacks
  • Backward compatible with existing chaincode endpoints
  • Follows existing API versioning conventions

Notes for Review

This implementation extends the existing chaincode lifecycle management infrastructure without disrupting current functionality. The code follows established Cello patterns and integrates seamlessly with the current authentication and certificate management systems.

Closes #672

sangwaboi avatar May 27 '25 20:05 sangwaboi

@YoungHypo could you please review this PR ..

sangwaboi avatar Jun 08 '25 05:06 sangwaboi

Need to resolve the conflicts first.

yeasy avatar Jul 05 '25 00:07 yeasy

Better migrate to the gateway mode. Will close first.

yeasy avatar Aug 16 '25 01:08 yeasy