new transactions shown on homepage!
This commit is contained in:
parent
851dc06a09
commit
cc7c876247
|
@ -91,18 +91,20 @@ TransactionSchema.statics.fromIdWithInfo = function(txid, cb) {
|
|||
TransactionSchema.statics.createFromArray = function(txs, next) {
|
||||
var that = this;
|
||||
if (!txs) return next();
|
||||
|
||||
var mongo_txs = [];
|
||||
async.forEach( txs,
|
||||
function(tx, callback) {
|
||||
that.create({ txid: tx }, function(err) {
|
||||
that.create({ txid: tx }, function(err, new_tx) {
|
||||
if (err && ! err.toString().match(/E11000/)) {
|
||||
return callback(err);
|
||||
}
|
||||
console.log(new_tx);
|
||||
mongo_txs.push(new_tx);
|
||||
return callback();
|
||||
});
|
||||
},
|
||||
function(err) {
|
||||
return next(err);
|
||||
return next(err, mongo_txs);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
@ -3,7 +3,11 @@
|
|||
var Transaction = require('../../models/Transaction');
|
||||
|
||||
// server-side socket behaviour
|
||||
module.exports = function(app, io) {
|
||||
|
||||
var io = null;
|
||||
|
||||
module.exports.init = function(app, io_ext) {
|
||||
io = io_ext;
|
||||
io.set('log level', 1); // reduce logging
|
||||
io.sockets.on('connection', function(socket) {
|
||||
Transaction.findOne(function(err, tx) {
|
||||
|
@ -14,3 +18,7 @@ module.exports = function(app, io) {
|
|||
});
|
||||
};
|
||||
|
||||
|
||||
module.exports.broadcast_tx = function(tx) {
|
||||
io.sockets.emit('tx', tx);
|
||||
};
|
||||
|
|
|
@ -13,6 +13,7 @@ function spec() {
|
|||
var Block = require('../app/models/Block');
|
||||
var Transaction = require('../app/models/Transaction');
|
||||
var TransactionItem = require('../app/models/TransactionItem');
|
||||
var sockets = require('../app/views/sockets/main.js');
|
||||
|
||||
function Sync(config) {
|
||||
this.tx_count =0;
|
||||
|
@ -61,11 +62,13 @@ function spec() {
|
|||
|
||||
Sync.prototype.storeTxs = function(txids, cb) {
|
||||
var that=this;
|
||||
Transaction.createFromArray(txids, function(err) {
|
||||
Transaction.createFromArray(txids, function(err, inserted_txs) {
|
||||
if (err) return cb(err);
|
||||
|
||||
async.each(txids, function(txid, next) {
|
||||
async.each(inserted_txs, function(new_tx, next) {
|
||||
var txid = new_tx.txid;
|
||||
|
||||
sockets.broadcast_tx(new_tx);
|
||||
// This will trigger an RPC call
|
||||
Transaction.explodeTransactionItems( txid, function(err) {
|
||||
that.tx_count++;
|
||||
|
@ -202,6 +205,7 @@ function spec() {
|
|||
if (!(opts && opts.skip_db_connection)) {
|
||||
mongoose.connect(config.db);
|
||||
}
|
||||
this.opts = opts;
|
||||
this.db = mongoose.connection;
|
||||
this.rpc = new RpcClient(config.bitcoind);
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ angular.module('mystery.system').controller('IndexController', ['$scope', 'Globa
|
|||
socket.on('tx', function(data) {
|
||||
var tx = data;
|
||||
console.log('Transaction received! ' + tx.txid);
|
||||
$scope.txs.push(tx.txid);
|
||||
$scope.txs.unshift(tx.txid);
|
||||
});
|
||||
|
||||
$scope.txs = [];
|
||||
|
|
|
@ -59,7 +59,7 @@ require('./config/routes')(app);
|
|||
// socket.io
|
||||
var server = require('http').createServer(app);
|
||||
var io = require('socket.io').listen(server);
|
||||
require('./app/views/sockets/main.js')(app,io);
|
||||
require('./app/views/sockets/main.js').init(app,io);
|
||||
|
||||
//Start the app by listening on <port>
|
||||
var port = process.env.PORT || config.port;
|
||||
|
|
Loading…
Reference in New Issue