Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// TODO: use strategy pattern, like wallet
const chalk = require('chalk')
const { allPass } = require('mojiscript')
const { isCommand, getArgs } = require('../lib/command')
const actions = require('../actions')
const { tables } = require('../stores/fs')
const { doesServerHavePackage } = require('./lib/doesServerHavePackage')
const tutorial = require('../tutorial')
const name = 'coind'
const commands = ['start', 'stop', 'status', '--help']
const isCommandValid = command =>
command != null && commands.some(o => o === command)
const test = allPass([isCommand(name), doesServerHavePackage(name)])
const exec = req => {
const { username } = req.session
const [command] = getArgs(req.body.line)
if (command != null || command === '--help') {
if (!isCommandValid(command)) {
return [actions.echo(`${name}: ${command}: Invalid command`)]
}
const server = tables.servers.find({
address: { $eq: req.session.env.HOST }
})[0]
const state = server.state || (server.state = {})
//@ts-check
const { allPass } = require('mojiscript')
const path = require('path')
const { isCommand } = require('../../lib/command')
const { doesServerHavePackage } = require('../lib/doesServerHavePackage')
const { execStrategy, getStrategies } = require('../../lib/strategies')
const name = 'wallet'
const strategyPath = path.join(__dirname, '**/*.strategy.js')
const strategies = getStrategies(strategyPath)
/**
* @type { import('../../types/strategy').StrategyTest }
*/
const test = allPass([isCommand(name), doesServerHavePackage(name)])
/**
* @type { import('../../types/strategy').StrategyExec }
*/
const exec = execStrategy(strategies)
module.exports = {
sort: 10,
test: test,
exec: exec,
name
}
//@ts-check
const { allPass } = require('mojiscript')
const path = require('path')
const { doesServerHavePackage } = require('../lib/doesServerHavePackage')
const { isCommand } = require('../../lib/command')
const { execStrategy, getStrategies } = require('../../lib/strategies')
const name = 'cryptolock'
const strategyPath = path.join(__dirname, '**/*.strategy.js')
const strategies = getStrategies(strategyPath)
/**
* @type { import('../../types/strategy').StrategyTest }
*/
const test = allPass([isCommand(name), doesServerHavePackage(name)])
/**
* @type { import('../../types/strategy').StrategyExec }
*/
const exec = execStrategy(strategies)
module.exports = {
sort: 10,
test: test,
exec: exec
}
//@ts-check
const { allPass } = require('mojiscript')
const path = require('path')
const { isCommand } = require('../../lib/command')
const { doesServerHavePackage } = require('../lib/doesServerHavePackage')
const { execStrategy, getStrategies } = require('../../lib/strategies')
const name = 'coind'
const strategyPath = path.join(__dirname, '**/*.strategy.js')
const strategies = getStrategies(strategyPath)
/**
* @type { import('../../types/strategy').StrategyTest }
*/
const test = allPass([isCommand(name), doesServerHavePackage(name)])
/**
* @type { import('../../types/strategy').StrategyExec }
*/
const exec = execStrategy(strategies)
module.exports = {
sort: 10,
test: test,
exec: exec,
name
}
const calculateTotalCollected = req => {
const servers = tables.servers
.find({ owner: { $eq: req.session.username } })
.filter(allPass([hasCoind, isOn]))
const total = Number((reward * servers.length).toFixed(8))
return total
}
//@ts-check
const { allPass } = require('mojiscript')
const path = require('path')
const { isCommand } = require('../../lib/command')
const { doesServerHavePackage } = require('../lib/doesServerHavePackage')
const { execStrategy, getStrategies } = require('../../lib/strategies')
const name = 'nscan'
const strategies = getStrategies(path.join(__dirname, '**/*.strategy.js'))
/**
* @type { import('../../types/strategy').StrategyTest }
*/
const test = allPass([isCommand(name), doesServerHavePackage(name)])
/**
* @type { import('../../types/strategy').StrategyExec }
*/
const exec = execStrategy(strategies)
module.exports = {
sort: 10,
test,
exec,
name
}
const ansi = require('ansi-escapes')
const { allPass } = require('mojiscript')
const { getArgs, isCommand } = require('../../lib/command')
const { animateProgressBar } = require('../../lib/progressbar')
const actions = require('../../actions')
const { tables } = require('../../stores/fs')
const { doesServerHavePackage } = require('../lib/doesServerHavePackage')
const name = 'xssh'
const UP = ansi.cursorPrevLine
/**
* @type { import('../../types/strategy').StrategyTest }
*/
const test = allPass([isCommand(name), doesServerHavePackage(name)])
/**
* @type { import('../../types/strategy').StrategyExec }
*/
const exec = req => {
const [address] = getArgs(req.body.line)
if (address == null) {
return [actions.echo(`Usage: ${name} address`)]
}
const server =
address !== 'home'
? tables.servers.find({ address: { $eq: address } })[0]
: null
const logger = require('../logger')
const name = 'nscan'
const spawnServer = (username, type = 0) => {
const address = randomIpv6()
return tables.servers.insert({ owner: username, address, type })
}
const isUserLucky = ({ servers }) =>
servers.length < 2 || Math.random() <= config.get('luck.nscan')
const isScanRunning = ({ nscan_end_at }) =>
nscan_end_at && Date.parse(nscan_end_at) - Date.now() >= 0
const test = allPass([isCommand(name), doesServerHavePackage(name)])
const exec = req => {
const { username } = req.session
const { nscan_end_at } = req.state
const servers = tables.servers.find({ owner: { $eq: username } })
const isLucky = isUserLucky({ username, servers })
const isStarted = nscan_end_at != null
const shouldDiscoverServer =
(!isStarted && isLucky) || (isStarted && !isScanRunning(req.state))
if (shouldDiscoverServer) {
logger.info(`\`${username}\`: \`nscan\` found new server`)
delete req.state.nscan_end_at
tables.state.update(req.state)
chalk`{bgCyan.black training: } Training of {cyan.bold ${lesson}} is complete.`
),
...rewards.map(reward => {
if (reward.startsWith('pkg:')) {
const pkg = reward.substr(4)
return actions.echo(chalk`package {cyan.bold ${pkg}} is available.
type {cyan.bold pkg install ${pkg}} to install.`)
}
})
]
}
/**
* @type { import('../../types/strategy').StrategyTest }
*/
const test = allPass([isCommand(name), doesServerHavePackage(name)])
/**
* @type { import('../../types/strategy').StrategyExec }
*/
const exec = req => {
const [arg] = getArgs(req.body.line)
const myTraining = getAvailableTraining({
session: req.session,
state: req.state
})
if ((req.state.training || []).some(t => t === arg)) {
return [
actions.echo(chalk`${name}: You have already trained {cyan.bold ${arg}}`)
]
//@ts-check
const { anyPass } = require('mojiscript')
const { isCommand } = require('../../lib/command')
/**
* @type { import('../../types/strategy').StrategyTest }
*/
const test = anyPass([isCommand(''), isCommand('noop')])
/**
* @type { import('../../types/strategy').StrategyExec }
*/
const exec = () => []
module.exports = {
sort: 10,
test,
exec
}