fix block and tx times for historic
This commit is contained in:
parent
479b262361
commit
4457342af0
|
@ -53,7 +53,7 @@ BlockSchema.statics.customCreate = function(block, cb) {
|
||||||
newBlock.time = block.time ? block.time : Math.round(new Date().getTime() / 1000);
|
newBlock.time = block.time ? block.time : Math.round(new Date().getTime() / 1000);
|
||||||
newBlock.hash = block.blockHash;
|
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);
|
if (err) return cb(err);
|
||||||
newBlock.save(function(err) {
|
newBlock.save(function(err) {
|
||||||
return cb(err, inserted_txs);
|
return cb(err, inserted_txs);
|
||||||
|
|
|
@ -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;
|
var that = this;
|
||||||
if (!txs) return next();
|
if (!txs) return next();
|
||||||
var mongo_txs = [];
|
var mongo_txs = [];
|
||||||
var now = Math.round(new Date().getTime() / 1000);
|
|
||||||
|
|
||||||
async.forEachLimit(txs, CONCURRENCY, function(txid, cb) {
|
async.forEachLimit(txs, CONCURRENCY, function(txid, cb) {
|
||||||
|
|
||||||
that.explodeTransactionItems( txid, function(err) {
|
that.explodeTransactionItems( txid, function(err) {
|
||||||
if (err) return next(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 (err && ! err.toString().match(/E11000/)) return cb(err);
|
||||||
|
|
||||||
if (new_tx) mongo_txs.push(new_tx);
|
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) {
|
this.queryInfo(txid, function(err, info) {
|
||||||
if (err || !info) return cb(err);
|
if (err || !info) return cb(err);
|
||||||
|
@ -131,7 +130,7 @@ TransactionSchema.statics.explodeTransactionItems = function(txid, cb) {
|
||||||
value_sat : -1 * i.valueSat,
|
value_sat : -1 * i.valueSat,
|
||||||
addr : i.addr,
|
addr : i.addr,
|
||||||
index : i.n,
|
index : i.n,
|
||||||
ts : info.time,
|
ts : time,
|
||||||
}, next_in);
|
}, next_in);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -155,7 +154,7 @@ TransactionSchema.statics.explodeTransactionItems = function(txid, cb) {
|
||||||
value_sat : o.valueSat,
|
value_sat : o.valueSat,
|
||||||
addr : o.scriptPubKey.addresses[0],
|
addr : o.scriptPubKey.addresses[0],
|
||||||
index : o.n,
|
index : o.n,
|
||||||
ts : info.time,
|
ts : time,
|
||||||
}, next_out);
|
}, next_out);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in New Issue