From 4457342af0f38aa0f724b1a9dcaecc1ef2ea9381 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Thu, 16 Jan 2014 10:54:59 -0300 Subject: [PATCH] fix block and tx times for historic --- app/models/Block.js | 2 +- app/models/Transaction.js | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/models/Block.js b/app/models/Block.js index 17010f4..a011ef9 100644 --- a/app/models/Block.js +++ b/app/models/Block.js @@ -53,7 +53,7 @@ BlockSchema.statics.customCreate = function(block, cb) { newBlock.time = block.time ? block.time : Math.round(new Date().getTime() / 1000); newBlock.hash = block.blockHash; - Transaction.createFromArray(block.tx, function(err, inserted_txs) { + Transaction.createFromArray(block.tx, newBlock.time, function(err, inserted_txs) { if (err) return cb(err); newBlock.save(function(err) { return cb(err, inserted_txs); diff --git a/app/models/Transaction.js b/app/models/Transaction.js index 80287f5..d1eb3b6 100644 --- a/app/models/Transaction.js +++ b/app/models/Transaction.js @@ -87,18 +87,17 @@ TransactionSchema.statics.fromIdWithInfo = function(txid, cb) { }; -TransactionSchema.statics.createFromArray = function(txs, next) { +TransactionSchema.statics.createFromArray = function(txs, time, next) { var that = this; if (!txs) return next(); var mongo_txs = []; - var now = Math.round(new Date().getTime() / 1000); async.forEachLimit(txs, CONCURRENCY, function(txid, cb) { that.explodeTransactionItems( txid, function(err) { if (err) return next(err); - that.create({txid: txid, time: now}, function(err, new_tx) { + that.create({txid: txid, time: time}, function(err, new_tx) { if (err && ! err.toString().match(/E11000/)) return cb(err); if (new_tx) mongo_txs.push(new_tx); @@ -112,7 +111,7 @@ TransactionSchema.statics.createFromArray = function(txs, next) { }; -TransactionSchema.statics.explodeTransactionItems = function(txid, cb) { +TransactionSchema.statics.explodeTransactionItems = function(txid, time, cb) { this.queryInfo(txid, function(err, info) { if (err || !info) return cb(err); @@ -131,7 +130,7 @@ TransactionSchema.statics.explodeTransactionItems = function(txid, cb) { value_sat : -1 * i.valueSat, addr : i.addr, index : i.n, - ts : info.time, + ts : time, }, next_in); } else { @@ -155,7 +154,7 @@ TransactionSchema.statics.explodeTransactionItems = function(txid, cb) { value_sat : o.valueSat, addr : o.scriptPubKey.addresses[0], index : o.n, - ts : info.time, + ts : time, }, next_out); } else {