Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
protected async _init(): Promise {
this.logger.info('Initializing L1 Data Transport Service...')
this.state.db = level(this.options.dbPath)
await this.state.db.open()
this.state.l1TransportServer = new L1TransportServer({
...this.options,
db: this.state.db,
})
// Optionally enable sync from L1.
if (this.options.syncFromL1) {
this.state.l1IngestionService = new L1IngestionService({
...this.options,
db: this.state.db,
})
}
// Optionally enable sync from L2.
export function setup () {
// open databases
dbPath = path.join(app.getPath('userData'), 'Hyperdrive')
mkdirp.sync(path.join(dbPath, 'Archives')) // make sure the folders exist
db = level(dbPath)
archiveMetaDb = subleveldown(db, 'archive-meta', { valueEncoding: 'json' })
subscribedArchivesDb = subleveldown(db, 'subscribed-archives', { valueEncoding: 'json' })
ownedArchivesDb = subleveldown(db, 'owned-archives', { valueEncoding: 'json' })
drive = hyperdrive(db)
// watch archives for FS changes
var watcher = chokidar.watch(path.join(dbPath, 'Archives'), { persistent: true, cwd: path.join(dbPath, 'Archives') })
watcher.on('ready', () => { // wait till ready, otherwise we get an 'add' for each existing file
watcher.on('add', onArchiveFSChange.bind(null, 'add', 'file'))
watcher.on('addDir', onArchiveFSChange.bind(null, 'add', 'directory'))
watcher.on('change', onArchiveFSChange.bind(null, 'change', 'file'))
// watcher.on('unlink', onArchiveFSChange.bind(null, 'unlink', 'file')) TODO: dat doesnt support deletes yet
// watcher.on('unlinkDir', onArchiveFSChange.bind(null, 'unlink', 'directory')) TODO: dat doesnt support deletes yet
})
app.once('will-quit', () => watcher.close())
constructor(time = 1000 * 60 * 10, attempts = 4) {
this.time = time; // time before timeout, default value 10 mins
this.attempts = attempts; // max amount of attempts, default value is 4
this.ipsTimeout = level('.ipchecker-ipstimeout');
this.ipsAttempts = level('.ipchecker-ipsattempts');
}
constructor(options = {}) {
this.options = options
this.blockDb = level(`${this.options.db}/block`, defaultDBOptions)
this.detailsDb = level(`${this.options.db}/details`, defaultDBOptions)
this.txPoolDb = level(`${this.options.db}/txPool`, defaultDBOptions)
// transaction pool
this.txPool = new TxPool(this.txPoolDb)
// sync manager
this.syncManager = new SyncManager(this, this.options.network)
// create instance for web3
this.web3 = new Web3(this.options.web3Provider)
// create root chain contract
this.parentContract = new this.web3.eth.Contract(
RootChain.abi,
this.options.rootChainContract
)
constructor(options = {}) {
this.options = options
this.blockDb = level(`${this.options.db}/block`, defaultDBOptions)
this.detailsDb = level(`${this.options.db}/details`, defaultDBOptions)
this.txPoolDb = level(`${this.options.db}/txPool`, defaultDBOptions)
// transaction pool
this.txPool = new TxPool(this.txPoolDb)
// sync manager
this.syncManager = new SyncManager(this, this.options.network)
// create instance for web3
this.web3 = new Web3(this.options.web3Provider)
// create root chain contract
this.parentContract = new this.web3.eth.Contract(
RootChain.abi,
this.options.rootChainContract
)
constructor(options = {}) {
this.options = options
this.blockDb = level(`${this.options.db}/block`, defaultDBOptions)
this.detailsDb = level(`${this.options.db}/details`, defaultDBOptions)
this.txPoolDb = level(`${this.options.db}/txPool`, defaultDBOptions)
// transaction pool
this.txPool = new TxPool(this.txPoolDb)
// sync manager
this.syncManager = new SyncManager(this, this.options.network)
// create instance for web3
this.web3 = new Web3(this.options.web3Provider)
// create root chain contract
this.parentContract = new this.web3.eth.Contract(
RootChain.abi,
this.options.rootChainContract
constructor() {
// TODO: offer other solutions than LevelDB
const name = config.get('LEVEL_DB')
this.db = level(name, {valueEncoding: 'json'})
}
return new Promise((resolve, reject) => {
Level(location, options, function (err, dbs) {
if (err) {
reject(err)
} else {
resolve(dbs)
}
})
})
}
constructor(repository: Repository) {
this.repository = repository
this.db = Level(npath.join(repository.paths.fibers, 'db'), { valueEncoding: 'json' })
}
import Level from 'level'
import Logger from './logger.js'
const logger = Logger.create('Service Worker')
const db = Level('cache')
const myFetch = (request) => {
logger.debug('fetching', request)
if (!db.isOpen()) {
logger.warn('db not open')
return db.on('open').then(myFetch(request))
}
return db.get(request.url)
.then((resp) => {
logger.debug(`${request.url} found in cache`)
let headers = new Headers()
headers.append('Content-Type', 'application/json')
return new Response(resp, {status: 200, statusText: 'OK', headers})
}, (err) => {
logger.debug(`${request.url} not found in cache, fetching it remotely`)
return fetch(request)