A Python implementation of the JAM (Joint Accumulator Mechanism) protocol, featuring a safrole component for state management and block processing.
Jam_python/
├── config/ # Configuration files
├── docs/ # Documentation
├── examples/ # Basic usage examples
├── server/ # 🆕 JAM Safrole Integration Server
│ ├── app.py # FastAPI server application
│ ├── client_example.py # Example client implementation
│ ├── test_server.py # Server testing script
│ ├── sample_data.json # Sample data for testing
│ ├── start_server.sh # Server startup script
│ ├── requirements.txt # Server dependencies
│ └── README.md # Server documentation
├── src/ # Core JAM implementation
│ └── jam/
│ ├── core/ # Core protocol logic
│ │ └── safrole_manager.py
│ ├── protocols/ # Protocol implementations
│ └── utils/ # Utility functions
├── tests/ # Test suite
├── main.py # Main application entry point
├── requirements.txt # Project dependencies
└── setup.py # Package setup
- Core JAM Protocol: Implementation of the Joint Accumulator Mechanism
- Safrole Component: State management and block processing
- Integration Server: 🆕 REST API server for external integration
- Crypto Bridge: Cryptographic operations and verification
- Fallback Conditions: Protocol fallback mechanisms
- Comprehensive Testing: Unit and integration tests
The project now includes a FastAPI-based REST server that provides a clean interface to the JAM protocol's safrole component. This server allows external systems to:
- Initialize the safrole manager with pre_state data
- Process blocks and update protocol state
- Monitor current system state
- Reset the manager when needed
-
Navigate to server directory:
cd server -
Install server dependencies:
pip install -r requirements.txt
-
Start the server:
python app.py # Or use the startup script: ./start_server.sh -
Access API documentation:
- Interactive docs: http://localhost:8000/docs
- Alternative docs: http://localhost:8000/redoc
-
Test the server:
python test_server.py
| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
Server information |
GET |
/health |
Health check |
POST |
/initialize |
Initialize safrole manager |
POST |
/process-block |
Process a block |
GET |
/state |
Get current state |
POST |
/reset |
Reset manager |
For detailed server documentation, see server/README.md.
- Python 3.8+
- pip package manager
-
Clone the repository:
git clone <repository-url> cd Jam_python
-
Install dependencies:
pip install -r requirements.txt
-
Install server dependencies (optional):
cd server pip install -r requirements.txt cd ..
from src.jam.core.safrole_manager import SafroleManager
# Initialize with pre_state
manager = SafroleManager(pre_state_data)
# Process a block
result = manager.process_block(block_input)import requests
# Initialize safrole manager
response = requests.post("http://localhost:8000/initialize", json=pre_state_data)
# Process blocks
response = requests.post("http://localhost:8000/process-block", json=block_data)
# Get current state
response = requests.get("http://localhost:8000/state")# Basic usage examples
python examples/basic_usage.py
# Server client example
cd server
python client_example.py# Run all tests
python -m pytest tests/
# Test the server
cd server
python test_server.pyThe project uses YAML configuration files in the config/ directory. See config/config.yaml for available options.
src/jam/core/: Core protocol implementationsrc/jam/protocols/: Protocol-specific implementationssrc/jam/utils/: Utility functions and crypto bridgeserver/: Integration server and APItests/: Comprehensive test suite
- Follow the existing code structure
- Add appropriate tests
- Update documentation
- Ensure compatibility with the integration server
SafroleManager: Main JAM protocol managerCryptoBridge: Cryptographic operationsFallbackCondition: Protocol fallback logic
BlockInput: Block input data structurePreState: Protocol pre-state structureStateRequest: Complete state requestStateResponse: Standardized response format
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
This project is licensed under the same terms as the JAM protocol specification.
For questions and support:
- Check the documentation in
docs/ - Review the examples in
examples/ - Test with the integration server
- Open an issue for bugs or feature requests
Note: The integration server requires the JAM source code to be accessible in the src/ directory. Ensure proper setup before running the server.