Skip to content

Commit

Permalink
screen wallet addresses (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangruber authored Nov 7, 2023
1 parent 9984e8f commit 7c64fb4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
19 changes: 13 additions & 6 deletions commands/station.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import fs from 'node:fs/promises'
import { metrics } from '../lib/metrics.js'
import { paths } from '../lib/paths.js'
import pRetry from 'p-retry'
import { fetch } from 'undici'

const { FIL_WALLET_ADDRESS } = process.env

Expand All @@ -15,21 +16,27 @@ const moduleNames = [
'bacalhau'
]

const panic = msg => {
console.error(msg)
process.exit(1)
}

export const station = async ({ json, experimental }) => {
if (!FIL_WALLET_ADDRESS) {
console.error('FIL_WALLET_ADDRESS required')
process.exit(1)
}
if (!FIL_WALLET_ADDRESS) panic('FIL_WALLET_ADDRESS required')
if (FIL_WALLET_ADDRESS.startsWith('f1')) {
console.error('Warning: f1... addresses are deprecated and will not receive any rewards.')
console.error('Please use an address starting with f410 or 0x')
} else if (
!FIL_WALLET_ADDRESS.startsWith('f410') &&
!FIL_WALLET_ADDRESS.startsWith('0x')
) {
console.error('FIL_WALLET_ADDRESS must start with f410 or 0x')
process.exit(1)
panic('FIL_WALLET_ADDRESS must start with f410 or 0x')
}
const fetchRes = await fetch(
`https://station-wallet-screening.fly.dev/${FIL_WALLET_ADDRESS}`
)
if (fetchRes.status === 403) panic('Invalid FIL_WALLET_ADDRESS address')
if (!fetchRes.ok) panic('Failed to check FIL_WALLET_ADDRESS address')

startPingLoop().unref()
for (const moduleName of moduleNames) {
Expand Down
7 changes: 7 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ describe('CLI', () => {
it('fails without address', async () => {
await assert.rejects(execa(station))
})
it('fails with sanctioned address', async () => {
await assert.rejects(execa(station, {
env: {
FIL_WALLET_ADDRESS: '0x1da5821544e25c636c1417ba96ade4cf6d2f9b5a'
}
}))
})
it('works with address', async () => {
const ps = execa(station, { env: { FIL_WALLET_ADDRESS } })
await once(ps.stdout, 'data')
Expand Down

0 comments on commit 7c64fb4

Please sign in to comment.