flosight-api/app/models/Transaction.js
2014-01-08 01:37:29 -03:00

65 lines
939 B
JavaScript

'use strict';
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
/**
*/
var TransactionSchema = new Schema({
txid: {
type: String,
index: true,
unique: true,
},
version: Number,
locktime: Number,
vin: {
type: Array,
default: [],
},
vout: {
type: Array,
default: [],
},
blockhash: {
type: String,
index: true,
default: null,
},
confirmations: Number,
time: Number,
blocktime: Number,
});
/**
* Statics
*/
TransactionSchema.statics.load = function(id, cb) {
this.findOne({
_id: id
}).exec(cb);
};
TransactionSchema.statics.fromID = function(txid, cb) {
this.findOne({
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);