generated from axone-protocol/template-oss
-
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.
- Loading branch information
1 parent
cf98e2e
commit be482b8
Showing
20 changed files
with
196 additions
and
17 deletions.
There are no files selected for viewing
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
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,36 @@ | ||
import { WithPaginationResponse } from "./with-pagination.response"; | ||
|
||
export type RewardsHistoryResponse = WithPaginationResponse<{ | ||
tx_responses: Tx[]; | ||
}>; | ||
|
||
|
||
export interface Tx { | ||
txhash: string; | ||
code: number; | ||
timestamp: string; | ||
tx: { | ||
body: { | ||
messages: Array<{ | ||
"@type": string | ||
}>; | ||
} | ||
}; | ||
events: Event[]; | ||
} | ||
|
||
export interface Event { | ||
type: string; | ||
attributes: [ | ||
{ | ||
key: string; | ||
value: string; | ||
index: string; | ||
}, | ||
{ | ||
key: string; | ||
value: string; | ||
index: string; | ||
} | ||
] | ||
} |
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
File renamed without changes.
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,6 @@ | ||
export interface GetWalletRewardsHistoryDto { | ||
address: string; | ||
limit?: number; | ||
offset?: number; | ||
} | ||
|
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,4 @@ | ||
export enum WalletPrefix { | ||
WALLET = 'wallet', | ||
REWARDS_HISTORY = 'rewards_history', | ||
} |
File renamed without changes.
5 changes: 5 additions & 0 deletions
5
src/modules/wallet/schemas/get-wallet-rewards-history.schema.ts
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,5 @@ | ||
import * as Joi from "joi"; | ||
|
||
export const GetWalletRewardsHistorySchema = Joi.object({ | ||
address: Joi.string().required(), | ||
}) |
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,34 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
|
||
import { RedisService } from "@core/lib/redis.service"; | ||
import { config } from "@core/config/config"; | ||
import { WalletPrefix } from "./enums/wallet-prefix.enum"; | ||
|
||
@Injectable() | ||
export class WalletCache { | ||
constructor( | ||
private readonly redisService: RedisService, | ||
) { } | ||
|
||
async setWalletRewardHistory(hash: string, history: unknown) { | ||
await this.redisService.setWithTTL(this.createRedisKey(WalletPrefix.REWARDS_HISTORY, hash), JSON.stringify(history), config.cache.walletRewardHistory); | ||
} | ||
|
||
async getWalletRewardHistory(hash: string) { | ||
return this.getObjectFromRedis(this.createRedisKey(WalletPrefix.REWARDS_HISTORY, hash)); | ||
} | ||
|
||
private async getObjectFromRedis<T>(key: string): Promise<T | null> { | ||
const serialized = await this.redisService.get(key); | ||
|
||
if (!serialized) { | ||
return null; | ||
} | ||
|
||
return JSON.parse(serialized as string); | ||
} | ||
|
||
private createRedisKey(...ids: string[]) { | ||
return ids.reduce((acc, id) => acc + `_${id}`, `${WalletPrefix.WALLET}`); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export enum WalletRoutesEnum { | ||
BALANCES = 'balances', | ||
REWARD_HISTORY = 'reward-history', | ||
} |
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,5 @@ | ||
import { createHash } from "crypto"; | ||
|
||
export function hash(obj: unknown): string { | ||
return createHash("sha256").update(JSON.stringify(obj)).digest("hex"); | ||
} |
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,7 @@ | ||
export function extractNumbers(string: string): number[] { | ||
const matches = string.match(/\d+/g); | ||
if (matches) { | ||
return matches.map(Number); | ||
} | ||
return []; | ||
} |