2014-01-09 15:24:14 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies.
|
|
|
|
*/
|
|
|
|
var mongoose = require('mongoose'),
|
2014-01-10 16:42:39 -08:00
|
|
|
Schema = mongoose.Schema
|
2014-01-09 15:24:14 -08:00
|
|
|
;
|
|
|
|
|
|
|
|
/**
|
2014-01-10 16:42:39 -08:00
|
|
|
* Addr Schema
|
2014-01-09 15:24:14 -08:00
|
|
|
*/
|
|
|
|
var AddressSchema = new Schema({
|
|
|
|
|
|
|
|
// For now we keep this as short as possible
|
|
|
|
// More fields will be propably added as we move
|
|
|
|
// forward with the UX
|
|
|
|
addr: {
|
|
|
|
type: String,
|
|
|
|
index: true,
|
|
|
|
unique: true,
|
|
|
|
},
|
2014-01-10 16:42:39 -08:00
|
|
|
inputs: [{
|
|
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
|
|
ref: 'TransactionItem' //Edit: I'd put the schema. Silly me.
|
|
|
|
}],
|
|
|
|
output: [{
|
|
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
|
|
ref: 'TransactionItem' //Edit: I'd put the schema. Silly me.
|
|
|
|
}],
|
2014-01-09 15:24:14 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AddressSchema.statics.load = function(id, cb) {
|
|
|
|
this.findOne({
|
|
|
|
_id: id
|
|
|
|
}).exec(cb);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
AddressSchema.statics.fromAddr = function(hash, cb) {
|
|
|
|
this.findOne({
|
|
|
|
hash: hash,
|
|
|
|
}).exec(cb);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
AddressSchema.statics.fromAddrWithInfo = function(hash, cb) {
|
2014-01-10 16:42:39 -08:00
|
|
|
this.fromHash(hash, function(err, addr) {
|
2014-01-09 15:24:14 -08:00
|
|
|
if (err) return cb(err);
|
2014-01-10 16:42:39 -08:00
|
|
|
if (!addr) { return cb(new Error('Addr not found')); }
|
|
|
|
// TODO
|
|
|
|
// addr.getInfo(function(err) { return cb(err,addr); } );
|
2014-01-09 15:24:14 -08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = mongoose.model('Address', AddressSchema);
|