2014-01-07 11:49:42 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies.
|
|
|
|
*/
|
|
|
|
var mongoose = require('mongoose'),
|
|
|
|
Schema = mongoose.Schema;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
var TransactionSchema = new Schema({
|
2014-01-07 16:03:48 -08:00
|
|
|
txid: {
|
2014-01-07 11:49:42 -08:00
|
|
|
type: String,
|
|
|
|
index: true,
|
|
|
|
unique: true,
|
|
|
|
},
|
2014-01-07 16:03:48 -08:00
|
|
|
version: Number,
|
|
|
|
locktime: Number,
|
|
|
|
vin: {
|
|
|
|
type: Array,
|
|
|
|
default: [],
|
2014-01-07 11:49:42 -08:00
|
|
|
},
|
2014-01-07 16:03:48 -08:00
|
|
|
vout: {
|
|
|
|
type: Array,
|
|
|
|
default: [],
|
|
|
|
},
|
2014-01-07 20:37:29 -08:00
|
|
|
blockhash: {
|
|
|
|
type: String,
|
|
|
|
index: true,
|
|
|
|
default: null,
|
|
|
|
},
|
2014-01-07 16:03:48 -08:00
|
|
|
confirmations: Number,
|
|
|
|
time: Number,
|
|
|
|
blocktime: Number,
|
2014-01-07 11:49:42 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Statics
|
|
|
|
*/
|
|
|
|
|
|
|
|
TransactionSchema.statics.load = function(id, cb) {
|
|
|
|
this.findOne({
|
|
|
|
_id: id
|
|
|
|
}).exec(cb);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-01-07 16:03:48 -08:00
|
|
|
TransactionSchema.statics.fromID = function(txid, cb) {
|
2014-01-07 11:49:42 -08:00
|
|
|
this.findOne({
|
2014-01-07 16:03:48 -08:00
|
|
|
txid: txid,
|
2014-01-07 11:49:42 -08:00
|
|
|
}).exec(cb);
|
|
|
|
};
|
|
|
|
|
2014-01-07 16:03:48 -08:00
|
|
|
/*
|
|
|
|
* virtual
|
|
|
|
*/
|
|
|
|
|
|
|
|
// ugly? new object every call?
|
|
|
|
TransactionSchema.virtual('date').get(function () {
|
|
|
|
return new Date(this.time);
|
|
|
|
});
|
|
|
|
|
2014-01-07 11:49:42 -08:00
|
|
|
module.exports = mongoose.model('Transaction', TransactionSchema);
|