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

Luke/dpe 1701 add current competition stats indexing to the history server #35

Merged
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
21 changes: 20 additions & 1 deletion ts/sdk/src/serializer/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
autoserializeAsArray,
autoserializeUsing
} from 'cerializr';
import { CompetitionResult, CompetitionRoundSummaryRecord, CompetitionRoundWinnerRecord } from '../types/types';
import { CompetitionResult, CompetitionRoundSummaryRecord, CompetitionRoundWinnerRecord, LiveCompetitionInfo } from '../types/types';


const BNSerializationFn = (target: BN) =>
Expand Down Expand Up @@ -201,11 +201,27 @@ export class SerializableCompetitionResult implements CompetitionResult {
@autoserializeAsArray(SerializableCompetitionRoundWinner) winners: SerializableCompetitionRoundWinner[];
}

class SerializableTopCompetitor {
@autoserializeUsing(SERIALIZATION_UTILS.PublicKeySerializeAndDeserializeFns) authority: PublicKey;
@autoserializeUsing(SERIALIZATION_UTILS.BNSerializeAndDeserializeFns) ticketCount: BN;
}

export class SerializableLiveCompetitionInfo implements LiveCompetitionInfo {
@autoserializeAs(Number) lastFetchedTs: number;
@autoserializeAs(Number) roundNumber: number;
@autoserializeAs(Number) startTs: number;
@autoserializeAs(Number) endTs: number;
@autoserializeAs(Number) totalCompetitors: number;
@autoserializeUsing(SERIALIZATION_UTILS.BNSerializeAndDeserializeFns) totalTickets: BN;
@autoserializeAsArray(SerializableTopCompetitor) topCompetitors;
}

export const Serializer = {
Serialize: {
SerializableSummaryEvent: (cls: SerializableSummaryEvent) => Serialize(cls, SerializableSummaryEvent),
SerializableCompetitionRoundWinner: (cls: SerializableCompetitionRoundWinner) => Serialize(cls, SerializableCompetitionRoundWinner),
SerializableCompetitionResult: (cls: SerializableCompetitionResult) => Serialize(cls, SerializableCompetitionResult),
SerializableLiveCompetitionInfo: (cls: SerializableLiveCompetitionInfo) => Serialize(cls, SerializableLiveCompetitionInfo),
},
Deserialize: {
SerializableSummaryEvent: (cls: Record<string, unknown>) =>
Expand All @@ -217,6 +233,9 @@ export const Serializer = {
SerializableCompetitionResult: (cls: Record<string, unknown>) =>
// @ts-ignore
Deserialize(cls as JsonObject, SerializableCompetitionResult) as SerializableCompetitionResult,
SerializableLiveCompetitionInfo: (cls: Record<string, unknown>) =>
// @ts-ignore
Deserialize(cls as JsonObject, SerializableLiveCompetitionInfo) as SerializableLiveCompetitionInfo,
},
setDeserializeFromSnakeCase: () => {
SetDeserializeKeyTransform(SnakeCase);
Expand Down
15 changes: 14 additions & 1 deletion ts/sdk/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,17 @@ export type CompetitionResult = {
placement: number;
winnerEvent: Event<CompetitionRoundWinnerRecord>;
}[];
};
};

export type LiveCompetitionInfo = {
lastFetchedTs: number;
roundNumber: number;
startTs: number;
endTs: number;
totalCompetitors: number;
totalTickets: BN;
topCompetitors: {
authority: PublicKey;
ticketCount: BN;
}[];
};