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){ function(cb){
if (opts.destroy) { if (opts.destroy) {
console.log("Deleting Blocks..."); console.log("Deleting Blocks...");
Block.remove().exec(cb); return Block.remove().exec(cb);
} }
return cb();
}, },
function(cb){ function(cb){
if (opts.destroy) { if (opts.destroy) {
console.log("Deleting TXs..."); console.log("Deleting TXs...");
Transaction.remove().exec(cb); return Transaction.remove().exec(cb);
} }
return cb();
}, },
function(cb) { function(cb) {
that.syncBlocks(opts.reindex, function(err) { that.syncBlocks(opts.reindex, function(err) {

View File

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

View File

@ -10,15 +10,25 @@ var mongoose = require('mongoose'),
/** /**
*/ */
var TransactionSchema = new Schema({ var TransactionSchema = new Schema({
hash: { txid: {
type: String, type: String,
index: true, index: true,
unique: true, unique: true,
}, },
parsed: { version: Number,
type: Boolean, locktime: Number,
default: false, 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({ this.findOne({
hash: hash, txid: txid,
}).exec(cb); }).exec(cb);
}; };
/*
* virtual
*/
// ugly? new object every call?
TransactionSchema.virtual('date').get(function () {
return new Date(this.time);
});
module.exports = mongoose.model('Transaction', TransactionSchema); module.exports = mongoose.model('Transaction', TransactionSchema);