3.0 KiB
3.0 KiB
Overview
The Repository contract is a decentralized version control system that allows users to create, manage, and track repositories on the blockchain. It provides functionality for creating repositories, adding commits, and retrieving repository metadata and commit history.
Interface
| Function | Parameters | Returns | Description |
|---|---|---|---|
createRepository |
name (string), description (string), isPublic (bool) |
bytes32 |
Create a new repository with unique identifier |
addCommit |
repositoryId (bytes32), commitHash (bytes32), message (string), parentCommitHash (bytes32) |
void |
Add a commit to a specific repository |
getRepository |
repositoryId (bytes32) |
RepositoryMetadata |
Retrieve repository metadata |
getRepositoryCommits |
repositoryId (bytes32) |
Commit[] |
Retrieve all commits for a repository |
getUserRepositories |
user (address) |
bytes32[] |
Retrieve all repositories owned by a user |
Events
-
RepositoryCreated: Emitted when a new repository is createdrepositoryId: Unique identifier of the repositoryowner: Address of the repository creatorname: Name of the repository
-
CommitAdded: Emitted when a new commit is added to a repositoryrepositoryId: Identifier of the repositorycommitHash: Hash of the commitauthor: Address of the commit author
Storage Layout
repositories: Mapping of repository IDs to repository metadatarepositoryCommits: Mapping of repository IDs to array of commitsuserRepositories: Mapping of user addresses to array of repository IDs
Access Control
- Repository creation is open to any user
- Only repository owners can add commits to their repositories
- Repository visibility can be set to public or private
- Modifiers validate repository name length
Security Considerations
- Use of
keccak256for generating unique repository IDs - Checks for repository existence before operations
- Owner-only commit addition prevents unauthorized modifications
- Input validation for repository names
- Use of
bytes32for efficient storage and comparison
Deployment
ChunkNet Devnet Deployment Parameters
- RPC URL: https://rpc.chunknet.org
- Chain ID: 214562
- Recommended Deployment Tools:
- Hardhat
- Foundry
- Truffle
Deployment Script Example
bash
forge create Repository
--rpc-url https://rpc.chunknet.org
--private-key $PRIVATE_KEY
--chain 214562
Testing
Recommended Test Scenarios
-
Repository creation
- Validate repository ID generation
- Check event emissions
- Test name length constraints
-
Commit management
- Add commits to repositories
- Verify commit metadata
- Test owner-only commit restrictions
-
Retrieval functions
- Get repository metadata
- Retrieve commits
- List user repositories
Test Coverage
- Unit tests for each function
- Integration tests with other system contracts
- Edge case and error handling tests