Browse Source

use isChange from address

activeAddress
Ivan Socolsky 10 years ago
parent
commit
1258ac24fb
  1. 10
      lib/model/addressmanager.js
  2. 5
      lib/server.js
  3. 6
      test/integration/server.js

10
lib/model/addressmanager.js

@ -45,16 +45,6 @@ AddressManager.prototype.getCurrentAddressPath = function(isChange) {
(isChange ? this.changeAddressIndex : this.receiveAddressIndex); (isChange ? this.changeAddressIndex : this.receiveAddressIndex);
}; };
AddressManager.getIndexesForPath = function(path) {
var s = path.split('/');
var l = s.length;
return {
isChange: s[l - 2] === '1',
addressIndex: parseInt(s[l - 1], 10),
copayerIndex: parseInt(s[l - 3], 10)
};
};
AddressManager.prototype.getNewAddressPath = function(isChange) { AddressManager.prototype.getNewAddressPath = function(isChange) {
var ret = this.getCurrentAddressPath(isChange); var ret = this.getCurrentAddressPath(isChange);
this._incrementIndex(isChange); this._incrementIndex(isChange);

5
lib/server.js

@ -22,7 +22,6 @@ var WalletUtils = require('./walletutils');
var Wallet = require('./model/wallet'); var Wallet = require('./model/wallet');
var Copayer = require('./model/copayer'); var Copayer = require('./model/copayer');
var Address = require('./model/address'); var Address = require('./model/address');
var AddressManager = require('./model/addressmanager');
var TxProposal = require('./model/txproposal'); var TxProposal = require('./model/txproposal');
var Notification = require('./model/notification'); var Notification = require('./model/notification');
@ -290,8 +289,8 @@ WalletService.prototype.getMainAddresses = function(opts, cb) {
self.storage.fetchAddresses(self.walletId, function(err, addresses) { self.storage.fetchAddresses(self.walletId, function(err, addresses) {
if (err) return cb(err); if (err) return cb(err);
var mainAddresses = _.filter(addresses, function(x) { var mainAddresses = _.filter(addresses, {
return !AddressManager.getIndexesForPath(x.path).isChange; isChange: false
}); });
return cb(null, mainAddresses); return cb(null, mainAddresses);

6
test/integration/server.js

@ -107,7 +107,9 @@ helpers.stubUtxos = function(server, wallet, amounts, cb) {
scriptPubKey: address.getScriptPubKey(wallet.m).toBuffer().toString('hex'), scriptPubKey: address.getScriptPubKey(wallet.m).toBuffer().toString('hex'),
address: address.address, address: address.address,
}; };
obj.toObject = function() {return obj;}; obj.toObject = function() {
return obj;
};
return obj; return obj;
}); });
blockExplorer.getUnspentUtxos = sinon.stub().callsArgWith(1, null, utxos); blockExplorer.getUnspentUtxos = sinon.stub().callsArgWith(1, null, utxos);
@ -670,7 +672,7 @@ describe('Copay server', function() {
should.not.exist(err); should.not.exist(err);
balance.totalAmount.should.equal(helpers.toSatoshi(300)); balance.totalAmount.should.equal(helpers.toSatoshi(300));
balance.lockedAmount.should.equal(helpers.toSatoshi(100)); balance.lockedAmount.should.equal(helpers.toSatoshi(100));
server.getAddresses({}, function(err, addresses) { server.storage.fetchAddresses(wallet.id, function(err, addresses) {
should.not.exist(err); should.not.exist(err);
var change = _.filter(addresses, { var change = _.filter(addresses, {
isChange: true isChange: true

Loading…
Cancel
Save