From a1ef89487fce892796e4556445ef924e41f3189b Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Thu, 16 Jan 2014 16:56:09 -0300 Subject: [PATCH 1/6] Ey! we are contributors too! :) --- package.json | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index b136f9bc..3ddffc88 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,16 @@ "email": "manuelaraoz@gmail.com" }, { - "name": "Mario Colque", + "name": "Mario Colque", "email": "colquemario@gmail.com" + }, + { + "name": "Gustavo Cortez", + "email": "cmgustavo83@gmail.com" + }, + { + "name": "Juan Sosa", + "email": "bechilandia@gmail.com" } ], "bugs": { From face519245efa76dbb83f6557c4eba2a267fd93a Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 16 Jan 2014 17:25:52 -0300 Subject: [PATCH 2/6] move socket controller to controllers --- app/{views/sockets/main.js => controllers/socket.js} | 2 +- lib/HistoricSync.js | 2 +- lib/Sync.js | 2 +- server.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename app/{views/sockets/main.js => controllers/socket.js} (87%) diff --git a/app/views/sockets/main.js b/app/controllers/socket.js similarity index 87% rename from app/views/sockets/main.js rename to app/controllers/socket.js index b8b3f52d..c2fc0f7d 100644 --- a/app/views/sockets/main.js +++ b/app/controllers/socket.js @@ -1,6 +1,6 @@ 'use strict'; -var Transaction = require('../../models/Transaction'); +var Transaction = require('../models/Transaction'); // server-side socket behaviour diff --git a/lib/HistoricSync.js b/lib/HistoricSync.js index f3b99f14..11a2a547 100644 --- a/lib/HistoricSync.js +++ b/lib/HistoricSync.js @@ -14,7 +14,7 @@ function spec() { var Transaction = require('../app/models/Transaction'); var TransactionItem = require('../app/models/TransactionItem'); var Sync = require('./Sync').class(); - var sockets = require('../app/views/sockets/main.js'); + var sockets = require('../app/controllers/socket.js'); var CONCURRENCY = 5; diff --git a/lib/Sync.js b/lib/Sync.js index 084a1563..01a516cd 100644 --- a/lib/Sync.js +++ b/lib/Sync.js @@ -12,7 +12,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'); + var sockets = require('../app/controllers/socket.js'); var CONCURRENCY = 5; diff --git a/server.js b/server.js index f93802af..7e4caf6d 100644 --- a/server.js +++ b/server.js @@ -77,7 +77,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').init(app,io); +require('./app/controllers/socket.js').init(app,io); //Start the app by listening on var port = process.env.PORT || config.port; From 75b8d7279eed1b65fe4d4508e45bbdfbf4bf3c3b Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Thu, 16 Jan 2014 17:42:02 -0300 Subject: [PATCH 3/6] first step: preparing a common file for list of transactions --- public/views/address.html | 22 +------------ public/views/block.html | 53 +----------------------------- public/views/transaction/list.html | 35 ++++++++++++++++++++ 3 files changed, 37 insertions(+), 73 deletions(-) create mode 100644 public/views/transaction/list.html diff --git a/public/views/address.html b/public/views/address.html index bcafe336..539dca16 100644 --- a/public/views/address.html +++ b/public/views/address.html @@ -40,26 +40,6 @@

Transactions Transactions contained within this block

- - - - - - - - - - - - - - - - - - - - -
Transaction HashDatetimeFeeTransacted Amount
Loading...
{{tx.txid}}{{tx.time * 1000 | date:'medium'}}{{tx.feeds}}{{tx.valueOut}}
+
diff --git a/public/views/block.html b/public/views/block.html index a81b42dc..8d85c85d 100644 --- a/public/views/block.html +++ b/public/views/block.html @@ -50,18 +50,6 @@ Number Of Transactions {{block.tx.length}} - - Output Total - -- - - - Estimated Transaction Volume - -- - - - Transaction Fees - -- - Height {{block.height}} @@ -76,10 +64,6 @@
- - - - @@ -107,42 +91,7 @@

Transactions Transactions contained within this block

- -
-
- {{tx.txid}} - {{tx.time * 1000 | date:'medium'}} -
- -
-
- Transmitter -
-
- -
-
-
-
-

Receptor

-

Receptor

-
-
-

Bitcoin of Receptor

-

Bitcoin of Receptor

-
-
-
-
- -
- Feeds: {{tx.feeds}} -
- {{tx.valueOut}} -
-
-
- +
diff --git a/public/views/transaction/list.html b/public/views/transaction/list.html new file mode 100644 index 00000000..b41efc17 --- /dev/null +++ b/public/views/transaction/list.html @@ -0,0 +1,35 @@ +
+
+ {{tx.txid}} + {{tx.time * 1000 | date:'medium'}} +
+ +
+
+ Transmitter +
+
+ +
+
+
+
+

Receptor

+

Receptor

+
+
+

Bitcoin of Receptor

+

Bitcoin of Receptor

+
+
+
+
+ +
+ Feeds: {{tx.feeds}} +
+ {{tx.valueOut}} +
+
+
+ From 522d35905a9182928983c6deb97074aec3b5ddea Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Thu, 16 Jan 2014 18:28:23 -0300 Subject: [PATCH 4/6] final step: colquito/complete info of transaction list --- public/views/transaction/list.html | 33 +++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/public/views/transaction/list.html b/public/views/transaction/list.html index b41efc17..ca60761f 100644 --- a/public/views/transaction/list.html +++ b/public/views/transaction/list.html @@ -1,12 +1,23 @@ +
Loading...
{{tx.txid}} {{tx.time * 1000 | date:'medium'}} -
+
- Transmitter + No Inputs (Newly Generated isCoinBasens) +
+
+ {{vin.addr}} + {{vin.value}} BTC +

+ Outpoint: + {{vin.txid}} +

+
+
@@ -14,22 +25,24 @@
-

Receptor

-

Receptor

+
+ {{vout.scriptPubKey.type}} +
-

Bitcoin of Receptor

-

Bitcoin of Receptor

+
+ {{address}} + {{vout.value}} BTC +
- Feeds: {{tx.feeds}} + Feeds: {{tx.feeds}}
{{tx.valueOut}}
-
-
- + + From 59a34beda062fda2fd3f95c9583b1721c1eb5d2a Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Thu, 16 Jan 2014 23:23:10 -0300 Subject: [PATCH 5/6] fixes jshint warnings. add config for disabling sync --- app/controllers/socket.js | 16 ++++++------- app/models/Status.js | 2 +- config/env/development.js | 2 ++ lib/HistoricSync.js | 36 ++++++++++++++-------------- lib/PeerSync.js | 3 +-- lib/Sync.js | 15 ++++++------ server.js | 49 +++++++++++++++++++++++---------------- 7 files changed, 66 insertions(+), 57 deletions(-) diff --git a/app/controllers/socket.js b/app/controllers/socket.js index c2fc0f7d..7bcad799 100644 --- a/app/controllers/socket.js +++ b/app/controllers/socket.js @@ -1,25 +1,23 @@ 'use strict'; -var Transaction = require('../models/Transaction'); - // server-side socket behaviour -var io = null; +// io is a variable already taken in express +var ios = null; module.exports.init = function(app, io_ext) { - io = io_ext; - io.set('log level', 1); // reduce logging - io.sockets.on('connection', function(socket) { - + ios = io_ext; + ios.set('log level', 1); // reduce logging + ios.sockets.on('connection', function() { }); }; module.exports.broadcast_tx = function(tx) { - io.sockets.emit('tx', tx); + ios.sockets.emit('tx', tx); }; module.exports.broadcast_block = function(block) { - io.sockets.emit('block', block); + ios.sockets.emit('block', block); }; diff --git a/app/models/Status.js b/app/models/Status.js index 9ab66785..321e2271 100644 --- a/app/models/Status.js +++ b/app/models/Status.js @@ -97,7 +97,7 @@ function spec() { callback(null, bh.result); }); } - ], + ], function (err, result) { that.lastblockhash = result; return next(); diff --git a/config/env/development.js b/config/env/development.js index 0d4e6c1b..fbe2cb41 100755 --- a/config/env/development.js +++ b/config/env/development.js @@ -14,4 +14,6 @@ module.exports = { disableAgent: true, }, network: 'testnet', + disableP2pSync: false, + disableHistoricSync: false, } diff --git a/lib/HistoricSync.js b/lib/HistoricSync.js index 11a2a547..2c432d9c 100644 --- a/lib/HistoricSync.js +++ b/lib/HistoricSync.js @@ -4,19 +4,13 @@ require('classtool'); function spec() { - var mongoose = require('mongoose'); var util = require('util'); var RpcClient = require('bitcore/RpcClient').class(); var networks = require('bitcore/networks'); var async = require('async'); var config = require('../config/config'); var Block = require('../app/models/Block'); - var Transaction = require('../app/models/Transaction'); - var TransactionItem = require('../app/models/TransactionItem'); var Sync = require('./Sync').class(); - var sockets = require('../app/controllers/socket.js'); - var CONCURRENCY = 5; - function HistoricSync(opts) { this.block_count= 0; @@ -26,10 +20,12 @@ function spec() { } function p() { - var params = Array.prototype.slice.call(arguments); + var args = []; + Array.prototype.push.apply( args, arguments ); - params.unshift('[historic_sync]'); - console.log.apply(this,params); + args.unshift('[historic_sync]'); + /*jshint validthis:true */ + console.log.apply(this, args); } var progress_bar = function(string, current, total) { @@ -59,11 +55,11 @@ function spec() { var blockInfo; var blockObj; - async.series([ + async.series([ // Already got it? function(c) { Block.findOne({hash:blockHash}, function(err,block){ - if (err) { p(err); return c(err); }; + if (err) { p(err); return c(err); } if (block) { existed = 1; blockObj = block; @@ -96,7 +92,7 @@ function spec() { function(c) { if (existed) return c(); - that.sync.storeBlock(blockInfo.result, function(err, block) { + that.sync.storeBlock(blockInfo.result, function(err) { existed = err && err.toString().match(/E11000/); if (err && ! existed) return c(err); return c(); @@ -133,8 +129,9 @@ function spec() { HistoricSync.prototype.syncBlocks = function(start, end, isForward, cb) { var that = this; - p('Syncing Blocks, starting from: %s end: %s isForward:', - start, end, isForward); + p('Starting from: ', start); + p(' to : ', end); + p(' isForward: ', isForward); return that.getPrevNextBlock( start, end, @@ -203,7 +200,7 @@ function spec() { return cb(); }); }, - ], + ], function(err) { function sync() { @@ -224,7 +221,7 @@ function spec() { if (err && err.message.match(/ECONNREFUSED/) && retry_attemps--){ setTimeout(function() { - p("Retrying in %d secs ", retry_secs); + p('Retrying in %d secs', retry_secs); sync(); }, retry_secs * 1000); } @@ -232,9 +229,12 @@ function spec() { return next(err, that.block_count); }); } - sync(); + if (!err) + sync(); + else + return next(err, 0); }); - } + }; HistoricSync.prototype.import_history = function(opts, next) { var that = this; diff --git a/lib/PeerSync.js b/lib/PeerSync.js index f7e51b65..08561aca 100644 --- a/lib/PeerSync.js +++ b/lib/PeerSync.js @@ -23,7 +23,7 @@ function spec() { that.sync = new Sync({ networkName: network }); - that.sync.init(config, function() { + that.sync.init(config, function() { that.PeerManager = require('bitcore/PeerManager').createClass({ config: { network: network @@ -69,7 +69,6 @@ function spec() { }; PeerSync.prototype.handle_block = function(info) { - var self = this; var block = info.message.block; var blockHash = coinUtil.formatHashFull(block.calcHash()); console.log('[p2p_sync] Handle block: ' + blockHash); diff --git a/lib/Sync.js b/lib/Sync.js index 01a516cd..1e193493 100644 --- a/lib/Sync.js +++ b/lib/Sync.js @@ -5,18 +5,19 @@ require('classtool'); function spec() { var mongoose = require('mongoose'); - var util = require('util'); - var RpcClient = require('bitcore/RpcClient').class(); - var async = require('async'); var config = require('../config/config'); var Block = require('../app/models/Block'); var Transaction = require('../app/models/Transaction'); +<<<<<<< Updated upstream var TransactionItem = require('../app/models/TransactionItem'); var sockets = require('../app/controllers/socket.js'); var CONCURRENCY = 5; +======= + var sockets = require('../app/views/sockets/main.js'); +>>>>>>> Stashed changes - function Sync(config) { + function Sync() { this.tx_count = 0; } @@ -68,7 +69,7 @@ function spec() { start, end, isForward); - return that.getPrevNextBlock( start, end, + return that.getPrevNextBlock( start, end, isForward ? { next: 1 } : { prev: 1}, cb); }; @@ -84,7 +85,7 @@ function spec() { this.db.on('error', function(err) { console.log('connection error:' + err); - moogose.disconnect(); + mongoose.disconnect(); }); this.db.on('disconnect', function(err) { @@ -99,7 +100,7 @@ function spec() { Sync.prototype.close = function() { if (!(this.opts && this.opts.skip_db_connection)) { - console.log("closing connection"); + console.log('closing connection'); this.db.close(); } }; diff --git a/server.js b/server.js index 7e4caf6d..b69b910d 100644 --- a/server.js +++ b/server.js @@ -4,6 +4,7 @@ //Set the node enviornment variable if not set before process.env.NODE_ENV = process.env.NODE_ENV || 'development'; + /** * Module dependencies. */ @@ -13,6 +14,7 @@ var express = require('express'), HistoricSync = require('./lib/HistoricSync').class(), mongoose = require('mongoose'); + /** * Main application entry file. */ @@ -42,31 +44,38 @@ var walk = function(path) { walk(models_path); // historic_sync process -var hs = new HistoricSync(); -hs.init({ - skip_db_connection: true, - networkName: config.network -}, function() { - hs.import_history({ - reverse: 1, - }, function(){ - console.log('historic_sync finished!'); +if (!config.disableHistoricSync) { + var hs = new HistoricSync(); + hs.init({ + skip_db_connection: true, + networkName: config.network + }, function() { + hs.import_history({ + reverse: 1, + }, function(){ + console.log('historic_sync finished!'); + }); }); -}); +} // p2p_sync process -var ps = new PeerSync(); -ps.init({ - skip_db_connection: true, - broadcast_txs: true, - broadcast_blocks: true -}, function() { - ps.run(); -}); +if (!config.disableP2pSync) { + var ps = new PeerSync(); + ps.init({ + skip_db_connection: true, + broadcast_txs: true, + broadcast_blocks: true + }, function() { + ps.run(); + }); +} // express app -var app = express(); + +/*jshint validthis:true */ +var app = express(); + //express settings require('./config/express')(app, db); @@ -76,7 +85,7 @@ require('./config/routes')(app); // socket.io var server = require('http').createServer(app); -var io = require('socket.io').listen(server); +var ios = require('socket.io').listen(server); require('./app/controllers/socket.js').init(app,io); //Start the app by listening on From 3affbd43be90f6e2ba115989a9f26f789f8f39fa Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Thu, 16 Jan 2014 23:26:12 -0300 Subject: [PATCH 6/6] remove all jshint warns --- lib/Sync.js | 6 ------ server.js | 8 +++----- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/Sync.js b/lib/Sync.js index 1e193493..941ac37a 100644 --- a/lib/Sync.js +++ b/lib/Sync.js @@ -8,13 +8,7 @@ function spec() { var config = require('../config/config'); var Block = require('../app/models/Block'); var Transaction = require('../app/models/Transaction'); -<<<<<<< Updated upstream - var TransactionItem = require('../app/models/TransactionItem'); var sockets = require('../app/controllers/socket.js'); - var CONCURRENCY = 5; -======= - var sockets = require('../app/views/sockets/main.js'); ->>>>>>> Stashed changes function Sync() { diff --git a/server.js b/server.js index b69b910d..1d61a87a 100644 --- a/server.js +++ b/server.js @@ -72,10 +72,8 @@ if (!config.disableP2pSync) { } // express app - -/*jshint validthis:true */ -var app = express(); - +/*global app: true*/ +var app = express(); //express settings require('./config/express')(app, db); @@ -86,7 +84,7 @@ require('./config/routes')(app); // socket.io var server = require('http').createServer(app); var ios = require('socket.io').listen(server); -require('./app/controllers/socket.js').init(app,io); +require('./app/controllers/socket.js').init(app,ios); //Start the app by listening on var port = process.env.PORT || config.port;
Relayed By --
Difficulty {{block.difficulty}}