@hsuite/snapshots
A powerful NestJS module for generating, managing, and storing token holder snapshots on the Hedera network with real-time progress tracking via WebSockets.
Features
Asynchronous snapshot generation using Bull queues
Real-time progress tracking via WebSocket events
IPFS integration for decentralized storage
JWT authentication for secure WebSocket connections
Rate-limited API calls to Hedera network
Comprehensive error handling and logging
TypeScript support with full type definitions
Installation
Dependencies
This module requires the following peer dependencies:
@nestjs/common: ^10.4.2
@nestjs/core: ^10.4.2
And the following dependencies:
@hsuite/hashgraph: 2.0.0
@hsuite/auth-types: 2.0.0
@hsuite/ipfs: 2.0.0
@hsuite/nestjs-swagger: 2.0.0
@hashgraph/sdk: ^2.51.0
Module Configuration
Import and configure the module in your NestJS application:
Usage
Generating Snapshots
WebSocket Client Integration
WebSocket Events
The module emits the following events:
snapshots_progress
Progress update during generation
{ jobId, jobName, snapshotId, status: 'running', progress }
snapshots_active
Job started processing
{ jobId, jobName, snapshotId, status: 'activated', progress: 0 }
snapshots_completed
Job completed successfully
{ jobId, jobName, snapshotId, status: 'completed', progress: 100 }
snapshots_failed
Job failed with error
{ jobId, jobName, snapshotId, status: 'error', error }
Architecture
The module consists of several key components:
SnapshotsService: Main service for initiating snapshot generation
SnapshotsConsumer: Bull queue consumer for processing snapshots
SnapshotsGateway: WebSocket gateway for real-time updates
SnapshotsEvents: Event handling for queue operations
Processing Flow
Client requests snapshot generation via REST API
Service creates a Bull queue job
Consumer processes job in background:
Fetches token balances from Hedera (rate-limited)
Updates progress via WebSocket
Uploads final data to IPFS
Client receives real-time updates via WebSocket
Rate Limiting
The module implements rate limiting for Hedera API calls:
Batch size: 25 accounts per request
Delay: 1 second between API calls
Progress tracking: Updates after each batch
Documentation
Generate detailed documentation using Compodoc:
For documentation with coverage report:
License
This package is part of the HSuite Enterprise ecosystem.
Contributing
Please refer to the HSuite contribution guidelines.
Built with ❤️ by the HbarSuite Team Copyright © 2024 HbarSuite. All rights reserved.
Last updated