get bcoin working on windows.
This commit is contained in:
parent
cef88c6e4e
commit
3be5655539
2
bin/node
2
bin/node
@ -19,7 +19,7 @@ var node = new bcoin.fullnode({
|
||||
});
|
||||
|
||||
node.on('error', function(err) {
|
||||
bcoin.debug(err.stack + '');
|
||||
bcoin.error(err);
|
||||
});
|
||||
|
||||
node.open(function(err) {
|
||||
|
||||
@ -209,7 +209,7 @@ Environment.prototype.set = function set(options) {
|
||||
|
||||
options.prefix = options.prefix
|
||||
|| process.env.BCOIN_PREFIX
|
||||
|| process.env.HOME + '/.bcoin';
|
||||
|| utils.HOME + '/.bcoin';
|
||||
|
||||
options.network = options.network
|
||||
|| process.env.BCOIN_NETWORK
|
||||
@ -286,7 +286,10 @@ Environment.prototype.ensurePrefix = function ensurePrefix() {
|
||||
try {
|
||||
fs.statSync(this.prefix);
|
||||
} 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._debug) {
|
||||
this.ensurePrefix();
|
||||
this._debug = fs.createWriteStream(this.debugFile, { flags: 'a' });
|
||||
}
|
||||
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.
|
||||
* @returns {Number} Adjusted time.
|
||||
|
||||
@ -1430,7 +1430,7 @@ Pool.prototype.searchWallet = function(wallet, callback) {
|
||||
|
||||
self.chain.reset(height, function(err) {
|
||||
if (err) {
|
||||
bcoin.debug('Failed to reset height: %s', err.message);
|
||||
bcoin.error(err);
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
@ -1452,7 +1452,7 @@ Pool.prototype.searchWallet = function(wallet, callback) {
|
||||
|
||||
self.chain.resetTime(ts, function(err) {
|
||||
if (err) {
|
||||
bcoin.debug('Failed to reset time: %s', err.message);
|
||||
bcoin.error(err);
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
|
||||
@ -37,6 +37,21 @@ if (!utils.isBrowser) {
|
||||
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.
|
||||
* @type function
|
||||
|
||||
Loading…
Reference in New Issue
Block a user