commit
1a404d4d08
|
@ -9,12 +9,9 @@ var mongoose = require('mongoose'),
|
||||||
util = require('bitcore/util/util'),
|
util = require('bitcore/util/util'),
|
||||||
BitcoreBlock= require('bitcore/Block').class(),
|
BitcoreBlock= require('bitcore/Block').class(),
|
||||||
Transaction = require('./Transaction'),
|
Transaction = require('./Transaction'),
|
||||||
async = require('async'),
|
|
||||||
config = require('../../config/config')
|
config = require('../../config/config')
|
||||||
;
|
;
|
||||||
|
|
||||||
var CONCURRENCY = 5;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Block Schema
|
* Block Schema
|
||||||
*/
|
*/
|
||||||
|
@ -47,16 +44,18 @@ BlockSchema.path('title').validate(function(title) {
|
||||||
|
|
||||||
BlockSchema.statics.createTimestamped = function(block, cb) {
|
BlockSchema.statics.createTimestamped = function(block, cb) {
|
||||||
|
|
||||||
var that = this;
|
var That= this;
|
||||||
var now = Math.round(new Date().getTime() / 1000);
|
var now = Math.round(new Date().getTime() / 1000);
|
||||||
|
|
||||||
var BlockSchema = mongoose.model('Block', BlockSchema);
|
var BlockSchema = mongoose.model('Block', BlockSchema);
|
||||||
var newBlock = new that();
|
var newBlock = new That();
|
||||||
newBlock.time = now;
|
newBlock.time = now;
|
||||||
|
|
||||||
Transaction.createFromArray(block.tx, function(err, inserted_txs) {
|
Transaction.createFromArray(block.tx, function(err, inserted_txs) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
newBlock.save(cb);
|
newBlock.save(function(err) {
|
||||||
|
return cb(err, inserted_txs);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -96,17 +96,15 @@ TransactionSchema.statics.createFromArray = function(txs, next) {
|
||||||
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);
|
||||||
|
|
||||||
that.create({txid: txid, time: now}, function(err, new_tx) {
|
that.create({txid: txid, time: now}, function(err, new_tx) {
|
||||||
|
|
||||||
//console.log("created:", 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);
|
||||||
return cb();
|
return cb();
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
function(err) {
|
function(err) {
|
||||||
return next(err, mongo_txs);
|
return next(err, mongo_txs);
|
||||||
|
@ -117,8 +115,6 @@ TransactionSchema.statics.createFromArray = function(txs, next) {
|
||||||
TransactionSchema.statics.explodeTransactionItems = function(txid, cb) {
|
TransactionSchema.statics.explodeTransactionItems = function(txid, cb) {
|
||||||
|
|
||||||
this.queryInfo(txid, function(err, info) {
|
this.queryInfo(txid, function(err, info) {
|
||||||
|
|
||||||
//console.log("INFO",info);
|
|
||||||
if (err || !info) return cb(err);
|
if (err || !info) return cb(err);
|
||||||
|
|
||||||
var index = 0;
|
var index = 0;
|
||||||
|
@ -168,7 +164,8 @@ TransactionSchema.statics.explodeTransactionItems = function(txid, cb) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
function (err) {
|
function (err) {
|
||||||
return cb(err);
|
if (err && ! err.toString().match(/E11000/)) return cb(err);
|
||||||
|
return cb();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -45,7 +45,6 @@ function spec() {
|
||||||
function(c) {
|
function(c) {
|
||||||
Block.findOne({hash:blockHash}, function(err,block){
|
Block.findOne({hash:blockHash}, function(err,block){
|
||||||
if (err) { console.log(err); return c(err); };
|
if (err) { console.log(err); return c(err); };
|
||||||
|
|
||||||
if (block) {
|
if (block) {
|
||||||
existed = 1;
|
existed = 1;
|
||||||
blockObj = block;
|
blockObj = block;
|
||||||
|
|
Loading…
Reference in New Issue