socket api for address transactions
This commit is contained in:
parent
5fe57077d7
commit
6c7ecef5d4
@ -10,9 +10,6 @@ module.exports.init = function(app, io_ext) {
|
|||||||
ios.sockets.on('connection', function(socket) {
|
ios.sockets.on('connection', function(socket) {
|
||||||
socket.on('subscribe', function(topic) {
|
socket.on('subscribe', function(topic) {
|
||||||
socket.join(topic);
|
socket.join(topic);
|
||||||
if (topic !== 'inv') {
|
|
||||||
module.exports.broadcast_address_tx(topic, 'hello world');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -4,17 +4,18 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var mongoose = require('mongoose'),
|
var mongoose = require('mongoose'),
|
||||||
Schema = mongoose.Schema,
|
Schema = mongoose.Schema,
|
||||||
async = require('async'),
|
async = require('async'),
|
||||||
RpcClient = require('bitcore/RpcClient').class(),
|
RpcClient = require('bitcore/RpcClient').class(),
|
||||||
Transaction = require('bitcore/Transaction').class(),
|
Transaction = require('bitcore/Transaction').class(),
|
||||||
Address = require('bitcore/Address').class(),
|
Address = require('bitcore/Address').class(),
|
||||||
BitcoreBlock= require('bitcore/Block').class(),
|
BitcoreBlock = require('bitcore/Block').class(),
|
||||||
networks = require('bitcore/networks'),
|
networks = require('bitcore/networks'),
|
||||||
util = require('bitcore/util/util'),
|
util = require('bitcore/util/util'),
|
||||||
bignum = require('bignum'),
|
bignum = require('bignum'),
|
||||||
config = require('../../config/config'),
|
config = require('../../config/config'),
|
||||||
|
sockets = require('../controllers/socket.js'),
|
||||||
TransactionItem = require('./TransactionItem');
|
TransactionItem = require('./TransactionItem');
|
||||||
|
|
||||||
var CONCURRENCY = 5;
|
var CONCURRENCY = 5;
|
||||||
@ -94,8 +95,14 @@ TransactionSchema.statics.createFromArray = function(txs, time, next) {
|
|||||||
|
|
||||||
async.forEachLimit(txs, CONCURRENCY, function(txid, cb) {
|
async.forEachLimit(txs, CONCURRENCY, function(txid, cb) {
|
||||||
|
|
||||||
that.explodeTransactionItems( txid, time, function(err) {
|
that.explodeTransactionItems( txid, time, function(err, addrs) {
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
|
if (addrs) {
|
||||||
|
async.each(addrs, function(addr){
|
||||||
|
sockets.broadcast_address_tx(addr, {'txid': txid});
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
that.create({txid: txid, time: time}, function(err, new_tx) {
|
that.create({txid: txid, time: time}, function(err, new_tx) {
|
||||||
if (err && ! err.toString().match(/E11000/)) return cb(err);
|
if (err && ! err.toString().match(/E11000/)) return cb(err);
|
||||||
@ -112,7 +119,7 @@ TransactionSchema.statics.createFromArray = function(txs, time, next) {
|
|||||||
|
|
||||||
|
|
||||||
TransactionSchema.statics.explodeTransactionItems = function(txid, time, cb) {
|
TransactionSchema.statics.explodeTransactionItems = function(txid, time, cb) {
|
||||||
|
var addrs = [];
|
||||||
this.queryInfo(txid, function(err, info) {
|
this.queryInfo(txid, function(err, info) {
|
||||||
if (err || !info) return cb(err);
|
if (err || !info) return cb(err);
|
||||||
|
|
||||||
@ -124,7 +131,6 @@ TransactionSchema.statics.explodeTransactionItems = function(txid, time, cb) {
|
|||||||
async.forEachLimit(info.vin, CONCURRENCY, function(i, next_in) {
|
async.forEachLimit(info.vin, CONCURRENCY, function(i, next_in) {
|
||||||
if (i.addr && i.value) {
|
if (i.addr && i.value) {
|
||||||
|
|
||||||
//console.log("Creating IN %s %d", i.addr, i.valueSat);
|
|
||||||
TransactionItem.create({
|
TransactionItem.create({
|
||||||
txid : txid,
|
txid : txid,
|
||||||
value_sat : -1 * i.valueSat,
|
value_sat : -1 * i.valueSat,
|
||||||
@ -132,6 +138,9 @@ TransactionSchema.statics.explodeTransactionItems = function(txid, time, cb) {
|
|||||||
index : i.n,
|
index : i.n,
|
||||||
ts : time,
|
ts : time,
|
||||||
}, next_in);
|
}, next_in);
|
||||||
|
if (addrs.indexOf(i.addr) === -1) {
|
||||||
|
addrs.push(i.addr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ( !i.coinbase ) {
|
if ( !i.coinbase ) {
|
||||||
@ -148,7 +157,6 @@ TransactionSchema.statics.explodeTransactionItems = function(txid, time, cb) {
|
|||||||
* TODO Support multisigs
|
* TODO Support multisigs
|
||||||
*/
|
*/
|
||||||
if (o.value && o.scriptPubKey && o.scriptPubKey.addresses && o.scriptPubKey.addresses[0]) {
|
if (o.value && o.scriptPubKey && o.scriptPubKey.addresses && o.scriptPubKey.addresses[0]) {
|
||||||
//console.log("Creating OUT %s %d", o.scriptPubKey.addresses[0], o.valueSat);
|
|
||||||
TransactionItem.create({
|
TransactionItem.create({
|
||||||
txid : txid,
|
txid : txid,
|
||||||
value_sat : o.valueSat,
|
value_sat : o.valueSat,
|
||||||
@ -164,7 +172,7 @@ TransactionSchema.statics.explodeTransactionItems = function(txid, time, cb) {
|
|||||||
},
|
},
|
||||||
function (err) {
|
function (err) {
|
||||||
if (err && ! err.toString().match(/E11000/)) return cb(err);
|
if (err && ! err.toString().match(/E11000/)) return cb(err);
|
||||||
return cb();
|
return cb(null, addrs);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -20,9 +20,6 @@ angular.module('insight.address').controller('AddressController',
|
|||||||
socket.on('connect', function() {
|
socket.on('connect', function() {
|
||||||
socket.emit('subscribe', $routeParams.addrStr);
|
socket.emit('subscribe', $routeParams.addrStr);
|
||||||
});
|
});
|
||||||
socket.on('tx', function(data) {
|
|
||||||
console.log('Incoming message:', data);
|
|
||||||
});
|
|
||||||
|
|
||||||
$scope.params = $routeParams;
|
$scope.params = $routeParams;
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
@ -1,13 +1,28 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('insight.transactions').controller('transactionsController', ['$scope', '$routeParams', '$location', 'Global', 'Transaction', 'TransactionsByBlock', 'TransactionsByAddress', function ($scope, $routeParams, $location, Global, Transaction, TransactionsByBlock, TransactionsByAddress) {
|
angular.module('insight.transactions').controller('transactionsController',
|
||||||
|
['$scope',
|
||||||
|
'$routeParams',
|
||||||
|
'$location',
|
||||||
|
'Global',
|
||||||
|
'Transaction',
|
||||||
|
'TransactionsByBlock',
|
||||||
|
'TransactionsByAddress',
|
||||||
|
'socket',
|
||||||
|
function ($scope, $routeParams, $location, Global, Transaction, TransactionsByBlock, TransactionsByAddress, socket) {
|
||||||
$scope.global = Global;
|
$scope.global = Global;
|
||||||
|
|
||||||
$scope.findOne = function() {
|
|
||||||
|
$scope.findThis = function() {
|
||||||
|
$scope.findTx($routeParams.txId);
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.findTx = function(txid) {
|
||||||
Transaction.get({
|
Transaction.get({
|
||||||
txId: $routeParams.txId
|
txId: txid
|
||||||
}, function(tx) {
|
}, function(tx) {
|
||||||
$scope.tx = tx;
|
$scope.tx = tx;
|
||||||
|
$scope.txs.push(tx);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -26,6 +41,12 @@ angular.module('insight.transactions').controller('transactionsController', ['$s
|
|||||||
$scope.txs = txs;
|
$scope.txs = txs;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
socket.on('tx', function(tx) {
|
||||||
|
console.log('Incoming message for new transaction!', tx);
|
||||||
|
$scope.findTx(tx.txid);
|
||||||
|
});
|
||||||
|
|
||||||
|
$scope.txs = [];
|
||||||
|
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
<section data-ng-controller="transactionsController" data-ng-init="findOne()">
|
<section data-ng-controller="transactionsController" data-ng-init="findThis()">
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h1>
|
<h1>
|
||||||
Transaction
|
Transaction
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user