bitcore-wallet-service/lib/model/addressable.js

35 lines
986 B
JavaScript
Raw Normal View History

2015-02-02 06:55:03 -08:00
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) {
2015-02-02 11:32:13 -08:00
return HDPath.Branch(isChange ? this.changeAddressIndex : this.receiveAddressIndex, isChange, this.copayerIndex);
2015-02-02 06:55:03 -08:00
};
Addressable.prototype.getNewAddressPath = function (isChange) {
this.addAddress(isChange);
2015-02-02 11:32:13 -08:00
return this.getCurrentAddressPath(isChange);
2015-02-02 06:55:03 -08:00
};
module.exports = Addressable;