browser: fixes.
This commit is contained in:
parent
7fc6efadff
commit
a4e37cf9df
@ -31,8 +31,8 @@ function show(obj) {
|
|||||||
floating.style.display = 'block';
|
floating.style.display = 'block';
|
||||||
}
|
}
|
||||||
|
|
||||||
logger = new bcoin.logger({ level: 'debug' });
|
logger = new bcoin.logger({ level: 'debug', console: true });
|
||||||
logger.writeConsole = function(level, args) {
|
logger.writeConsole = function(level, module, args) {
|
||||||
var name = bcoin.logger.levelsByVal[level];
|
var name = bcoin.logger.levelsByVal[level];
|
||||||
var msg = util.format(args, false);
|
var msg = util.format(args, false);
|
||||||
if (++scrollback > 1000) {
|
if (++scrollback > 1000) {
|
||||||
@ -40,10 +40,21 @@ logger.writeConsole = function(level, args) {
|
|||||||
scrollback = 1;
|
scrollback = 1;
|
||||||
}
|
}
|
||||||
log.innerHTML += '<span style="color:blue;">' + util.now() + '</span> ';
|
log.innerHTML += '<span style="color:blue;">' + util.now() + '</span> ';
|
||||||
if (name === 'error')
|
if (name === 'error') {
|
||||||
log.innerHTML += '<span style="color:red;">[' + name + ']</span> ';
|
log.innerHTML += '<span style="color:red;">';
|
||||||
else
|
log.innerHTML += '[';
|
||||||
log.innerHTML += '[' + name + '] ';
|
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.innerHTML += escape(msg) + '\n';
|
||||||
log.scrollTop = log.scrollHeight;
|
log.scrollTop = log.scrollHeight;
|
||||||
};
|
};
|
||||||
@ -163,7 +174,7 @@ function setMouseup(el, obj) {
|
|||||||
|
|
||||||
function formatWallet(wallet) {
|
function formatWallet(wallet) {
|
||||||
var html = '';
|
var html = '';
|
||||||
var key = wallet.master.toJSON(true).key;
|
var json = wallet.master.toJSON(true);
|
||||||
var i, tx, el;
|
var i, tx, el;
|
||||||
|
|
||||||
html += '<b>Wallet</b><br>';
|
html += '<b>Wallet</b><br>';
|
||||||
@ -179,8 +190,8 @@ function formatWallet(wallet) {
|
|||||||
html += 'Current Address: <b>' + wallet.getAddress() + '</b><br>';
|
html += 'Current Address: <b>' + wallet.getAddress() + '</b><br>';
|
||||||
}
|
}
|
||||||
|
|
||||||
html += 'Extended Private Key: <b>' + key.xprivkey + '</b><br>';
|
html += 'Extended Private Key: <b>' + json.key.xprivkey + '</b><br>';
|
||||||
html += 'Mnemonic: <b>' + key.mnemonic.phrase + '</b><br>';
|
html += 'Mnemonic: <b>' + json.mnemonic.phrase + '</b><br>';
|
||||||
|
|
||||||
wallet.getBalance().then(function(balance) {
|
wallet.getBalance().then(function(balance) {
|
||||||
html += 'Confirmed Balance: <b>'
|
html += 'Confirmed Balance: <b>'
|
||||||
@ -215,13 +226,14 @@ node = new bcoin.fullnode({
|
|||||||
hash: true,
|
hash: true,
|
||||||
query: true,
|
query: true,
|
||||||
prune: true,
|
prune: true,
|
||||||
network: 'testnet',
|
network: 'main',
|
||||||
db: 'leveldb',
|
db: 'leveldb',
|
||||||
coinCache: 30000000,
|
coinCache: 30000000,
|
||||||
|
logConsole: true,
|
||||||
logger: logger
|
logger: logger
|
||||||
});
|
});
|
||||||
|
|
||||||
wdb = node.use(bcoin.walletdb);
|
wdb = node.use(bcoin.walletplugin);
|
||||||
|
|
||||||
node.on('error', function(err) {
|
node.on('error', function(err) {
|
||||||
;
|
;
|
||||||
@ -231,15 +243,17 @@ node.chain.on('block', addItem);
|
|||||||
node.mempool.on('tx', addItem);
|
node.mempool.on('tx', addItem);
|
||||||
|
|
||||||
node.open().then(function() {
|
node.open().then(function() {
|
||||||
node.connect().then(function() {
|
return node.connect();
|
||||||
node.startSync();
|
}).then(function() {
|
||||||
|
node.startSync();
|
||||||
wdb.primary.on('balance', function() {
|
|
||||||
formatWallet(wdb.primary);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
wdb.primary.on('balance', function() {
|
||||||
formatWallet(wdb.primary);
|
formatWallet(wdb.primary);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
formatWallet(wdb.primary);
|
||||||
|
}).catch(function(err) {
|
||||||
|
throw err;
|
||||||
});
|
});
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|||||||
@ -20,7 +20,10 @@ proxy.on('error', function(err) {
|
|||||||
console.error(err.stack + '');
|
console.error(err.stack + '');
|
||||||
});
|
});
|
||||||
|
|
||||||
server = new HTTPBase();
|
server = new HTTPBase({
|
||||||
|
port: +process.argv[2] || 8080,
|
||||||
|
sockets: false
|
||||||
|
});
|
||||||
|
|
||||||
server.get('/favicon.ico', function(req, res) {
|
server.get('/favicon.ico', function(req, res) {
|
||||||
res.send(404, '', 'txt');
|
res.send(404, '', 'txt');
|
||||||
@ -52,4 +55,4 @@ server.on('error', function(err) {
|
|||||||
|
|
||||||
proxy.attach(server.server);
|
proxy.attach(server.server);
|
||||||
|
|
||||||
server.listen(+process.argv[2] || 8080);
|
server.open();
|
||||||
|
|||||||
@ -225,7 +225,7 @@ WSProxy.prototype.attach = function attach(server) {
|
|||||||
function SocketState(server, socket) {
|
function SocketState(server, socket) {
|
||||||
this.pow = server.pow;
|
this.pow = server.pow;
|
||||||
this.target = server.target;
|
this.target = server.target;
|
||||||
this.snonce = util.nonce(true);
|
this.snonce = util.nonce();
|
||||||
this.socket = null;
|
this.socket = null;
|
||||||
this.host = IP.normalize(socket.conn.remoteAddress);
|
this.host = IP.normalize(socket.conn.remoteAddress);
|
||||||
this.remoteHost = null;
|
this.remoteHost = null;
|
||||||
|
|||||||
@ -178,7 +178,7 @@ function Environment() {
|
|||||||
// Miner
|
// Miner
|
||||||
this.require('mining', './mining');
|
this.require('mining', './mining');
|
||||||
this.require('miner', './mining/miner');
|
this.require('miner', './mining/miner');
|
||||||
this.require('minerblock', './mining/minerblock');
|
this.require('template', './mining/template');
|
||||||
|
|
||||||
// Net
|
// Net
|
||||||
this.require('net', './net');
|
this.require('net', './net');
|
||||||
@ -250,6 +250,7 @@ function Environment() {
|
|||||||
this.require('path', './wallet/path');
|
this.require('path', './wallet/path');
|
||||||
this.require('walletkey', './wallet/walletkey');
|
this.require('walletkey', './wallet/walletkey');
|
||||||
this.require('walletdb', './wallet/walletdb');
|
this.require('walletdb', './wallet/walletdb');
|
||||||
|
this.require('walletplugin', './wallet/plugin');
|
||||||
|
|
||||||
// Workers
|
// Workers
|
||||||
this.require('workers', './workers');
|
this.require('workers', './workers');
|
||||||
|
|||||||
@ -70,7 +70,7 @@ RPCBase.prototype.call = co(function* call(body, query) {
|
|||||||
|
|
||||||
assert(Array.isArray(cmd.params), 'Params must be an array.');
|
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++) {
|
for (i = 0; i < cmds.length; i++) {
|
||||||
|
|||||||
@ -176,9 +176,6 @@ Logger.prototype.open = co(function* open() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Logger.prototype._open = co(function* open() {
|
Logger.prototype._open = co(function* open() {
|
||||||
if (fs.unsupported)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!this.filename) {
|
if (!this.filename) {
|
||||||
this.closed = false;
|
this.closed = false;
|
||||||
return;
|
return;
|
||||||
@ -189,6 +186,11 @@ Logger.prototype._open = co(function* open() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fs.unsupported) {
|
||||||
|
this.closed = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.shrink)
|
if (this.shrink)
|
||||||
yield this.truncate();
|
yield this.truncate();
|
||||||
|
|
||||||
@ -224,6 +226,12 @@ Logger.prototype._close = co(function* close() {
|
|||||||
this.timer = null;
|
this.timer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fs.unsupported) {
|
||||||
|
this.closed = true;
|
||||||
|
this.stream = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.stream) {
|
if (this.stream) {
|
||||||
try {
|
try {
|
||||||
this.closing = true;
|
this.closing = true;
|
||||||
@ -324,6 +332,9 @@ Logger.prototype._reopen = co(function* reopen() {
|
|||||||
if (this.closed)
|
if (this.closed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (fs.unsupported)
|
||||||
|
return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.stream = yield openStream(this.filename);
|
this.stream = yield openStream(this.filename);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@ -1472,26 +1472,17 @@ WalletDB.prototype.decryptKeys = co(function* decryptKeys(wallet, key) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
WalletDB.prototype.resend = co(function* resend() {
|
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),
|
gte: layout.w(0x00000000),
|
||||||
lte: layout.w(0xffffffff)
|
lte: layout.w(0xffffffff)
|
||||||
});
|
});
|
||||||
|
|
||||||
for (;;) {
|
for (i = 0; i < keys.length; i++) {
|
||||||
item = yield iter.next();
|
key = keys[i];
|
||||||
|
wid = layout.ww(key);
|
||||||
if (!item)
|
yield this.resendPending(wid);
|
||||||
break;
|
|
||||||
|
|
||||||
try {
|
|
||||||
wid = layout.ww(item.key);
|
|
||||||
yield this.resendPending(wid);
|
|
||||||
} catch (e) {
|
|
||||||
yield iter.end();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -80,6 +80,7 @@
|
|||||||
"./lib/net/dns": "./lib/net/dns-browser.js",
|
"./lib/net/dns": "./lib/net/dns-browser.js",
|
||||||
"./lib/net/tcp": "./lib/net/tcp-browser.js",
|
"./lib/net/tcp": "./lib/net/tcp-browser.js",
|
||||||
"./lib/net/upnp": "./lib/net/upnp-browser.js",
|
"./lib/net/upnp": "./lib/net/upnp-browser.js",
|
||||||
|
"./lib/utils/fs": "./browser/empty.js",
|
||||||
"./lib/utils/native": "./browser/empty.js",
|
"./lib/utils/native": "./browser/empty.js",
|
||||||
"./lib/utils/nfkd": "./lib/utils/nfkd-browser.js",
|
"./lib/utils/nfkd": "./lib/utils/nfkd-browser.js",
|
||||||
"./lib/utils/nexttick": "./lib/utils/nexttick-browser.js",
|
"./lib/utils/nexttick": "./lib/utils/nexttick-browser.js",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user