txdb: refactor.

This commit is contained in:
Christopher Jeffrey 2016-10-18 17:58:54 -07:00
parent f075767cdb
commit 3412916c89
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
5 changed files with 504 additions and 509 deletions

View File

@ -1260,26 +1260,31 @@ HTTPServer.prototype._initIO = function _initIO() {
});
this.walletdb.on('tx', function(id, tx, details) {
self.server.io.to(id).emit('wallet tx', details);
self.server.io.to('!all').emit('wallet tx', id, details);
var json = details.toJSON();
self.server.io.to(id).emit('wallet tx', json);
self.server.io.to('!all').emit('wallet tx', id, json);
});
this.walletdb.on('confirmed', function(id, tx, details) {
self.server.io.to(id).emit('wallet confirmed', details);
self.server.io.to('!all').emit('wallet confirmed', id, details);
var json = details.toJSON();
self.server.io.to(id).emit('wallet confirmed', json);
self.server.io.to('!all').emit('wallet confirmed', id, json);
});
this.walletdb.on('unconfirmed', function(id, tx, details) {
self.server.io.to(id).emit('wallet unconfirmed', details);
self.server.io.to('!all').emit('wallet unconfirmed', id, details);
var json = details.toJSON();
self.server.io.to(id).emit('wallet unconfirmed', json);
self.server.io.to('!all').emit('wallet unconfirmed', id, json);
});
this.walletdb.on('conflict', function(id, tx, details) {
self.server.io.to(id).emit('wallet conflict', details);
self.server.io.to('!all').emit('wallet conflict', id, details);
var json = details.toJSON();
self.server.io.to(id).emit('wallet conflict', json);
self.server.io.to('!all').emit('wallet conflict', id, json);
});
this.walletdb.on('balance', function(id, balance) {
var json = balance.toJSON();
self.server.io.to(id).emit('wallet balance', json);
self.server.io.to('!all').emit('wallet balance', id, json);
});

File diff suppressed because it is too large Load Diff

View File

@ -26,7 +26,6 @@ var HD = require('../hd/hd');
var Account = require('./account');
var MasterKey = require('./masterkey');
var LRU = require('../utils/lru');
var PathInfo = require('./pathinfo');
/**
* BIP44 Wallet

View File

@ -1234,9 +1234,13 @@ WalletDB.prototype.getWalletsByHashes = co(function* getWalletsByHashes(tx) {
*/
WalletDB.prototype.getWalletsByInsert = co(function* getWalletsByInsert(tx) {
var result = [];
var hashes = tx.getOutputHashes('hex');
var i, j, input, hash, wids;
var i, j, result, hashes, input, hash, wids;
if (this.options.resolution)
return yield this.getWalletsByHashes(tx);
result = [];
hashes = tx.getOutputHashes('hex');
for (i = 0; i < tx.inputs.length; i++) {
input = tx.inputs[i];

View File

@ -19,6 +19,7 @@ describe('Chain', function() {
node = new bcoin.fullnode({ db: 'memory' });
chain = node.chain;
walletdb = node.walletdb;
walletdb.options.resolution = false;
miner = node.miner;
node.on('error', function() {});