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.
34 lines
986 B
34 lines
986 B
var _ = require('lodash');
|
|
var HDPath = require('./hdpath');
|
|
|
|
function Addressable (opts) {
|
|
this.receiveAddressIndex = 0;
|
|
this.changeAddressIndex = 0;
|
|
this.copayerIndex = ( opts && _.isNumber(opts.copayerIndex)) ? opts.copayerIndex : HDPath.SHARED_INDEX;
|
|
};
|
|
|
|
|
|
Addressable.prototype.fromObj = function (obj) {
|
|
this.receiveAddressIndex = obj.receiveAddressIndex;
|
|
this.changeAddressIndex = obj.changeAddressIndex;
|
|
this.copayerIndex = obj.copayerIndex;
|
|
};
|
|
|
|
Addressable.prototype.addAddress = function (isChange) {
|
|
if (isChange) {
|
|
this.changeAddressIndex++;
|
|
} else {
|
|
this.receiveAddressIndex++;
|
|
}
|
|
};
|
|
|
|
Addressable.prototype.getCurrentAddressPath = function (isChange) {
|
|
return HDPath.Branch(isChange ? this.changeAddressIndex : this.receiveAddressIndex, isChange, this.copayerIndex);
|
|
};
|
|
|
|
Addressable.prototype.getNewAddressPath = function (isChange) {
|
|
this.addAddress(isChange);
|
|
return this.getCurrentAddressPath(isChange);
|
|
};
|
|
|
|
module.exports = Addressable;
|
|
|