From 2f98fe35b335157c4e62f1be9c33c15cd1d43291 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 5 Feb 2014 15:08:39 -0300 Subject: [PATCH] rpc on classtool --- app/models/Address.js | 3 +-- lib/BlockDb.js | 9 +++------ lib/TransactionDb.js | 23 ++++++++++++----------- lib/TransactionRpc.js | 11 +++++------ test/integration/addr.js | 8 +++----- test/integration/addr.json | 6 +++--- 6 files changed, 27 insertions(+), 33 deletions(-) diff --git a/app/models/Address.js b/app/models/Address.js index 97e0527..d377cb1 100644 --- a/app/models/Address.js +++ b/app/models/Address.js @@ -61,9 +61,8 @@ function spec() { function (cb) { db.fromAddr(self.addrStr, function(err,txOut){ if (err) return cb(err); - txOut.forEach(function(txItem){ - var v = parseInt(txItem.value_sat); + var v = txItem.value_sat; self.totalReceivedSat += v; self.transactions.push(txItem.txid); diff --git a/lib/BlockDb.js b/lib/BlockDb.js index 430c4b5..95f9159 100644 --- a/lib/BlockDb.js +++ b/lib/BlockDb.js @@ -17,7 +17,8 @@ function spec(b) { levelup = require('levelup'), BitcoreBlock= require('bitcore/Block').class(), config = require('../config/config'); - var db = b.db || levelup(config.leveldb + '/blocks'); + var db = b.db || levelup(config.leveldb + '/blocks'); + var rpc = b.rpc || new RpcClient(config.bitcoind); var BlockDb = function() { @@ -112,8 +113,6 @@ function spec(b) { BlockDb.prototype.fromHashWithInfo = function(hash, cb) { - var rpc = new RpcClient(config.bitcoind); - rpc.getBlock(hash, function(err, info) { // Not found? if (err && err.code === -5) return cb(); @@ -135,7 +134,6 @@ function spec(b) { end: TIMESTAMP_ROOT + end_ts }) .on('data', function (data) { -console.log('[BlockDb.js.137:data:]',data); //TODO list.push({ ts: data.key.replace(TIMESTAMP_ROOT, ''), hash: data.value, @@ -149,8 +147,7 @@ console.log('[BlockDb.js.137:data:]',data); //TODO }); }; - BlockDb.blockIndex = function(height, cb) { - var rpc = new RpcClient(config.bitcoind); + BlockDb.prototype.blockIndex = function(height, cb) { rpc.getBlockHash(height, function(err, bh){ if (err) return cb(err); diff --git a/lib/TransactionDb.js b/lib/TransactionDb.js index ebc5669..7a45d74 100644 --- a/lib/TransactionDb.js +++ b/lib/TransactionDb.js @@ -82,8 +82,8 @@ function spec(b) { var v = data.value.split(':'); ret.push({ addr: v[0], - value_sat: v[1], - index: k[2], + value_sat: parseInt(v[1]), + index: parseInt(k[2]), }); }) .on('error', function (err) { @@ -98,9 +98,9 @@ function spec(b) { var v = data.value.split(':'); var set=0; for(var i=0; i