Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit a4ca3da

Browse files
authored
Merge pull request #2605 from w3f/will-v3.0.18
Add Types to Nominator DB Queries
2 parents 8241bb6 + 12fc985 commit a4ca3da

File tree

16 files changed

+58
-52
lines changed

16 files changed

+58
-52
lines changed

apps/1kv-backend-staging/templates/kusama-otv-backend.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ spec:
1717
source:
1818
repoURL: https://w3f.github.io/helm-charts/
1919
chart: otv-backend
20-
targetRevision: v3.0.17
20+
targetRevision: v3.0.18
2121
plugin:
2222
env:
2323
- name: HELM_VALUES

apps/1kv-backend-staging/templates/polkadot-otv-backend.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ spec:
1717
source:
1818
repoURL: https://w3f.github.io/helm-charts/
1919
chart: otv-backend
20-
targetRevision: v3.0.17
20+
targetRevision: v3.0.18
2121
plugin:
2222
env:
2323
- name: HELM_VALUES

apps/1kv-backend/templates/kusama-otv-backend.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ spec:
1717
source:
1818
repoURL: https://w3f.github.io/helm-charts/
1919
chart: otv-backend
20-
targetRevision: v3.0.17
20+
targetRevision: v3.0.18
2121
plugin:
2222
env:
2323
- name: HELM_VALUES

apps/1kv-backend/templates/polkadot-otv-backend.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ spec:
1717
source:
1818
repoURL: https://w3f.github.io/helm-charts/
1919
chart: otv-backend
20-
targetRevision: v3.0.17
20+
targetRevision: v3.0.18
2121
plugin:
2222
env:
2323
- name: HELM_VALUES

charts/otv-backend/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
description: 1K Validators Backend
22
name: otv-backend
3-
version: v3.0.17
4-
appVersion: v3.0.17
3+
version: v3.0.18
4+
appVersion: v3.0.18
55
apiVersion: v2

packages/common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@1kv/common",
3-
"version": "3.0.17",
3+
"version": "3.0.18",
44
"description": "Services for running the Thousand Validator Program.",
55
"main": "build/index.js",
66
"types": "build/index.d.ts",

packages/common/src/db/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export type NodeDetails = [
1818

1919
export * from "./queries";
2020

21+
export * from "./models";
22+
2123
export const dbLabel = { label: "DB" };
2224

2325
export class Db {

packages/common/src/db/models.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,22 @@ export const EraSchema = new Schema({
321321

322322
export const EraModel = mongoose.model("Era", EraSchema);
323323

324+
export interface Nominator {
325+
address: string;
326+
stash?: string;
327+
proxy?: string;
328+
bonded?: number;
329+
avgStake?: number;
330+
nominateAmount?: number;
331+
proxyDelay?: number;
332+
rewardDestination?: string;
333+
newBondedAmount?: number;
334+
current?: [{ name?: string; stash?: string; identity?: any }];
335+
lastNomination?: number;
336+
createdAt?: number;
337+
now?: number;
338+
}
339+
324340
export const NominatorSchema = new Schema({
325341
// The controller address
326342
address: String,

packages/common/src/db/queries/Nominator.ts

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CandidateModel, NominatorModel } from "../models";
1+
import { CandidateModel, Nominator, NominatorModel } from "../models";
22
import logger from "../../logger";
33
import { getCandidate } from "./Candidate";
44

@@ -24,26 +24,19 @@ export const removeStaleNominators = async (
2424
};
2525

2626
/** Nominator accessor functions */
27-
export const addNominator = async (
28-
nominator: any,
29-
// address: string,
30-
// stash: string,
31-
// proxy: string,
32-
// bonded: number,
33-
// now: number,
34-
// proxyDelay: number,
35-
// rewardDestination: string
36-
37-
// avgStake: number,
38-
// nominateAmount: number,
39-
// newBondedAmount: number
40-
): Promise<boolean> => {
41-
const { address, stash, proxy, bonded, now, proxyDelay, rewardDestination } =
42-
nominator;
43-
44-
logger.info(`(Db::addNominator) Adding ${address} at ${now}.`);
45-
27+
export const addNominator = async (nominator: Nominator): Promise<boolean> => {
4628
try {
29+
const {
30+
address,
31+
stash,
32+
proxy,
33+
bonded,
34+
now,
35+
proxyDelay,
36+
rewardDestination,
37+
} = nominator;
38+
39+
logger.info(`(Db::addNominator) Adding ${address} at ${now}.`);
4740
const data = await NominatorModel.findOne({ address }).lean();
4841
if (!data) {
4942
const nominator = new NominatorModel({
@@ -53,9 +46,6 @@ export const addNominator = async (
5346
bonded,
5447
proxyDelay,
5548
rewardDestination,
56-
// avgStake,
57-
// nominateAmount,
58-
// newBondedAmount,
5949
current: [],
6050
lastNomination: 0,
6151
createdAt: now,
@@ -75,19 +65,10 @@ export const addNominator = async (
7565
bonded,
7666
proxyDelay,
7767
rewardDestination,
78-
// avgStake,
79-
// nominateAmount,
80-
// newBondedAmount,
8168
},
8269
);
8370
} catch (e) {
8471
logger.info(JSON.stringify(e));
85-
logger.info(address);
86-
logger.info(stash);
87-
logger.info(proxy);
88-
logger.info(bonded);
89-
logger.info(proxyDelay);
90-
logger.info(rewardDestination);
9172
}
9273
};
9374

@@ -182,11 +163,15 @@ export const setLastNomination = async (
182163
return true;
183164
};
184165

185-
export const getCurrentTargets = async (address: string): Promise<any[]> => {
166+
export const getCurrentTargets = async (
167+
address: string,
168+
): Promise<{ name?: string; stash?: string; identity?: any }[]> => {
186169
try {
187-
const nominator = await NominatorModel.findOne({ address }).lean();
170+
const nominator = await NominatorModel.findOne({
171+
address,
172+
}).lean<Nominator>();
188173
if (nominator) {
189-
return nominator?.current;
174+
return nominator?.current || [];
190175
} else {
191176
return [];
192177
}
@@ -195,10 +180,10 @@ export const getCurrentTargets = async (address: string): Promise<any[]> => {
195180
}
196181
};
197182

198-
export const allNominators = async (): Promise<any[]> => {
199-
return NominatorModel.find({ address: /.*/ }).lean().exec();
183+
export const allNominators = async (): Promise<Nominator[]> => {
184+
return NominatorModel.find({ address: /.*/ }).lean();
200185
};
201186

202-
export const getNominator = async (stash: string): Promise<any> => {
203-
return NominatorModel.findOne({ stash: stash }).lean().exec();
187+
export const getNominator = async (stash: string): Promise<Nominator> => {
188+
return NominatorModel.findOne({ stash: stash }).lean();
204189
};

packages/common/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import "@polkadot/api-augment";
22
import { Db } from "./db";
33
import * as queries from "./db/queries";
4+
import * as Models from "./db/models";
45
import * as Config from "./config";
56
import logger from "./logger";
67
import { ChainData } from "./chaindata";
@@ -23,4 +24,5 @@ export {
2324
Util,
2425
Constraints,
2526
Score,
27+
Models,
2628
};

0 commit comments

Comments
 (0)