adapt REST API for leveldb

This commit is contained in:
Matias Alejo Garcia 2014-02-05 14:25:52 -03:00
parent 11aa379bb4
commit a66b7e54ce
3 changed files with 11 additions and 6 deletions

View File

@ -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);
}

View File

@ -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){

View File

@ -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,