browser: fixes.

This commit is contained in:
Christopher Jeffrey 2017-03-14 08:05:48 -07:00
parent 7fc6efadff
commit a4e37cf9df
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
8 changed files with 61 additions and 40 deletions

View File

@ -31,8 +31,8 @@ function show(obj) {
floating.style.display = 'block';
}
logger = new bcoin.logger({ level: 'debug' });
logger.writeConsole = function(level, args) {
logger = new bcoin.logger({ level: 'debug', console: true });
logger.writeConsole = function(level, module, args) {
var name = bcoin.logger.levelsByVal[level];
var msg = util.format(args, false);
if (++scrollback > 1000) {
@ -40,10 +40,21 @@ logger.writeConsole = function(level, args) {
scrollback = 1;
}
log.innerHTML += '<span style="color:blue;">' + util.now() + '</span> ';
if (name === 'error')
log.innerHTML += '<span style="color:red;">[' + name + ']</span> ';
else
log.innerHTML += '[' + name + '] ';
if (name === 'error') {
log.innerHTML += '<span style="color:red;">';
log.innerHTML += '[';
log.innerHTML += name
log.innerHTML += '] ';
if (module)
log.innerHTML += '(' + module + ') ';
log.innerHTML += '</span>';
} else {
log.innerHTML += '[';
log.innerHTML += name
log.innerHTML += '] ';
if (module)
log.innerHTML += '(' + module + ') ';
}
log.innerHTML += escape(msg) + '\n';
log.scrollTop = log.scrollHeight;
};
@ -163,7 +174,7 @@ function setMouseup(el, obj) {
function formatWallet(wallet) {
var html = '';
var key = wallet.master.toJSON(true).key;
var json = wallet.master.toJSON(true);
var i, tx, el;
html += '<b>Wallet</b><br>';
@ -179,8 +190,8 @@ function formatWallet(wallet) {
html += 'Current Address: <b>' + wallet.getAddress() + '</b><br>';
}
html += 'Extended Private Key: <b>' + key.xprivkey + '</b><br>';
html += 'Mnemonic: <b>' + key.mnemonic.phrase + '</b><br>';
html += 'Extended Private Key: <b>' + json.key.xprivkey + '</b><br>';
html += 'Mnemonic: <b>' + json.mnemonic.phrase + '</b><br>';
wallet.getBalance().then(function(balance) {
html += 'Confirmed Balance: <b>'
@ -215,13 +226,14 @@ node = new bcoin.fullnode({
hash: true,
query: true,
prune: true,
network: 'testnet',
network: 'main',
db: 'leveldb',
coinCache: 30000000,
logConsole: true,
logger: logger
});
wdb = node.use(bcoin.walletdb);
wdb = node.use(bcoin.walletplugin);
node.on('error', function(err) {
;
@ -231,15 +243,17 @@ node.chain.on('block', addItem);
node.mempool.on('tx', addItem);
node.open().then(function() {
node.connect().then(function() {
node.startSync();
wdb.primary.on('balance', function() {
formatWallet(wdb.primary);
});
return node.connect();
}).then(function() {
node.startSync();
wdb.primary.on('balance', function() {
formatWallet(wdb.primary);
});
formatWallet(wdb.primary);
}).catch(function(err) {
throw err;
});
})();

View File

@ -20,7 +20,10 @@ proxy.on('error', function(err) {
console.error(err.stack + '');
});
server = new HTTPBase();
server = new HTTPBase({
port: +process.argv[2] || 8080,
sockets: false
});
server.get('/favicon.ico', function(req, res) {
res.send(404, '', 'txt');
@ -52,4 +55,4 @@ server.on('error', function(err) {
proxy.attach(server.server);
server.listen(+process.argv[2] || 8080);
server.open();

View File

@ -225,7 +225,7 @@ WSProxy.prototype.attach = function attach(server) {
function SocketState(server, socket) {
this.pow = server.pow;
this.target = server.target;
this.snonce = util.nonce(true);
this.snonce = util.nonce();
this.socket = null;
this.host = IP.normalize(socket.conn.remoteAddress);
this.remoteHost = null;

View File

@ -178,7 +178,7 @@ function Environment() {
// Miner
this.require('mining', './mining');
this.require('miner', './mining/miner');
this.require('minerblock', './mining/minerblock');
this.require('template', './mining/template');
// Net
this.require('net', './net');
@ -250,6 +250,7 @@ function Environment() {
this.require('path', './wallet/path');
this.require('walletkey', './wallet/walletkey');
this.require('walletdb', './wallet/walletdb');
this.require('walletplugin', './wallet/plugin');
// Workers
this.require('workers', './workers');

View File

@ -70,7 +70,7 @@ RPCBase.prototype.call = co(function* call(body, query) {
assert(Array.isArray(cmd.params), 'Params must be an array.');
enforce(!cmd.id || typeof cmd.id !== 'object', 'Invalid ID.');
assert(!cmd.id || typeof cmd.id !== 'object', 'Invalid ID.');
}
for (i = 0; i < cmds.length; i++) {

View File

@ -176,9 +176,6 @@ Logger.prototype.open = co(function* open() {
*/
Logger.prototype._open = co(function* open() {
if (fs.unsupported)
return;
if (!this.filename) {
this.closed = false;
return;
@ -189,6 +186,11 @@ Logger.prototype._open = co(function* open() {
return;
}
if (fs.unsupported) {
this.closed = false;
return;
}
if (this.shrink)
yield this.truncate();
@ -224,6 +226,12 @@ Logger.prototype._close = co(function* close() {
this.timer = null;
}
if (fs.unsupported) {
this.closed = true;
this.stream = null;
return;
}
if (this.stream) {
try {
this.closing = true;
@ -324,6 +332,9 @@ Logger.prototype._reopen = co(function* reopen() {
if (this.closed)
return;
if (fs.unsupported)
return;
try {
this.stream = yield openStream(this.filename);
} catch (e) {

View File

@ -1472,26 +1472,17 @@ WalletDB.prototype.decryptKeys = co(function* decryptKeys(wallet, key) {
*/
WalletDB.prototype.resend = co(function* resend() {
var iter, item, wid;
var i, keys, key, wid;
iter = this.db.iterator({
keys = yield this.db.keys({
gte: layout.w(0x00000000),
lte: layout.w(0xffffffff)
});
for (;;) {
item = yield iter.next();
if (!item)
break;
try {
wid = layout.ww(item.key);
yield this.resendPending(wid);
} catch (e) {
yield iter.end();
throw e;
}
for (i = 0; i < keys.length; i++) {
key = keys[i];
wid = layout.ww(key);
yield this.resendPending(wid);
}
});

View File

@ -80,6 +80,7 @@
"./lib/net/dns": "./lib/net/dns-browser.js",
"./lib/net/tcp": "./lib/net/tcp-browser.js",
"./lib/net/upnp": "./lib/net/upnp-browser.js",
"./lib/utils/fs": "./browser/empty.js",
"./lib/utils/native": "./browser/empty.js",
"./lib/utils/nfkd": "./lib/utils/nfkd-browser.js",
"./lib/utils/nexttick": "./lib/utils/nexttick-browser.js",