-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #223 from sotatek-dev/develop
Develop
- Loading branch information
Showing
9 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { ENetworkName } from '../../../constants/blockchain.constant.js'; | ||
import { StringField } from '../../../shared/decorators/field.decorator.js'; | ||
|
||
export class EstimateBridgeRequestDto { | ||
@StringField({ | ||
enum: ENetworkName, | ||
}) | ||
receivedNetwork: ENetworkName; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { createClient, RedisClientType } from 'redis'; | ||
|
||
import { ENetworkName } from '../../../constants/blockchain.constant.js'; | ||
import { EEnvKey } from '../../../constants/env.constant.js'; | ||
|
||
@Injectable() | ||
export class RedisClientService implements OnModuleInit, OnModuleDestroy { | ||
private client: RedisClientType; | ||
constructor(private readonly configService: ConfigService) { | ||
this.client = createClient({ | ||
url: `redis://${configService.get(EEnvKey.REDIS_HOST)}:${configService.get(EEnvKey.REDIS_PORT)}`, | ||
}); | ||
} | ||
async onModuleInit() { | ||
await this.client.connect(); | ||
} | ||
async onModuleDestroy() { | ||
await this.client.disconnect(); | ||
} | ||
// noti | ||
// public async getCurrentNotificationCount(address: string): Promise<number> { | ||
// const res = await this.client.get(`not_count_${address}`); | ||
// return Number(res).valueOf(); | ||
// } | ||
// public async incrNotificationCount(address: string): Promise<number> { | ||
// return this.client.incr(`not_count_${address}`); | ||
// } | ||
|
||
// public async resetNotificationCount(address: string) { | ||
// return this.client.set(`not_count_${address}`, 0); | ||
// } | ||
// estimate bridge time | ||
async getCountWaitingTx(network: ENetworkName): Promise<number> { | ||
const res = await this.client.get(`waiting_tx_${network}`); | ||
return Number(res).valueOf(); | ||
} | ||
public async initCountWaitingTx(network: ENetworkName, initValue: number) { | ||
return this.client.set(`waiting_tx_${network}`, initValue); | ||
} | ||
public async incrCountWaitingTx(network: ENetworkName): Promise<number> { | ||
return this.client.incr(`waiting_tx_${network}`); | ||
} | ||
|
||
public async decrCountWaitingTx(network: ENetworkName) { | ||
return this.client.eval(` | ||
local key='waiting_tx_${network}' | ||
local current_value = tonumber(redis.call('GET', key) or 0) | ||
if current_value == 0 then | ||
return current_value | ||
else | ||
-- Decrement the value by 1 | ||
local new_value = current_value - 1 | ||
redis.call('SET', key, new_value) | ||
return new_value | ||
end | ||
`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Global, Module } from '@nestjs/common'; | ||
|
||
import { RedisClientService } from './redis-client.service.js'; | ||
|
||
@Global() | ||
@Module({ | ||
providers: [RedisClientService], | ||
exports: [RedisClientService], | ||
}) | ||
export class RedisModule {} |