mv wallet test from walletfactory to wallet
This commit is contained in:
parent
1ff109b5e5
commit
abf74695b6
5 changed files with 150 additions and 94 deletions
|
|
@ -57,6 +57,9 @@ var copayConfig = require('../../config');
|
|||
*/
|
||||
function Wallet(opts) {
|
||||
var self = this;
|
||||
preconditions.checkArgument(opts);
|
||||
|
||||
opts.reconnectDelay = opts.reconnectDelay || 500;
|
||||
|
||||
//required params
|
||||
['storage', 'network', 'blockchain',
|
||||
|
|
@ -177,6 +180,25 @@ Wallet.getMaxRequiredCopayers = function(totalCopayers) {
|
|||
return Wallet.COPAYER_PAIR_LIMITS[totalCopayers];
|
||||
};
|
||||
|
||||
/**
|
||||
* delete
|
||||
*
|
||||
* @param walletId
|
||||
* @param storage
|
||||
* @param cb
|
||||
* @return {undefined}
|
||||
*/
|
||||
Wallet.delete = function(walletId, storage, cb) {
|
||||
preconditions.checkArgument(cb);
|
||||
|
||||
storage.deletePrefix('wallet::' + walletId, function(err) {
|
||||
if (err) return cb(err);
|
||||
storage.deletePrefix(walletId + '::', function(err) {
|
||||
return cb(err);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @desc Set the copayer id for the owner of this wallet
|
||||
|
|
@ -874,7 +896,7 @@ Wallet.prototype.store = function(cb) {
|
|||
var self = this;
|
||||
this.keepAlive();
|
||||
|
||||
var val = this.toObj();
|
||||
var val = this.toObj();
|
||||
var key = 'wallet::' + this.id + ((val.opts && val.opts.name) ? '_' + obj.opts.name : '');
|
||||
this.storage.set(key, val, function(err) {
|
||||
log.debug('Wallet stored');
|
||||
|
|
@ -919,9 +941,23 @@ Wallet.prototype.toObj = function() {
|
|||
* @param {Storage} storage - a Storage instance to store the data of the wallet
|
||||
* @param {Network} network - a Network instance to communicate with peers
|
||||
* @param {Blockchain} blockchain - a Blockchain instance to retrieve state from the blockchain
|
||||
* @param skipFields
|
||||
*/
|
||||
Wallet.fromObj = function(o, storage, network, blockchain) {
|
||||
Wallet.fromObj = function(o, storage, network, blockchain, skipFields) {
|
||||
|
||||
|
||||
if (skipFields) {
|
||||
_.each(skipFields, function(k) {
|
||||
if (o[k]) {
|
||||
delete o[k];
|
||||
} else {
|
||||
throw new Error('unknown field:' + k);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// TODO Why moving everything to opts. This needs refactoring.
|
||||
|
||||
// clone opts
|
||||
var opts = JSON.parse(JSON.stringify(o.opts));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue