rm storage.storage to storage.db

This commit is contained in:
Matias Alejo Garcia 2014-09-27 18:00:27 -03:00
commit 028a300012
7 changed files with 39 additions and 34 deletions

View file

@ -8,6 +8,7 @@ var Wallet = require('./Wallet');
var _ = require('underscore');
var log = require('../log');
var PluginManager = require('./PluginManager');
var Profile = require('./Profile');
var Async = module.exports.Async = require('./Async');
var Insight = module.exports.Insight = require('./Insight');
var preconditions = require('preconditions').singleton();
@ -48,7 +49,7 @@ function Identity(config, version, pluginManager) {
if (pluginManager) {
storageOpts = {
storage: pluginManager.get('STORAGE')
storage: pluginManager.get('DB')
};
}

View file

@ -24,7 +24,7 @@ var KIND_UNIQUE = PluginManager.KIND_UNIQUE = 1;
var KIND_MULTIPLE = PluginManager.KIND_MULTIPLE = 2;
PluginManager.TYPE = {};
PluginManager.TYPE['STORAGE'] = KIND_UNIQUE;
PluginManager.TYPE['DB'] = KIND_UNIQUE;
PluginManager.prototype._register = function(obj, name) {
preconditions.checkArgument(obj.type, 'Plugin has not type:' + name);

View file

@ -4,35 +4,40 @@ var _ = require('underscore');
var log = require('../log');
var bitcore = require('bitcore');
function Profile(opts, storage) {
function Profile(opts, password, storage) {
preconditions.checkArgument(opts.email);
preconditions.checkArgument(opts.password);
preconditions.checkArgument(password);
preconditions.checkArgument(storage);
preconditions.checkArgument(storage.getItem);
this.email = opts.email;
this.password = opts.password;
this.hash = bitcore.util.sha256ripe160(this.email + this.password);
this.hash = bitcore.util.sha256ripe160(this.email + this.password).toString('hex');
this.storage = storage;
this.extra = opts.extra;
};
Profile.fromObj = function(obj, storage) {
return new Profile(obj, storage);
Profile.fromObj = function(obj, password, storage) {
var o = _.clone(obj);
return new Profile(obj, password, storage);
};
Profile.prototype.toObj = function() {
return JSON.parse(JSON.stringify(this));
var obj = _.clone(this);
delete obj['hash'];
return JSON.parse(JSON.stringify(obj));
};
Profile.prototype.store = function(cb) {
// TODO
return cb();
// this.storage.setItem(this.hash, this.toObj());
var val = this.toObj();
var key = 'identity::' + this.hash + '_' + this.email;
this.storage.setFromObj(key, val, function(err) {
log.debug('Identity stored');
if (cb)
cb(err);
});
};
module.exports = Profile;