Skip to content

Commit

Permalink
chore: add new query in validators endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
onmax committed Nov 16, 2024
1 parent fec4d4d commit d092a11
Show file tree
Hide file tree
Showing 8 changed files with 367 additions and 6 deletions.
4 changes: 2 additions & 2 deletions server/api/[version]/validators/index.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { mainQuerySchema } from '~~/server/utils/schemas'
import { fetchValidators } from '~~/server/utils/validators'

export default defineEventHandler(async (event) => {
const { payoutType, onlyActive, onlyKnown } = await getValidatedQuery(event, mainQuerySchema.parse)
const { payoutType, onlyActive, onlyKnown, withIdenticon } = await getValidatedQuery(event, mainQuerySchema.parse)

let addresses: string[] = []
let activeValidators: Validator[] = []
Expand All @@ -16,7 +16,7 @@ export default defineEventHandler(async (event) => {
addresses = activeValidators.map(v => v.address)
}

const { data: validators, error: errorValidators } = await fetchValidators({ payoutType, addresses, onlyKnown })
const { data: validators, error: errorValidators } = await fetchValidators({ payoutType, addresses, onlyKnown, withIdenticon })
if (errorValidators || !validators)
throw createError(errorValidators)

Expand Down
23 changes: 23 additions & 0 deletions server/database/migrations/0001_flashy_menace.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
PRAGMA foreign_keys=OFF;--> statement-breakpoint
CREATE TABLE `__new_validators` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`name` text DEFAULT 'Unknown validator' NOT NULL,
`address` text NOT NULL,
`description` text,
`fee` real DEFAULT -1,
`payout_type` text DEFAULT 'none',
`payout_schedule` text DEFAULT '',
`is_maintained_by_nimiq` integer DEFAULT false,
`icon` text NOT NULL,
`has_default_icon` integer DEFAULT true NOT NULL,
`accent_color` text NOT NULL,
`website` text,
`contact` text,
CONSTRAINT "enum_check" CHECK("__new_validators"."payout_type" IN ('none', 'restake', 'direct'))
);
--> statement-breakpoint
INSERT INTO `__new_validators`("id", "name", "address", "description", "fee", "payout_type", "payout_schedule", "is_maintained_by_nimiq", "icon", "has_default_icon", "accent_color", "website", "contact") SELECT "id", "name", "address", "description", "fee", "payout_type", "payout_schedule", "is_maintained_by_nimiq", "icon", "has_default_icon", "accent_color", "website", "contact" FROM `validators`;--> statement-breakpoint
DROP TABLE `validators`;--> statement-breakpoint
ALTER TABLE `__new_validators` RENAME TO `validators`;--> statement-breakpoint
PRAGMA foreign_keys=ON;--> statement-breakpoint
CREATE UNIQUE INDEX `validators_address_unique` ON `validators` (`address`);
1 change: 1 addition & 0 deletions server/database/migrations/0001_sloppy_slayback.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `validators` ADD `has_default_icon` integer NOT NULL;
324 changes: 324 additions & 0 deletions server/database/migrations/meta/0001_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,324 @@
{
"version": "6",
"dialect": "sqlite",
"id": "fae09d88-f7e3-445e-8852-da3b26ddead3",
"prevId": "95729871-3086-4fde-a2c8-7666bec7aef4",
"tables": {
"activity": {
"name": "activity",
"columns": {
"validator_id": {
"name": "validator_id",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"epoch_number": {
"name": "epoch_number",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"likelihood": {
"name": "likelihood",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"rewarded": {
"name": "rewarded",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"missed": {
"name": "missed",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"size_ratio": {
"name": "size_ratio",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"size_ratio_via_slots": {
"name": "size_ratio_via_slots",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {
"idx_election_block": {
"name": "idx_election_block",
"columns": [
"epoch_number"
],
"isUnique": false
}
},
"foreignKeys": {
"activity_validator_id_validators_id_fk": {
"name": "activity_validator_id_validators_id_fk",
"tableFrom": "activity",
"tableTo": "validators",
"columnsFrom": [
"validator_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"activity_validator_id_epoch_number_pk": {
"columns": [
"validator_id",
"epoch_number"
],
"name": "activity_validator_id_epoch_number_pk"
}
},
"uniqueConstraints": {},
"checkConstraints": {}
},
"scores": {
"name": "scores",
"columns": {
"validator_id": {
"name": "validator_id",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"from_epoch": {
"name": "from_epoch",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"to_epoch": {
"name": "to_epoch",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"total": {
"name": "total",
"type": "real",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"liveness": {
"name": "liveness",
"type": "real",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"size": {
"name": "size",
"type": "real",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"reliability": {
"name": "reliability",
"type": "real",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"reason": {
"name": "reason",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {
"idx_validator_id": {
"name": "idx_validator_id",
"columns": [
"validator_id"
],
"isUnique": false
}
},
"foreignKeys": {
"scores_validator_id_validators_id_fk": {
"name": "scores_validator_id_validators_id_fk",
"tableFrom": "scores",
"tableTo": "validators",
"columnsFrom": [
"validator_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"scores_validator_id_from_epoch_to_epoch_pk": {
"columns": [
"validator_id",
"from_epoch",
"to_epoch"
],
"name": "scores_validator_id_from_epoch_to_epoch_pk"
}
},
"uniqueConstraints": {},
"checkConstraints": {}
},
"validators": {
"name": "validators",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'Unknown validator'"
},
"address": {
"name": "address",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"fee": {
"name": "fee",
"type": "real",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": -1
},
"payout_type": {
"name": "payout_type",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": "'none'"
},
"payout_schedule": {
"name": "payout_schedule",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": "''"
},
"is_maintained_by_nimiq": {
"name": "is_maintained_by_nimiq",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": false
},
"icon": {
"name": "icon",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"has_default_icon": {
"name": "has_default_icon",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": true
},
"accent_color": {
"name": "accent_color",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"website": {
"name": "website",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"contact": {
"name": "contact",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {
"validators_address_unique": {
"name": "validators_address_unique",
"columns": [
"address"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {
"enum_check": {
"name": "enum_check",
"value": "\"validators\".\"payout_type\" IN ('none', 'restake', 'direct')"
}
}
}
},
"views": {},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"indexes": {}
}
}
7 changes: 7 additions & 0 deletions server/database/migrations/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
"when": 1731440861436,
"tag": "0000_cultured_the_fury",
"breakpoints": true
},
{
"idx": 1,
"version": "6",
"when": 1731773451802,
"tag": "0001_flashy_menace",
"breakpoints": true
}
]
}
1 change: 1 addition & 0 deletions server/database/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const validators = sqliteTable('validators', {
payoutSchedule: text('payout_schedule').default(''),
isMaintainedByNimiq: integer('is_maintained_by_nimiq', { mode: 'boolean' }).default(false),
icon: text('icon').notNull(),
hasDefaultIcon: integer('has_default_icon', { mode: 'boolean' }).notNull().default(true),
accentColor: text('accent_color').notNull(),
website: text('website'),
contact: text('contact', { mode: 'json' }),
Expand Down
Loading

0 comments on commit d092a11

Please sign in to comment.