fix bug in drop DBs + Transation with many fields in mongo

This commit is contained in:
Matias Alejo Garcia 2014-01-07 21:03:48 -03:00
parent 34cff77e42
commit 1063af6f90
3 changed files with 31 additions and 10 deletions

View File

@ -94,14 +94,16 @@ function spec(b) {
function(cb){
if (opts.destroy) {
console.log("Deleting Blocks...");
Block.remove().exec(cb);
return Block.remove().exec(cb);
}
return cb();
},
function(cb){
if (opts.destroy) {
console.log("Deleting TXs...");
Transaction.remove().exec(cb);
return Transaction.remove().exec(cb);
}
return cb();
},
function(cb) {
that.syncBlocks(opts.reindex, function(err) {

View File

@ -44,10 +44,10 @@ BlockSchema.methods.explodeTransactions = function(next) {
// console.log('exploding %s', this.hash, typeof this.tx);
async.forEach( this.tx,
async.forEach( this.tx,
function(tx, callback) {
// console.log('procesing TX %s', tx);
Transaction.create({ hash: tx }, function(err) {
Transaction.create({ txid: tx }, function(err) {
if (err && ! err.toString().match(/E11000/)) {
return callback();
}

View File

@ -10,15 +10,25 @@ var mongoose = require('mongoose'),
/**
*/
var TransactionSchema = new Schema({
hash: {
txid: {
type: String,
index: true,
unique: true,
},
parsed: {
type: Boolean,
default: false,
version: Number,
locktime: Number,
vin: {
type: Array,
default: [],
},
vout: {
type: Array,
default: [],
},
blockhash: String,
confirmations: Number,
time: Number,
blocktime: Number,
});
/**
@ -32,10 +42,19 @@ TransactionSchema.statics.load = function(id, cb) {
};
TransactionSchema.statics.fromHash = function(hash, cb) {
TransactionSchema.statics.fromID = function(txid, cb) {
this.findOne({
hash: hash,
txid: txid,
}).exec(cb);
};
/*
* virtual
*/
// ugly? new object every call?
TransactionSchema.virtual('date').get(function () {
return new Date(this.time);
});
module.exports = mongoose.model('Transaction', TransactionSchema);