You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.0 KiB

10 years ago
'use strict';
var _ = require('lodash');
10 years ago
var Copayer = require('./copayer');
10 years ago
function Wallet(opts) {
opts = opts || {};
10 years ago
this.createdOn = Math.floor(Date.now() / 1000);
10 years ago
this.id = opts.id;
this.name = opts.name;
this.m = opts.m;
this.n = opts.n;
this.status = 'pending';
this.publicKeyRing = [];
10 years ago
this.addressIndex = 0;
10 years ago
this.copayers = [];
10 years ago
};
Wallet.fromObj = function (obj) {
var x = new Wallet();
10 years ago
x.createdOn = obj.createdOn;
10 years ago
x.id = obj.id;
x.name = obj.name;
x.m = obj.m;
x.n = obj.n;
x.status = obj.status;
x.publicKeyRing = obj.publicKeyRing;
10 years ago
x.addressIndex = obj.addressIndex;
10 years ago
x.copayers = _.map(obj.copayers, function (copayer) {
return new Copayer(copayer);
});
10 years ago
return x;
};
10 years ago
Wallet.prototype.addCopayer = function (copayer) {
this.copayers.push(copayer);
if (this.copayers.length < this.n) return;
this.status = 'complete';
this.publicKeyRing = _.pluck(this.copayers, 'xPubKey');
};
Wallet.prototype.getCopayer = function (copayerId) {
return _.find(this.copayers, { id: copayerId });
};
10 years ago
module.exports = Wallet;