var assign = require('object-assign');
var MyEthActions = require('../actions/MyEthActions');

function EthService(url, options) {
  this.options = assign({
    blocksLimit: 20
  }, options||{});

  this.web3 = require('web3');
  this.web3.setProvider(new this.web3.providers.HttpProvider(url));
}

EthService.prototype.getNumber = function() {
  return this.web3.eth.blockNumber;
};

EthService.prototype.getBlocks = function() {
  return this.blocks;
};

EthService.prototype.start = function() {
  var number = this.getNumber();

  this.blocks = [];
  for(var i=0; i < this.options.blocksLimit; i++) {
    this.blocks.push( this.web3.eth.getBlock(number-i, false) );
  }

  MyEthActions.setupBlocks(this.blocks);

  var callback = function() {
    var number = this.getNumber();
    for(var i=this.blocks[0].number+1; i <= number; i++) {
      this.blocks.unshift(this.web3.eth.getBlock(i, false))
      MyEthActions.newBlock(this.blocks[0]);
    }
  };
  this.watcher = window.setInterval(callback.bind(this), 2000);
};

EthService.prototype.stop = function() {
  window.clearInterval(this.watcher);
};

module.exports = EthService;

@@ -289,19 +289,49 @@
 (url));%0A
-%7D%0A%0A
+%0A  this.watchers = %7B%7D;%0A%7D%0A%0Aassign(
 EthServi
@@ -342,17 +342,22 @@
 rototype
-.
+, %7B%0A  
 getNumbe
@@ -357,18 +357,17 @@
 etNumber
- =
+:
  functio
@@ -364,32 +364,34 @@
 r: function() %7B%0A
+  
   return this.we
@@ -414,33 +414,16 @@
 er;%0A
-%7D;%0A%0AEthService.prototype.
+  %7D,%0A%0A  
 getB
@@ -427,18 +427,17 @@
 etBlocks
- =
+:
  functio
@@ -442,16 +442,18 @@
 ion() %7B%0A
+  
   return
@@ -470,40 +470,159 @@
 ks;%0A
-%7D;%0A%0AEthService.prototype.
+  %7D,%0A%0A  getNetStats: function() %7B%0A    return %7B%0A      listening: this.web3.net.listening,%0A      peerCount: this.web3.net.peerCount%0A    %7D;%0A  %7D,%0A%0A  
 start
- =
+:
  fun
@@ -631,16 +631,18 @@
 ion() %7B%0A
+  
   var nu
@@ -663,24 +663,26 @@
 tNumber();%0A%0A
+  
   this.block
@@ -689,16 +689,18 @@
 s = %5B%5D;%0A
+  
   for(va
@@ -739,24 +739,26 @@
 mit; i++) %7B%0A
+  
     this.blo
@@ -814,13 +814,17 @@
  );%0A
+  
   %7D%0A%0A
+  
   My
@@ -864,25 +864,287 @@
 s);%0A
-%0A  var callback =
+    //MyEthActions.setupNetStats(this.getNetStats());%0A%0A    this.watchers%5B'blocks'%5D = window.setInterval(this._onNewBlock.bind(this), 2000);%0A  %7D,%0A%0A  stop: function() %7B%0A    for(var name in this.watchers) %7B%0A      window.clearInterval(this.watchers%5Bname%5D);%0A    %7D%0A  %7D,%0A%0A  _onNewBlock:
  fun
@@ -1365,158 +1365,11 @@
 %0A  %7D
-;%0A  this.watcher = window.setInterval(callback.bind(this), 2000);%0A%7D;%0A%0AEthService.prototype.stop = function() %7B%0A  window.clearInterval(this.watcher);
 %0A%7D
+)
 ;%0A%0Am

refactor EthService