wallet: events.
This commit is contained in:
parent
45867fffb6
commit
8ef70978d0
@ -968,19 +968,31 @@ HTTPServer.prototype._initIO = function _initIO() {
|
||||
});
|
||||
});
|
||||
|
||||
this.walletdb.on('tx', function(id, tx, details) {
|
||||
details = details.toJSON();
|
||||
this.walletdb.on('tx', function(id, tx, info) {
|
||||
var details = info.toJSON();
|
||||
self.server.io.to(id).emit('wallet tx', details);
|
||||
self.server.io.to('!all').emit('wallet tx', id, details);
|
||||
});
|
||||
|
||||
this.walletdb.on('confirmed', function(id, tx, details) {
|
||||
details = details.toJSON();
|
||||
this.walletdb.on('confirmed', function(id, tx, info) {
|
||||
var details = info.toJSON();
|
||||
self.server.io.to(id).emit('wallet confirmed', details);
|
||||
self.server.io.to('!all').emit('wallet confirmed', id, details);
|
||||
});
|
||||
|
||||
this.walletdb.on('balance', function(id, balance, details) {
|
||||
this.walletdb.on('unconfirmed', function(id, tx, info) {
|
||||
var details = info.toJSON();
|
||||
self.server.io.to(id).emit('wallet unconfirmed', details);
|
||||
self.server.io.to('!all').emit('wallet unconfirmed', id, details);
|
||||
});
|
||||
|
||||
this.walletdb.on('conflict', function(id, tx, info) {
|
||||
var details = info.toJSON();
|
||||
self.server.io.to(id).emit('wallet conflict', details);
|
||||
self.server.io.to('!all').emit('wallet conflict', id, details);
|
||||
});
|
||||
|
||||
this.walletdb.on('balance', function(id, balance) {
|
||||
balance = {
|
||||
confirmed: utils.btc(balance.confirmed),
|
||||
unconfirmed: utils.btc(balance.unconfirmed),
|
||||
@ -990,19 +1002,12 @@ HTTPServer.prototype._initIO = function _initIO() {
|
||||
self.server.io.to('!all').emit('wallet balance', id, balance);
|
||||
});
|
||||
|
||||
this.walletdb.on('address', function(id, receive, change, details) {
|
||||
details = details.toJSON();
|
||||
|
||||
this.walletdb.on('address', function(id, receive) {
|
||||
receive = receive.map(function(address) {
|
||||
return address.toJSON();
|
||||
});
|
||||
|
||||
change = change.map(function(address) {
|
||||
return address.toJSON();
|
||||
});
|
||||
|
||||
self.server.io.to(id).emit('wallet address', receive, change, details);
|
||||
self.server.io.to('!all').emit('wallet address', id, receive, change, details);
|
||||
self.server.io.to(id).emit('wallet address', receive);
|
||||
self.server.io.to('!all').emit('wallet address', id, receive);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -72,9 +72,8 @@ TXDB.prototype.prefix = function prefix(key) {
|
||||
*/
|
||||
|
||||
TXDB.prototype.emit = function emit(event, tx, info) {
|
||||
var details = info.toDetails();
|
||||
this.db.emit(event, info.id, tx, details);
|
||||
this.wallet.emit(event, tx, details);
|
||||
this.db.emit(event, info.id, tx, info);
|
||||
this.wallet.emit(event, tx, info);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -1058,10 +1058,9 @@ Wallet.prototype.getOutputPaths = function getOutputPaths(tx, callback) {
|
||||
|
||||
Wallet.prototype.syncOutputDepth = function syncOutputDepth(info, callback) {
|
||||
var self = this;
|
||||
var change = [];
|
||||
var receive = [];
|
||||
var accounts = {};
|
||||
var i, path, details, unlock;
|
||||
var i, path, unlock;
|
||||
|
||||
unlock = this.writeLock.lock(syncOutputDepth, [info, callback]);
|
||||
|
||||
@ -1117,9 +1116,6 @@ Wallet.prototype.syncOutputDepth = function syncOutputDepth(info, callback) {
|
||||
if (rcv)
|
||||
receive.push(rcv);
|
||||
|
||||
if (chng)
|
||||
change.push(chng);
|
||||
|
||||
next();
|
||||
});
|
||||
});
|
||||
@ -1129,15 +1125,15 @@ Wallet.prototype.syncOutputDepth = function syncOutputDepth(info, callback) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
details = info.toDetails();
|
||||
|
||||
self.db.emit('address', self.id, receive, change, details);
|
||||
self.emit('address', receive, change, details);
|
||||
if (receive.length > 0) {
|
||||
self.db.emit('address', self.id, receive);
|
||||
self.emit('address', receive);
|
||||
}
|
||||
|
||||
self.commit(function(err) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
return callback(null, receive, change);
|
||||
return callback(null, receive);
|
||||
});
|
||||
});
|
||||
};
|
||||
@ -1150,9 +1146,8 @@ Wallet.prototype.syncOutputDepth = function syncOutputDepth(info, callback) {
|
||||
* @param {Function} callback
|
||||
*/
|
||||
|
||||
Wallet.prototype.updateBalances = function updateBalances(info, callback) {
|
||||
Wallet.prototype.updateBalances = function updateBalances(callback) {
|
||||
var self = this;
|
||||
var details;
|
||||
|
||||
if (this.db.listeners('balance').length === 0
|
||||
&& this.listeners('balance').length === 0) {
|
||||
@ -1163,10 +1158,8 @@ Wallet.prototype.updateBalances = function updateBalances(info, callback) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
details = info.toDetails();
|
||||
|
||||
self.db.emit('balance', self.id, balance, details);
|
||||
self.emit('balance', balance, details);
|
||||
self.db.emit('balance', self.id, balance);
|
||||
self.emit('balance', balance);
|
||||
|
||||
return callback();
|
||||
});
|
||||
@ -1186,7 +1179,7 @@ Wallet.prototype.handleTX = function handleTX(info, callback) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
self.updateBalances(info, callback);
|
||||
self.updateBalances(callback);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -1771,6 +1771,7 @@ function PathInfo(id, tx, table) {
|
||||
|
||||
// Wallet-specific details cache.
|
||||
this._details = null;
|
||||
this._json = null;
|
||||
|
||||
if (tx)
|
||||
this.fromTX(tx, table);
|
||||
@ -1886,6 +1887,17 @@ PathInfo.prototype.toDetails = function toDetails() {
|
||||
return details;
|
||||
};
|
||||
|
||||
PathInfo.prototype.toJSON = function toJSON() {
|
||||
var json = this._json;
|
||||
|
||||
if (!json) {
|
||||
json = this.toDetails().toJSON();
|
||||
this._json = json;
|
||||
}
|
||||
|
||||
return json;
|
||||
};
|
||||
|
||||
/*
|
||||
* Helpers
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user