complete API in profile
This commit is contained in:
parent
7abdc77611
commit
1ff109b5e5
4 changed files with 141 additions and 17 deletions
|
|
@ -395,10 +395,10 @@ Identity.prototype.createWallet = function(opts, cb) {
|
|||
this.storage.setPassphrase(opts.passphrase);
|
||||
|
||||
|
||||
var self = this;
|
||||
var w = this._getWallet(opts);
|
||||
this.profile.addWallet(w.id, function(err) {
|
||||
if (err) return cb(err);
|
||||
var self = this;
|
||||
w.store(function(err) {
|
||||
if (err) return cb(err);
|
||||
self.storage.setLastOpened(w.id, function(err) {
|
||||
|
|
@ -453,6 +453,10 @@ Identity.prototype.openWallet = function(walletId, passphrase, cb) {
|
|||
});
|
||||
};
|
||||
|
||||
|
||||
TODO
|
||||
from profile
|
||||
implement lastOpen
|
||||
Identity.prototype.listWallets = function(cb) {
|
||||
var self = this;
|
||||
this.storage.getWallets(function(wallets) {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ function Profile(info, password, storage) {
|
|||
|
||||
this.email = info.email;
|
||||
this.extra = info.extra;
|
||||
this.walletIds = {};
|
||||
this.walletInfos = {};
|
||||
this.hash = Profile.hash(this.email, password);
|
||||
this.storage = storage;
|
||||
};
|
||||
|
|
@ -45,12 +45,47 @@ Profile.open = function(storage, cb) {
|
|||
});
|
||||
};
|
||||
|
||||
Profile.prototype.getWallet = function(walletId, cb) {
|
||||
return this.walletInfos[walletId];
|
||||
};
|
||||
|
||||
Profile.prototype.addWallet = function(walletId, cb) {
|
||||
if (this.walletIds[walletId])
|
||||
Profile.prototype.listWallets = function(opts, cb) {
|
||||
return _.sortBy(this.walletInfos,function(winfo){
|
||||
return winfo.lastOpenedTs || winfo.createdTs;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Profile.prototype.deleteWallet = function(walletId, cb) {
|
||||
if (!this.walletInfos[walletId])
|
||||
return cb(new Error('WNOEXIST: Wallet not on profile'));
|
||||
|
||||
delete this.walletInfos[walletId];
|
||||
|
||||
this.store({
|
||||
overwrite: true
|
||||
}, cb);
|
||||
};
|
||||
|
||||
Profile.prototype.addToWallet = function(walletId, info, cb) {
|
||||
if (!this.walletInfos[walletId])
|
||||
return cb(new Error('WNOEXIST: Wallet not on profile'));
|
||||
|
||||
this.walletInfos[walletId] = _.extend(this.walletInfos[walletId], info);
|
||||
|
||||
this.store({
|
||||
overwrite: true
|
||||
}, cb);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Profile.prototype.addWallet = function(walletId, info, cb) {
|
||||
if (this.walletInfos[walletId])
|
||||
return cb(new Error('WEXIST: Wallet already on profile'));
|
||||
|
||||
this.walletIds[walletId] = Date.now();
|
||||
this.walletInfos[walletId] = _.extend(info, {createdTs: Date.now(), id: walletId} );
|
||||
|
||||
this.store({
|
||||
overwrite: true
|
||||
}, cb);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue