This Hyperledger Fabric chaincode manages Zakat transactions for YDSF Malang and YDSF Jatim organizations. It provides a transparent and immutable record of Zakat collection and distribution.
This is a release candidate (RC) version with:
- Feature-complete implementation
- Comprehensive validation rules
- Full test coverage
- Error handling
- Pending production validation
- Secure Zakat transaction management
- Comprehensive validation rules
- Full test coverage
- Production-ready error handling
- Support for multiple organizations
- Transparent distribution tracking
- Hyperledger Fabric 2.4.0+
- Go 1.20+
- Docker and Docker Compose
type Zakat struct {
ID string `json:"ID"` // Format: ZKT-ORG-YYYYMM-NNNN
Muzakki string `json:"muzakki"` // Zakat donor's name
Amount float64 `json:"amount"` // Amount in IDR
Type string `json:"type"` // "fitrah" or "maal"
Status string `json:"status"` // "collected" or "distributed"
Organization string `json:"organization"` // Collecting organization
Timestamp string `json:"timestamp"` // ISO 8601 format
Mustahik string `json:"mustahik"` // Recipient's name (if distributed)
Distribution float64 `json:"distribution"` // Distributed amount
DistributedAt string `json:"distributedAt"`// Distribution timestamp (ISO 8601)
}
The Zakat ID follows a specific format to ensure uniqueness and traceability:
- Format:
ZKT-{ORG}-{YYYY}{MM}-{COUNTER}
- Example:
ZKT-YDSF-MLG-202311-0001
- Components:
ZKT
: Fixed prefix for Zakat transactionsORG
: Organization identifier (e.g., YDSF-MLG, YDSF-JTM)YYYY
: 4-digit yearMM
: 2-digit monthCOUNTER
: 4-digit sequential counter
- Description: Initializes the ledger with a sample Zakat transaction
- Validation:
- Checks if initial transaction already exists
- Validates all fields using standard validation functions
- Uses current timestamp in ISO 8601 format
- Error Handling:
- Returns descriptive errors for validation failures
- Handles GetState and PutState errors
- Returns: Error if initialization fails
- Description: Records a new Zakat donation
- Parameters:
zakatId
: Unique identifier (must follow ID format)donorName
: Name of the Zakat donoramount
: Monetary amount (must be positive)zakatType
: Type of Zakat ("maal" or "fitrah")organization
: Receiving organization (must be authorized)date
: Date of donation (ISO 8601 format)
- Validation:
- Validates ID format
- Checks for existing transactions
- Validates amount and organization
- Verifies timestamp format
- Returns: Error if validation fails or transaction exists
- Description: Retrieves details of a specific Zakat transaction
- Parameters:
zakatId
: Unique identifier for the Zakat transaction
- Returns: Complete transaction details or error if not found
- Description: Retrieves all Zakat transactions from the ledger
- Returns: Array of all Zakat transactions
- Error Handling: Returns error if retrieval fails
- Description: Records the distribution of a Zakat transaction
- Parameters:
zakatId
: Unique identifier of the Zakat to distributemustahik
: Name of the recipientamount
: Amount distributedtimestamp
: Distribution timestamp (ISO 8601)
- Validation:
- Verifies Zakat exists and is not distributed
- Validates distribution amount
- Checks timestamp format
- Returns: Error if validation fails or Zakat not found
- Description: Checks if a Zakat transaction exists
- Parameters:
zakatId
: Unique identifier to check
- Returns: Boolean indicating existence and any error
- Must follow pattern:
ZKT-{ORG}-{YYYY}{MM}-{COUNTER}
- Organization must be valid
- Date components must be valid
- Must be positive number
- Must be greater than 0
- Distribution amount cannot exceed original amount
- Must be either "YDSF Malang" or "YDSF Jatim"
- Must be authorized in the network
- Must be either "maal" or "fitrah"
- Cannot be changed after creation
- Automatically set to "collected" on creation
- Changes to "distributed" after successful distribution
- Cannot be manually modified
- Must be in ISO 8601 format
- Cannot be future dates
- Distribution date must be after collection date
The chaincode includes comprehensive test coverage:
cd chaincode/zakat
go test -v
- Input validation for all parameters
- Status transitions are strictly controlled
- Organization validation enforced
- Transaction integrity checks
- No direct status manipulation allowed
- Timestamp validation to prevent future dating
- Organization receives Zakat via
AddZakat()
- Transaction is recorded with "collected" status
- Organization distributes via
DistributeZakat()
- Status updates to "distributed"
- Full history maintained on chain
This project is licensed under the MIT License - see the LICENSE file for details.