Staking API Service
2024-11-29 @DanteBartel
π Overview
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.
π Key Features
- 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
π Components
The application is structured with the following key components:
Core Components
-
API Handlers
HealthCheck
: Health check endpoint for service monitoring
StakingHandler
: Manages staking operations and queries
-
Service Layer
StakingService
: Business logic for staking operations
FinalityProviderService
: Manages finality provider operations
-
Database Layer
PostgreSQL
: Primary data store using GORM
Infrastructure Components
-
Configuration
ConfigLoader
: Handles YAML-based configuration
EnvironmentLoader
: Manages environment variables
FinalityProviderConfig
: Manages finality provider settings
-
Middleware
CORS
: Cross-Origin Resource Sharing handler
Security
: Request security middleware
Swagger
: API documentation middleware
Directory Structure
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
π Getting Started
Prerequisites
Installation
- 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 the config/config-local.yml
file.
π Tests
The service only contains integration tests so far, run below:
make tests
π Update Mocks
- 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