add isChange to address model

This commit is contained in:
Ivan Socolsky 2015-02-21 19:13:15 -03:00
parent 0672c9084f
commit 24e6ceeab5
3 changed files with 13 additions and 1 deletions

View File

@ -13,6 +13,7 @@ Address.create = function(opts) {
x.createdOn = Math.floor(Date.now() / 1000);
x.address = opts.address;
x.isChange = opts.isChange;
x.path = opts.path;
x.publicKeys = opts.publicKeys;
return x;
@ -23,6 +24,7 @@ Address.fromObj = function(obj) {
x.createdOn = obj.createdOn;
x.address = obj.address;
x.isChange = obj.isChange;
x.path = obj.path;
x.publicKeys = obj.publicKeys;
return x;

View File

@ -122,7 +122,9 @@ Wallet.prototype.createAddress = function(isChange) {
$.checkState(this.isComplete());
var path = this.addressManager.getNewAddressPath(isChange);
return Address.create(WalletUtils.deriveAddress(this.publicKeyRing, path, this.m, this.network));
var address = Address.create(WalletUtils.deriveAddress(this.publicKeyRing, path, this.m, this.network));
address.isChange = isChange;
return address;
};

View File

@ -534,6 +534,7 @@ describe('Copay server', function() {
should.not.exist(err);
address.should.exist;
address.address.should.equal('38Jf1QE7ddXscW76ACgJrNkMWBwDAgMm6M');
address.isChange.should.be.false;
address.path.should.equal('m/2147483647/0/0');
done();
});
@ -669,6 +670,13 @@ describe('Copay server', function() {
should.not.exist(err);
balance.totalAmount.should.equal(helpers.toSatoshi(300));
balance.lockedAmount.should.equal(helpers.toSatoshi(100));
server.getAddresses({}, function(err, addresses) {
should.not.exist(err);
var change = _.filter(addresses, {
isChange: true
});
change.length.should.equal(1);
});
done();
});
});