update to master

This commit is contained in:
Matias Alejo Garcia 2014-06-13 11:30:48 -03:00
commit 4fe58ec446
5 changed files with 54 additions and 42 deletions

View file

@ -18,7 +18,7 @@
"sjcl": "1.0.0", "sjcl": "1.0.0",
"file-saver": "*", "file-saver": "*",
"qrcode-decoder-js": "*", "qrcode-decoder-js": "*",
"bitcore": "git://github.com/bitpay/bitcore.git#772b12e471a76c092f73271449edc1890078e49e", "bitcore": "git://github.com/bitpay/bitcore.git#c94d2789582a481db19955f9e5df0129ffcc9e92",
"angular-moment": "~0.7.1", "angular-moment": "~0.7.1",
"socket.io-client": ">=1.0.0", "socket.io-client": ">=1.0.0",
"mousetrap": "1.4.6" "mousetrap": "1.4.6"

View file

@ -89,9 +89,9 @@ Wallet.prototype._handlePublicKeyRing = function(senderId, data, isInbound) {
var wasIncomplete = !this.publicKeyRing.isComplete(); var wasIncomplete = !this.publicKeyRing.isComplete();
var hasChanged; var hasChanged;
try{ try {
hasChanged = this.publicKeyRing.merge(inPKR, true); hasChanged = this.publicKeyRing.merge(inPKR, true);
} catch (e){ } catch (e) {
this.log('## WALLET ERROR', e); //TODO this.log('## WALLET ERROR', e); //TODO
this.emit('connectionError', e.message); this.emit('connectionError', e.message);
return; return;
@ -140,7 +140,7 @@ Wallet.prototype._handleTxProposals = function(senderId, data, isInbound) {
Wallet.prototype._handleData = function(senderId, data, isInbound) { Wallet.prototype._handleData = function(senderId, data, isInbound) {
// TODO check message signature // TODO check message signature
if (data.type !== 'walletId' && this.id !== data.walletId) { if (data.type !== 'walletId' && this.id !== data.walletId) {
this.emit('badMessage', senderId); this.emit('badMessage', senderId);
this.log('badMessage FROM:', senderId); //TODO this.log('badMessage FROM:', senderId); //TODO
@ -281,7 +281,7 @@ Wallet.prototype.scheduleConnect = function() {
var self = this; var self = this;
if (self.network.isOnline()) { if (self.network.isOnline()) {
self.connectToAll(); self.connectToAll();
self.currentDelay = self.currentDelay*2 || self.reconnectDelay; self.currentDelay = self.currentDelay * 2 || self.reconnectDelay;
setTimeout(self.scheduleConnect.bind(self), self.currentDelay); setTimeout(self.scheduleConnect.bind(self), self.currentDelay);
} }
} }
@ -329,7 +329,7 @@ Wallet.prototype.toObj = function() {
opts: optsObj, opts: optsObj,
publicKeyRing: this.publicKeyRing.toObj(), publicKeyRing: this.publicKeyRing.toObj(),
txProposals: this.txProposals.toObj(), txProposals: this.txProposals.toObj(),
privateKey: this.privateKey?this.privateKey.toObj():undefined privateKey: this.privateKey ? this.privateKey.toObj() : undefined
}; };
return walletObj; return walletObj;
@ -454,7 +454,7 @@ Wallet.prototype.reject = function(ntxid) {
var myId = this.getMyCopayerId(); var myId = this.getMyCopayerId();
var txp = this.txProposals.txps[ntxid]; var txp = this.txProposals.txps[ntxid];
if (!txp || txp.rejectedBy[myId] || txp.signedBy[myId]) { if (!txp || txp.rejectedBy[myId] || txp.signedBy[myId]) {
throw new Error('Invalid transaction to reject: '+ntxid); throw new Error('Invalid transaction to reject: ' + ntxid);
} }
txp.rejectedBy[myId] = Date.now(); txp.rejectedBy[myId] = Date.now();
@ -569,6 +569,9 @@ Wallet.prototype.getBalance = function(cb) {
var BIT = coinUtil.BIT; var BIT = coinUtil.BIT;
var COIN = coinUtil.COIN; var COIN = coinUtil.COIN;
if (!BIT)
throw new Error('BIT not defined. A newer version of bitcore is needed');
this.getUnspent(function(err, safeUnspent, unspent) { this.getUnspent(function(err, safeUnspent, unspent) {
if (err) { if (err) {
return cb(err); return cb(err);
@ -593,7 +596,7 @@ Wallet.prototype.getBalance = function(cb) {
safeBalance += amt; safeBalance += amt;
} }
safeBalance = safeBalance.toFixed(0) /BIT ; safeBalance = safeBalance.toFixed(0) / BIT;
return cb(null, balance, balanceByAddr, safeBalance); return cb(null, balance, balanceByAddr, safeBalance);
}); });
}; };
@ -611,8 +614,8 @@ Wallet.prototype.getUnspent = function(cb) {
var uu = self.txProposals.getUsedUnspent(maxRejectCount); var uu = self.txProposals.getUsedUnspent(maxRejectCount);
for (var i in unspentList) { for (var i in unspentList) {
var u=unspentList[i]; var u = unspentList[i];
if (! uu[u.txid +','+u.vout]) if (!uu[u.txid + ',' + u.vout])
safeUnspendList.push(u); safeUnspendList.push(u);
} }

View file

@ -28,7 +28,7 @@
"homepage": "https://github.com/bitpay/copay", "homepage": "https://github.com/bitpay/copay",
"devDependencies": { "devDependencies": {
"async": "0.9.0", "async": "0.9.0",
"bitcore": "git://github.com/bitpay/bitcore.git#772b12e471a76c092f73271449edc1890078e49e", "bitcore": "git://github.com/bitpay/bitcore.git#c94d2789582a481db19955f9e5df0129ffcc9e92",
"blanket": "1.1.6", "blanket": "1.1.6",
"browser-pack": "2.0.1", "browser-pack": "2.0.1",
"browserify": "3.32.1", "browserify": "3.32.1",

View file

@ -31,7 +31,7 @@ describe('Wallet model', function() {
(function() { (function() {
new Wallet(config) new Wallet(config)
}).should. }).should.
throw (); throw();
}); });
var createW = function(netKey, N) { var createW = function(netKey, N) {
@ -111,7 +111,7 @@ describe('Wallet model', function() {
var pkr = w.publicKeyRing; var pkr = w.publicKeyRing;
for (var i = 0; i < N-1; i++) { for (var i = 0; i < N - 1; i++) {
if (privateKeys) { if (privateKeys) {
var k = privateKeys[i]; var k = privateKeys[i];
pkr.addCopayer(k ? k.deriveBIP45Branch().extendedPublicKeyString() : null); pkr.addCopayer(k ? k.deriveBIP45Branch().extendedPublicKeyString() : null);
@ -246,7 +246,7 @@ describe('Wallet model', function() {
o = JSON.parse(JSON.stringify(o)); o = JSON.parse(JSON.stringify(o));
// non stored options // non stored options
o.opts.reconnectDelay=100; o.opts.reconnectDelay = 100;
var w2 = Wallet.fromObj(o, var w2 = Wallet.fromObj(o,
new Storage(config.storage), new Storage(config.storage),
@ -275,15 +275,15 @@ describe('Wallet model', function() {
(function() { (function() {
Wallet.decodeSecret('4fp61K187CsYmjoRQC5iAdC5eGmbCRsAAXfwEwetSQgHvZs27eWKaLaNHRoKM'); Wallet.decodeSecret('4fp61K187CsYmjoRQC5iAdC5eGmbCRsAAXfwEwetSQgHvZs27eWKaLaNHRoKM');
}).should.not. }).should.not.
throw (); throw();
(function() { (function() {
Wallet.decodeSecret('4fp61K187CsYmjoRQC5iAdC5eGmbCRsAAXfwEwetSQgHvZs27eWKaLaNHRoK'); Wallet.decodeSecret('4fp61K187CsYmjoRQC5iAdC5eGmbCRsAAXfwEwetSQgHvZs27eWKaLaNHRoK');
}).should. }).should.
throw (); throw();
(function() { (function() {
Wallet.decodeSecret('12345'); Wallet.decodeSecret('12345');
}).should. }).should.
throw (); throw();
}); });
it('call reconnect after interval', function(done) { it('call reconnect after interval', function(done) {
@ -462,30 +462,34 @@ describe('Wallet model', function() {
}); });
}); });
var roundErrorChecks=[ var roundErrorChecks = [{
{ unspent: [ 1.0001 ], unspent: [1.0001],
balance: 1000100 balance: 1000100
}, }, {
{ unspent: [ 1.0002 , 1.0003 , 1.0004 ], unspent: [1.0002, 1.0003, 1.0004],
balance: 3000900 balance: 3000900
}, }, {
{ unspent: [ 0.000002 , 1.000003 , 2.000004 ], unspent: [0.000002, 1.000003, 2.000004],
balance: 3000009 balance: 3000009
}, {
unspent: [0.0001, 0.0003],
balance: 400
}, {
unspent: [0.0001, 0.0003, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0002],
balance: 1100
}, },
{ unspent: [ 0.0001 , 0.0003 ],
balance: 400
},
{ unspent: [ 0.0001 , 0.0003, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0002 ],
balance: 1100
},
]; ];
roundErrorChecks.forEach(function(c){ roundErrorChecks.forEach(function(c) {
it('check rounding errors '+ c.unspent[0], function(done) { it('check rounding errors ' + c.unspent[0], function(done) {
var w = createW2(); var w = createW2();
w.generateAddress(); w.generateAddress();
w.blockchain.fixUnspent(c.unspent.map(function(u){return {amount:u}})); w.blockchain.fixUnspent(c.unspent.map(function(u) {
return {
amount: u
}
}));
w.getBalance(function(err, balance, balanceByAddr, safeBalance) { w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
balance.should.equal(c.balance); balance.should.equal(c.balance);
done(); done();
@ -582,5 +586,5 @@ describe('Wallet model', function() {
var w = createW(); var w = createW();
w.getNetworkName().should.equal('testnet'); w.getNetworkName().should.equal('testnet');
}); });
}); });

View file

@ -1,15 +1,15 @@
'use strict'; 'use strict';
if (typeof process === 'undefined' || !process.version) { if (typeof process === 'undefined' || !process.version) {
// browser // browser
var chai = chai || require('chai'); var chai = chai || require('chai');
var should = chai.should(); var should = chai.should();
var copay = copay || require('../copay'); var copay = copay || require('../copay');
var LocalPlain = copay.StorageLocalPlain; var LocalPlain = copay.StorageLocalPlain;
describe('Storage/LocalPlain model', function() { describe.skip('Storage/LocalPlain model', function() {
it('should create an instance', function () { it('should create an instance', function() {
var s = new LocalPlain(); var s = new LocalPlain();
should.exist(s); should.exist(s);
}); });
@ -17,7 +17,12 @@ if (typeof process === 'undefined' || !process.version) {
describe('#setFromObj', function() { describe('#setFromObj', function() {
it('should set keys from an object', function() { it('should set keys from an object', function() {
localStorage.clear(); localStorage.clear();
var obj = {test:'testval', opts: {name: 'testname'}}; var obj = {
test: 'testval',
opts: {
name: 'testname'
}
};
var storage = new LocalPlain(); var storage = new LocalPlain();
storage.setFromObj('walletId', obj); storage.setFromObj('walletId', obj);
storage.get('walletId', 'test').should.equal('testval'); storage.get('walletId', 'test').should.equal('testval');