Skip to content

Conversation

@sangwaboi
Copy link

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 and others added 2 commits May 28, 2025 00:53
…RM64, fix build dependencies, use named volumes

Signed-off-by: Vishvendra <[email protected]>
…lement POST /api/v1/chaincodes/invoke endpoint with proper TLS integration and error handling - Close hyperledger-cello#672

Signed-off-by: Vishvendra <[email protected]>
@yeasy yeasy requested a review from YoungHypo May 29, 2025 20:54
…ith peer_list field and ChainCodeInvokeBody serializer
@sangwaboi
Copy link
Author

@YoungHypo could you please review this PR ..

Vishvendra and others added 5 commits June 10, 2025 10:44
…lity - Fix code formatting issues and implement invoke endpoint

Signed-off-by: Vishvendra <[email protected]>
…cker fixes, linting improvements, and comprehensive TLS functionality

Signed-off-by: Vishvendra <[email protected]>
…flake8 errors from 111 to 40 (64% improvement)

Signed-off-by: Vishvendra <[email protected]>
@yeasy
Copy link
Contributor

yeasy commented Jul 5, 2025

Need to resolve the conflicts first.

@yeasy
Copy link
Contributor

yeasy commented Aug 16, 2025

Better migrate to the gateway mode. Will close first.

@yeasy yeasy closed this Aug 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Chaincode Invoke Demo

2 participants