Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MEX-527] Pairs memory store service #1539

Open
wants to merge 2 commits into
base: MEX-527-memory-store-plugin
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/modules/common/filters/connection.args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { Field, Int, InputType } from '@nestjs/graphql';
import { IsOptional, Max } from 'class-validator';
import { PaginationArgs } from 'src/modules/dex.model';
import { Expose } from 'class-transformer';

type PagingMeta =
| { pagingType: 'forward'; after?: string; first: number }
Expand Down Expand Up @@ -83,17 +84,21 @@ export function getPagingParameters(args: ConnectionArgs): PaginationArgs {

@InputType()
export default class ConnectionArgs implements ConnectionArguments {
@Expose()
@Field({ nullable: true, description: 'Paginate before opaque cursor' })
public before?: ConnectionCursor;

@Expose()
@Field({ nullable: true, description: 'Paginate after opaque cursor' })
public after?: ConnectionCursor;

@Expose()
@IsOptional()
@Max(100)
@Field(() => Int, { nullable: true, description: 'Paginate first' })
public first?: number;

@Expose()
@IsOptional()
@Max(100)
@Field(() => Int, { nullable: true, description: 'Paginate last' })
Expand Down
3 changes: 3 additions & 0 deletions src/modules/dex.model.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Field, ArgsType, Int } from '@nestjs/graphql';
import { Expose } from 'class-transformer';

@ArgsType()
export class PaginationArgs {
@Expose()
@Field(() => Int)
offset = 0;

@Expose()
@Field(() => Int)
limit = 10;

Expand Down
4 changes: 4 additions & 0 deletions src/modules/memory-store/entities/global.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export class GlobalStateSingleton {
public tokensState: { [key: string]: EsdtToken } = {};
public initStatus: GlobalStateInitStatus =
GlobalStateInitStatus.NOT_STARTED;

public getPairsArray(): PairModel[] {
return Object.values(this.pairsState);
}
}

export const GlobalState = new GlobalStateSingleton();
5 changes: 3 additions & 2 deletions src/modules/memory-store/memory.store.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Module } from '@nestjs/common';
import { MemoryStoreFactoryService } from './services/memory.store.factory.service';
import { PairMemoryStoreService } from './services/pair.memory.store.service';

@Module({
providers: [MemoryStoreFactoryService],
exports: [MemoryStoreFactoryService],
providers: [MemoryStoreFactoryService, PairMemoryStoreService],
exports: [MemoryStoreFactoryService, PairMemoryStoreService],
})
export class MemoryStoreModule {}
20 changes: 18 additions & 2 deletions src/modules/memory-store/services/memory.store.factory.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
import { Injectable } from '@nestjs/common';
import { IMemoryStoreService } from './interfaces';
import { PairMemoryStoreService } from './pair.memory.store.service';
import { PairModel } from 'src/modules/pair/models/pair.model';
import { PairsResponse } from 'src/modules/pair/models/pairs.response';

@Injectable()
export class MemoryStoreFactoryService {
private queryMapping: Record<string, IMemoryStoreService<any, any>> = {};

constructor(private readonly pairMemoryStore: PairMemoryStoreService) {
const pairQueries = Object.keys(
this.pairMemoryStore.getTargetedQueries(),
);

for (const query of pairQueries) {
this.queryMapping[query] = this
.pairMemoryStore as IMemoryStoreService<
PairModel[],
PairsResponse
>;
}
}

isReady(): boolean {
// TODO: replace with actual checks on compatible memory store services
return false;
return this.pairMemoryStore.isReady();
}

getTargetedQueryNames(): string[] {
Expand Down
Loading