fix bug in drop DBs + Transation with many fields in mongo
This commit is contained in:
parent
34cff77e42
commit
1063af6f90
6
Sync.js
6
Sync.js
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue