Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: now properly fix bootstrap in core
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Feb 18, 2018
1 parent d527b45 commit 9f39a6f
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions src/core/components/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
'use strict'

const defaultNodes = require('../runtime/config-nodejs.json').Bootstrap
// const MultiAddr = require('multiaddr')
const Multiaddr = require('multiaddr')
const promisify = require('promisify-es6')

function isValid (ma) {
if (typeof ma === 'string') {
try {
ma = new Multiaddr(ma)
return Boolean(ma)
} catch (err) {
return false
}
} else if (ma) {
return Multiaddr.isMultiaddr(ma)
} else {
return false
}
}

module.exports = function bootstrap (self) {
return {
list: promisify((callback) => {
Expand All @@ -17,17 +32,13 @@ module.exports = function bootstrap (self) {
add: promisify((multiaddr, args, callback) => {
if (typeof args === 'function') {
callback = args
args = {default: false}
args = { default: false }
}
try {
if (multiaddr) {
// TODO understand what was the purpose of this code
// it failed on tests, it passes without
// multiaddr = new MultiAddr(multiaddr)
}
} catch (err) {
return setImmediate(() => callback(err))

if (multiaddr && !isValid(multiaddr)) {
return setImmediate(() => callback(new Error('Not valid multiaddr')))
}

self._repo.config.get((err, config) => {
if (err) {
return callback(err)
Expand All @@ -53,13 +64,8 @@ module.exports = function bootstrap (self) {
callback = args
args = {all: false}
}
try {
if (multiaddr) {
// TODO understand what was the purpose of this code
// multiaddr = new MultiAddr(multiaddr)
}
} catch (err) {
return setImmediate(() => callback(err))
if (multiaddr && !isValid(multiaddr)) {
return setImmediate(() => callback(new Error('Not valid multiaddr')))
}

self._repo.config.get((err, config) => {
Expand Down

0 comments on commit 9f39a6f

Please sign in to comment.