From a66b7e54ceccc6a335cd3f3b1f54182abd94ac69 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 5 Feb 2014 14:25:52 -0300 Subject: [PATCH] adapt REST API for leveldb --- app/controllers/transactions.js | 10 +++++++--- app/models/Address.js | 6 +++--- lib/BlockDb.js | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/controllers/transactions.js b/app/controllers/transactions.js index 9eeb5f1..e69b76d 100644 --- a/app/controllers/transactions.js +++ b/app/controllers/transactions.js @@ -3,11 +3,11 @@ /** * Module dependencies. */ -var Transaction = require('../../lib/TransactionDb').class(); var Address = require('../models/Address'); var async = require('async'); var common = require('./common'); +var TransactionDb = require('../../lib/TransactionDb').class(); var BlockDb = require('../../lib/BlockDb').class(); var bdb = new BlockDb(); @@ -17,7 +17,9 @@ var bdb = new BlockDb(); * Find transaction by hash ... */ exports.transaction = function(req, res, next, txid) { - Transaction.fromIdWithInfo(txid, function(err, tx) { + var tDb = new TransactionDb(); + + tDb.fromIdWithInfo(txid, function(err, tx) { if (err || ! tx) return common.handleErrors(err, res); else { @@ -40,7 +42,9 @@ exports.show = function(req, res) { var getTransaction = function(txid, cb) { - Transaction.fromIdWithInfo(txid, function(err, tx) { + var tDb = new TransactionDb(); + + tDb.fromIdWithInfo(txid, function(err, tx) { if (err) { console.log(err); } diff --git a/app/models/Address.js b/app/models/Address.js index 8dc6286..97e0527 100644 --- a/app/models/Address.js +++ b/app/models/Address.js @@ -9,8 +9,7 @@ function spec() { var BitcoreUtil = require('bitcore/util/util'); var TransactionDb = require('../../lib/TransactionDb').class(); - function Address(addrStr, txDb) { - this.txDb = txDb || new TransactionDb(); + function Address(addrStr) { this.balanceSat = 0; this.totalReceivedSat = 0; this.totalSentSat = 0; @@ -57,9 +56,10 @@ function spec() { Address.prototype.update = function(next) { var self = this; + var db = new TransactionDb(); async.series([ function (cb) { - self.txDb.fromAddr(self.addrStr, function(err,txOut){ + db.fromAddr(self.addrStr, function(err,txOut){ if (err) return cb(err); txOut.forEach(function(txItem){ diff --git a/lib/BlockDb.js b/lib/BlockDb.js index 39e220d..430c4b5 100644 --- a/lib/BlockDb.js +++ b/lib/BlockDb.js @@ -135,6 +135,7 @@ 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,