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){
|
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) {
|
||||||
|
|||||||
@ -44,10 +44,10 @@ BlockSchema.methods.explodeTransactions = function(next) {
|
|||||||
|
|
||||||
// console.log('exploding %s', this.hash, typeof this.tx);
|
// console.log('exploding %s', this.hash, typeof this.tx);
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user