Skip to content
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
2 changes: 1 addition & 1 deletion app/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const isActivitySync = computed(() => Boolean(status.value?.missingEpochs?.lengt
const isScoreSync = computed(() => status.value?.missingScore === false)
const isSynced = computed(() => isActivitySync.value && isScoreSync.value)

const { gitBranch, nimiqNetwork } = useRuntimeConfig().public
const { gitBranch, nimiqNetwork } = useSafeRuntimeConfig().public

interface EnvItemType { branch: string, network: string, link: string }

Expand Down
2 changes: 1 addition & 1 deletion app/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const tooltips = {
}
function useStats() {
const network = useRuntimeConfig().public.nimiqNetwork as 'test-albatross' | 'main-albatross'
const network = useSafeRuntimeConfig().public.nimiqNetwork as 'test-albatross' | 'main-albatross'
const averageScore = computed(() => {
if (!validators?.value?.length)
Expand Down
2 changes: 2 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check
import antfu from '@antfu/eslint-config'
import safeRuntimeConfig from 'nuxt-safe-runtime-config/eslint'
import withNuxt from './.nuxt/eslint.config.mjs'

export default withNuxt(
Expand All @@ -14,4 +15,5 @@ export default withNuxt(
'vue/object-property-newline': ['error', { allowAllPropertiesOnSameLine: false }],
},
}),
safeRuntimeConfig.configs.recommended,
)
3 changes: 0 additions & 3 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ export default defineNuxtConfig({

consola.info(`Nimiq network: \`${nimiqNetwork}\``)
consola.info(`Git branch: \`${gitBranch}\``)

const { projectUrl, env } = nuxt.options.runtimeConfig.hub
consola.info(`Remote NuxtHub: \`${projectUrl || 'local'}@${env}\``)
},
},

Expand Down
8 changes: 5 additions & 3 deletions packages/nimiq-validator-trustscore/src/range.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,12 @@ describe('get range with mock implementation', () => {
})
})

describe('get range without mocking', () => {
const rpcUrl = env.ALBATROSS_RPC_NODE_URL
const network = env.NUXT_PUBLIC_NIMIQ_NETWORK
const rpcUrl = env.ALBATROSS_RPC_NODE_URL
const network = env.NUXT_PUBLIC_NIMIQ_NETWORK
const hasRpcEnv = Boolean(rpcUrl && network)
const describeIf = hasRpcEnv ? describe : describe.skip

describeIf('get range without mocking', () => {
it('env ok', () => {
expect(rpcUrl).toBeDefined()
expect(network).toBeDefined()
Expand Down
85 changes: 75 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ catalog:
nimiq-css: ^1.0.0-beta.61
nimiq-rpc-client-ts: 1.0.0-beta.28
nuxt: ^4.0.1
nuxt-safe-runtime-config: ^0.0.3
nuxt-safe-runtime-config: ^0.0.17
ofetch: ^1.4.1
pathe: ^2.0.3
reka-ui: ^2.4.0
Expand Down
2 changes: 1 addition & 1 deletion server/api/[version]/distribution.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default defineCachedEventHandler(async () => {
if (!latestBlockOk)
throw createError(latestBlockError)

const network = useRuntimeConfig().public.nimiqNetwork as 'test-albatross' | 'main-albatross'
const network = useSafeRuntimeConfig().public.nimiqNetwork as 'test-albatross' | 'main-albatross'
const circulating = posSupplyAt(latestBlock.timestamp, { network })

const stakedRatio = staked / circulating
Expand Down
2 changes: 1 addition & 1 deletion server/api/[version]/status.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default defineCachedEventHandler(async () => {
throw createError('No Albatross RPC Node URL')
initRpcClient({ url: rpcUrl })

const { nimiqNetwork: network } = useRuntimeConfig().public
const { nimiqNetwork: network } = useSafeRuntimeConfig().public

// We get a "window" whose size is determined by the range
const [rangeSuccess, errorRange, range] = await getRange({ network })
Expand Down
2 changes: 1 addition & 1 deletion server/api/[version]/validators/[address].get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default defineEventHandler(async (event) => {
const isValid = ValidationUtils.isValidAddress(address)
if (!isValid)
throw createError({ statusCode: 400, statusMessage: 'Invalid address format' })
const { nimiqNetwork: network } = useRuntimeConfig().public
const { nimiqNetwork: network } = useSafeRuntimeConfig().public

const [rangeSuccess, errorRange, range] = await getRange({ network })
if (!rangeSuccess || !range)
Expand Down
2 changes: 1 addition & 1 deletion server/api/[version]/validators/index.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default defineEventHandler(async (event) => {
if (!rpcUrl)
throw createError('No Albatross RPC Node URL')
initRpcClient({ url: rpcUrl })
const { nimiqNetwork: network } = useRuntimeConfig().public
const { nimiqNetwork: network } = useSafeRuntimeConfig().public

const [rangeSuccess, errorRange, range] = await getRange({ network })
if (!rangeSuccess || !range)
Expand Down
2 changes: 1 addition & 1 deletion server/plugins/setup-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default defineNitroPlugin(async () => {

// Import validators on dev branch
hubHooks.hookOnce('database:migrations:done', async () => {
const { nimiqNetwork, gitBranch } = useRuntimeConfig().public
const { nimiqNetwork, gitBranch } = useSafeRuntimeConfig().public
if (gitBranch !== 'dev')
return

Expand Down
2 changes: 1 addition & 1 deletion server/tasks/sync/epochs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default defineTask({
description: 'Sync all missing blockchain epochs to D1 database',
},
async run() {
const config = useRuntimeConfig()
const config = useSafeRuntimeConfig()

try {
const rpcUrl = getRpcUrl()
Expand Down
8 changes: 4 additions & 4 deletions server/tasks/sync/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ export default defineTask({
description: 'Sync validator snapshot and calculate scores',
},
async run() {
const config = useRuntimeConfig()
const config = useSafeRuntimeConfig()

try {
const rpcUrl = getRpcUrl()
if (!rpcUrl)
throw new Error('No Albatross RPC Node URL')
initRpcClient({ url: rpcUrl })

// Use import.meta.dev for consistent behavior with Cloudflare Workers runtime
const source = import.meta.dev ? 'filesystem' : 'github'
const { nimiqNetwork, gitBranch } = config.public

const [importSuccess, errorImport, importData] = await importValidators(source, { nimiqNetwork, gitBranch })
const [importSuccess, errorImport, importData] = import.meta.dev
? await importValidators('filesystem', { nimiqNetwork, gitBranch })
: await importValidatorsBundled(nimiqNetwork)
if (!importSuccess || !importData) {
const error = new Error(errorImport || 'Unable to import from GitHub')
await sendSyncFailureNotification('snapshot', error)
Expand Down
2 changes: 1 addition & 1 deletion server/utils/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ interface FetchMissingEpochsParams {
* Fetches the activities of the epochs that have finished and are missing in the database.
*/
export async function fetchMissingEpochs({ report, controller }: FetchMissingEpochsParams = {}): Result<number[]> {
const { nimiqNetwork: network } = useRuntimeConfig().public
const { nimiqNetwork: network } = useSafeRuntimeConfig().public

// The range that we will consider
const [rangeSuccess, errorRange, range] = await getRange({ network })
Expand Down
2 changes: 1 addition & 1 deletion server/utils/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import process from 'node:process'

export function getRpcUrl() {
return useRuntimeConfig().albatrossRpcNodeUrl || process.env.ALBATROSS_RPC_NODE_URL || ''
return useSafeRuntimeConfig().albatrossRpcNodeUrl || process.env.ALBATROSS_RPC_NODE_URL || ''
}
2 changes: 1 addition & 1 deletion server/utils/scores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async function calculateScore(range: Range, validatorId: number): Result<Calcula
* Given a range of epochs, it will compute the score for each validator entry found in the activity table.
*/
export async function upsertScoresSnapshotEpoch(): Result<CalculateScoreResult> {
const { nimiqNetwork: network } = useRuntimeConfig().public
const { nimiqNetwork: network } = useSafeRuntimeConfig().public
const [rangeSuccess, errorRange, range] = await getRange({ network })
if (!rangeSuccess || !range)
return [false, errorRange || 'No range', undefined]
Expand Down
8 changes: 4 additions & 4 deletions server/utils/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ export async function sendSlackNotification(options: SlackNotificationOptions):
return
}

const { slackWebhookUrl } = useRuntimeConfig()
const { slackWebhookUrl } = useSafeRuntimeConfig()

if (!slackWebhookUrl) {
consola.warn('NUXT_SLACK_WEBHOOK_URL not configured, skipping Slack notification')
return
}

const { nimiqNetwork, gitBranch } = useRuntimeConfig().public
const { nimiqNetwork, gitBranch } = useSafeRuntimeConfig().public

// Prepare the message
let messageText = options.message
Expand Down Expand Up @@ -124,7 +124,7 @@ export async function sendSyncFailureNotification(
error: any,
endpoint?: string,
): Promise<void> {
const { nimiqNetwork } = useRuntimeConfig().public
const { nimiqNetwork } = useSafeRuntimeConfig().public

await sendSlackNotification({
message: `🚨 Sync failure detected on ${nimiqNetwork}`,
Expand Down Expand Up @@ -157,7 +157,7 @@ export async function sendNewEpochNotification(
epochNumber: number,
totalSynced: number,
): Promise<void> {
const { nimiqNetwork } = useRuntimeConfig().public
const { nimiqNetwork } = useSafeRuntimeConfig().public

// Only send for mainnet
if (nimiqNetwork !== 'main-albatross') {
Expand Down
Loading