From 2aefe7119d4ccb90b480b5052dfebd007b32c32b Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Thu, 16 Jan 2014 11:01:01 -0300 Subject: [PATCH] fix hash in block historical sync --- app/models/Block.js | 3 ++- app/models/Transaction.js | 2 +- lib/Sync.js | 2 +- test/model/transaction.js | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/models/Block.js b/app/models/Block.js index a011ef9..d538b70 100644 --- a/app/models/Block.js +++ b/app/models/Block.js @@ -51,10 +51,11 @@ BlockSchema.statics.customCreate = function(block, cb) { var newBlock = new That(); newBlock.time = block.time ? block.time : Math.round(new Date().getTime() / 1000); - newBlock.hash = block.blockHash; + newBlock.hash = block.hash; 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 d1eb3b6..d8971f7 100644 --- a/app/models/Transaction.js +++ b/app/models/Transaction.js @@ -94,7 +94,7 @@ TransactionSchema.statics.createFromArray = function(txs, time, next) { async.forEachLimit(txs, CONCURRENCY, function(txid, cb) { - that.explodeTransactionItems( txid, function(err) { + that.explodeTransactionItems( txid, time, function(err) { if (err) return next(err); that.create({txid: txid, time: time}, function(err, new_tx) { diff --git a/lib/Sync.js b/lib/Sync.js index cd0805a..d4a38c1 100644 --- a/lib/Sync.js +++ b/lib/Sync.js @@ -227,7 +227,7 @@ function spec() { } // This will trigger an RPC call - Transaction.explodeTransactionItems( tx.txid, function(err) { + Transaction.explodeTransactionItems( tx.txid, tx.time, function(err) { if (proc++ % 1000 === 0) progress_bar('\tproc', pull, total); next(err); }); diff --git a/test/model/transaction.js b/test/model/transaction.js index d42c172..351ed2c 100644 --- a/test/model/transaction.js +++ b/test/model/transaction.js @@ -118,7 +118,8 @@ describe('Transaction', function(){ // Remove first TransactionItem.remove({txid: v.txid}, function(err) { - Transaction.explodeTransactionItems(v.txid, function(err, tx) { + var now = Math.round(new Date().getTime() / 1000); + Transaction.explodeTransactionItems(v.txid, now, function(err, tx) { if (err) done(err); TransactionItem