2024-11-29 @DanteBartel
The Staking API Service is focused on serving information about dApps, general message passing (GMP) and staking transactions. These information can be utilised by Scalar Staking app and Scanner app for user to review and interact with.
- DApps
- Serve information about dApps
- CRUD methods for dApps
- Serve information about Custodials
- GMP
- Serve information about GMP
- Staking transactions
- Serve information about staking transactions
The application is structured with the following key components:
-
API Handlers
HealthCheck
: Health check endpoint for service monitoringStakingHandler
: Manages staking operations and queries
-
Service Layer
StakingService
: Business logic for staking operationsFinalityProviderService
: Manages finality provider operations
-
Database Layer
PostgreSQL
: Primary data store using GORM
-
Configuration
ConfigLoader
: Handles YAML-based configurationEnvironmentLoader
: Manages environment variablesFinalityProviderConfig
: Manages finality provider settings
-
Middleware
CORS
: Cross-Origin Resource Sharing handlerSecurity
: Request security middlewareSwagger
: API documentation middleware
src/
├── api/ # API handlers and routes
├── config/ # Configuration files
├── docs/ # API documentation
├── internal/ # Internal packages
│ ├── service/ # Logic services
│ ├── models/ # Data models
│ └── db/ # Database interfaces
└── cmd/ # Application entry points
The service uses the following key dependencies:
- Chi router for HTTP routing
- GORM for database operations
- Swagger for API documentation
- Prometheus for metrics
- Zerolog for logging
- Docker
- Go
- Clone the repository:
git clone https://github.com/scalarorg/scalar-api
- Prepare the config
Edit the config/config-local.yml
file to match your local environment.
- Run the service:
make run-local
OR, you can run as a docker container
make start-xchains-api
- Open your browser and navigate to
http://localhost:<port>
to see the api server running, where<port>
is the port specified in theconfig/config-local.yml
file.
The service only contains integration tests so far, run below:
make tests
- Make sure the interfaces such as the
DBClient
is up to date - Install
mockery
: https://vektra.github.io/mockery/latest/ - Run
make generate-mock-interface