insight-ui-zcash/app/models/Transaction.js

65 lines
939 B
JavaScript
Raw Normal View History

2014-01-07 11:49:42 -08:00
'use strict';
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
/**
*/
var TransactionSchema = new Schema({
txid: {
2014-01-07 11:49:42 -08:00
type: String,
index: true,
unique: true,
},
version: Number,
locktime: Number,
vin: {
type: Array,
default: [],
2014-01-07 11:49:42 -08:00
},
vout: {
type: Array,
default: [],
},
2014-01-07 20:37:29 -08:00
blockhash: {
type: String,
index: true,
default: null,
},
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);
};
TransactionSchema.statics.fromID = function(txid, cb) {
2014-01-07 11:49:42 -08:00
this.findOne({
txid: txid,
2014-01-07 11:49:42 -08:00
}).exec(cb);
};
/*
* 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);