get bcoin working on windows.

This commit is contained in:
Christopher Jeffrey 2016-05-19 16:09:21 -07:00
parent cef88c6e4e
commit 3be5655539
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
4 changed files with 76 additions and 10 deletions

View File

@ -19,7 +19,7 @@ var node = new bcoin.fullnode({
}); });
node.on('error', function(err) { node.on('error', function(err) {
bcoin.debug(err.stack + ''); bcoin.error(err);
}); });
node.open(function(err) { node.open(function(err) {

View File

@ -209,7 +209,7 @@ Environment.prototype.set = function set(options) {
options.prefix = options.prefix options.prefix = options.prefix
|| process.env.BCOIN_PREFIX || process.env.BCOIN_PREFIX
|| process.env.HOME + '/.bcoin'; || utils.HOME + '/.bcoin';
options.network = options.network options.network = options.network
|| process.env.BCOIN_NETWORK || process.env.BCOIN_NETWORK
@ -286,7 +286,10 @@ Environment.prototype.ensurePrefix = function ensurePrefix() {
try { try {
fs.statSync(this.prefix); fs.statSync(this.prefix);
} catch (e) { } catch (e) {
fs.mkdirSync(this.prefix, 488 /* 0750 */); if (e.code === 'ENOENT')
fs.mkdirSync(this.prefix, 488 /* 0750 */);
else
throw e;
} }
}; };
@ -318,15 +321,63 @@ Environment.prototype.debug = function debug() {
} }
if (this.debugFile) { if (this.debugFile) {
if (!this._debug) {
this.ensurePrefix();
this._debug = fs.createWriteStream(this.debugFile, { flags: 'a' });
}
msg = utils.format(args, false); msg = utils.format(args, false);
this._debug.write(process.pid + ': ' + msg + '\n'); this.write(msg);
} }
}; };
/**
* Output an error.
* @param {Error} err
*/
Environment.prototype.error = function error(err) {
var msg;
if (!err)
return;
if (typeof err === 'string')
err = new Error(err);
if (this.isBrowser) {
if (this.debugLogs)
console.error(err);
return;
}
if (this.debugLogs) {
msg = (err.message + '').replace(/^ *Error: */, '');
if (process.stdout && process.stdout.isTTY)
msg = '\x1b[1;31m[Error]\x1b[m ' + msg;
else
msg = '[Error] ' + msg;
process.stderr.write(msg + '\n');
}
if (this.debugFile)
this.write(err.stack + '');
};
/**
* Write a message to the debug log.
* @param {String} msg
*/
Environment.prototype.write = function write(msg) {
if (this.isBrowser)
return;
if (!this._debug) {
this.ensurePrefix();
this._debug = fs.createWriteStream(this.debugFile, { flags: 'a' });
}
this._debug.write(process.pid + ': ' + msg + '\n');
};
/** /**
* Get the adjusted time. * Get the adjusted time.
* @returns {Number} Adjusted time. * @returns {Number} Adjusted time.

View File

@ -1430,7 +1430,7 @@ Pool.prototype.searchWallet = function(wallet, callback) {
self.chain.reset(height, function(err) { self.chain.reset(height, function(err) {
if (err) { if (err) {
bcoin.debug('Failed to reset height: %s', err.message); bcoin.error(err);
return callback(err); return callback(err);
} }
@ -1452,7 +1452,7 @@ Pool.prototype.searchWallet = function(wallet, callback) {
self.chain.resetTime(ts, function(err) { self.chain.resetTime(ts, function(err) {
if (err) { if (err) {
bcoin.debug('Failed to reset time: %s', err.message); bcoin.error(err);
return callback(err); return callback(err);
} }

View File

@ -37,6 +37,21 @@ if (!utils.isBrowser) {
aes = require('./aes'); aes = require('./aes');
} }
/**
* The home directory.
* @const {String}
*/
try {
utils.HOME = require('o' + 's').homedir();
} catch (e) {
utils.HOME = process.env.HOME
|| process.env.USERPROFILE
|| process.env.HOMEPATH;
}
assert(typeof utils.HOME === 'string');
/** /**
* Global NOP function. * Global NOP function.
* @type function * @type function