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