Skip to content

Commit

Permalink
add matrix handle to candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
wpank committed Oct 22, 2022
1 parent 4d86d2b commit 35102e8
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 7 deletions.
5 changes: 4 additions & 1 deletion helmfile.d/config/kusama/otv-backend-prod.yaml.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ config: |
"test": false,
"retroactive": false,
"historicalNominations": false,
"apiEndpoints": []
"apiEndpoints": [
"wss://kusama-rpc.polkadot.io",
"wss://kusama.api.onfinality.io/public-ws"
]
},
"constraints": {
"skipConnectionTime": false,
Expand Down
5 changes: 4 additions & 1 deletion helmfile.d/config/polkadot/otv-backend-prod.yaml.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ config: |
"test": false,
"retroactive": false,
"historicalNominations": false,
"apiEndpoints": []
"apiEndpoints": [
"wss://rpc.polkadot.io",
"wss://polkadot.api.onfinality.io/public-ws"
]
},
"constraints": {
"skipConnectionTime": false,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
],
"scripts": {
"create-config:all": "yarn workspaces foreach run create-config",
"create-kusama-config:all": "yarn workspaces foreach run create-kusama-config",
"docker:start": "yarn build:clean && docker-compose up -d --build",
"lint": "yarn workspaces foreach run lint",
"lint:fix": "yarn workspaces foreach run lint:fix",
"clean": "yarn workspaces foreach run clean",
"clean": "rm -rf redis/ && yarn workspaces foreach run clean",
"build": "yarn workspaces foreach -t run build",
"build:clean": "yarn workspaces foreach run clean:build",
"start:dev:gateway": "yarn workspace @1kv/gateway run start:dev",
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/db/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export const CandidateSchema = new Schema({
// The referenda indexes voted on
democracyVotes: [Number],
infrastructureLocation: LocationSchema,
matrix: [String],
});

export const CandidateModel = mongoose.model("Candidate", CandidateSchema);
Expand Down
7 changes: 6 additions & 1 deletion packages/common/src/db/queries/Candidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ export const addCandidate = async (
kusamaStash: string,
skipSelfStake: boolean,
bio: string,
matrix: any,
bot?: any
): Promise<boolean> => {
const network = (await getChainMetadata()).name;
const keyring = new Keyring();
const ss58Prefix = network == "Kusama" ? 2 : 0;
stash = keyring.encodeAddress(stash, ss58Prefix);
logger.info(`(Db::addCandidate) name: ${name} stash: ${stash}`);
logger.info(
`(Db::addCandidate) name: ${name} stash: ${stash} matrix: ${matrix}`
);

// Check to see if the candidate has already been added as a node.
const data = await CandidateModel.findOne({ name });
Expand All @@ -35,6 +38,7 @@ export const addCandidate = async (
kusamaStash,
skipSelfStake,
bio,
matrix,
});

if (!!bot) {
Expand All @@ -55,6 +59,7 @@ export const addCandidate = async (
kusamaStash,
skipSelfStake,
bio,
matrix,
}
);
};
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,18 @@ const start = async (cmd: { config: string }) => {
if (candidate === null) {
continue;
} else {
const { name, stash } = candidate;
const { name, stash, riotHandle } = candidate;
const bio = candidate.bio || "";
// Polkadot only options.
const kusamaStash = candidate.kusamaStash || "";
const skipSelfStake = candidate.skipSelfStake || false;

await queries.addCandidate(
name,
stash,
kusamaStash,
skipSelfStake,
bio
bio,
riotHandle
);
}
}
Expand Down
35 changes: 35 additions & 0 deletions packages/gateway/src/services/Candidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,40 @@ export const getCandidate = async (stash: any): Promise<any> => {

try {
candidate = await queries.getCandidate(stash);
if (candidate && candidate.stash) {
const score = await queries.getValidatorScore(candidate.stash);
return {
discoveredAt: candidate.discoveredAt,
nominatedAt: candidate.nominatedAt,
offlineSince: candidate.offlineSince,
offlineAccumulated: candidate.offlineAccumulated,
rank: candidate.rank,
faults: candidate.faults,
invalidityReasons: candidate.invalidityReasons,
unclaimedEras: candidate.unclaimedEras,
inclusion: candidate.inclusion,
name: candidate.name,
queuedKeys: candidate.queuedKeys,
nextKeys: candidate.nextKeys,
stash: candidate.stash,
rewardDestination: candidate.rewardDestination,
controller: candidate.controller,
kusamaStash: candidate.kusamaStash,
commission: candidate.commission,
identity: candidate.identity,
active: candidate.active,
valid: candidate.valid,
validity: candidate.invalidity,
score: score,
total: score && score.total ? score.total : 0,
location: candidate.location,
councilStake: candidate.councilStake,
councilVotes: candidate.councilVotes,
democracyVoteCount: candidate.democracyVoteCount,
democracyVotes: candidate.democracyVotes,
matrix: candidate.matrix,
};
}
} catch (error) {
logger.error("findCandidate", { error });
}
Expand Down Expand Up @@ -43,6 +77,7 @@ export const getCandidates = async (): Promise<any> => {
councilVotes: candidate.councilVotes,
democracyVoteCount: candidate.democracyVoteCount,
democracyVotes: candidate.democracyVotes,
matrix: candidate.matrix,
};
})
);
Expand Down

0 comments on commit 35102e8

Please sign in to comment.