commit
d4fa919a8b
5 changed files with 221 additions and 189 deletions
|
|
@ -182,7 +182,6 @@ Insight.prototype._request = function(options, callback) {
|
||||||
request.open(options.method, url, true);
|
request.open(options.method, url, true);
|
||||||
request.timeout = 5000;
|
request.timeout = 5000;
|
||||||
request.ontimeout = function() {
|
request.ontimeout = function() {
|
||||||
console.log('Insight timeout...retrying');
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
return self._request(options,callback);
|
return self._request(options,callback);
|
||||||
}, self.retryDelay);
|
}, self.retryDelay);
|
||||||
|
|
@ -206,9 +205,7 @@ Insight.prototype._request = function(options, callback) {
|
||||||
else {
|
else {
|
||||||
var err= 'Error code: ' + request.status + ' - Status: ' + request.statusText
|
var err= 'Error code: ' + request.status + ' - Status: ' + request.statusText
|
||||||
+ ' - Description: ' + request.responseText;
|
+ ' - Description: ' + request.responseText;
|
||||||
console.log('Insight Temporary error (will retry):', err);
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
console.log('### Retrying Insight Request....'); //TODO
|
|
||||||
return self._request(options,callback);
|
return self._request(options,callback);
|
||||||
}, self.retryDelay);
|
}, self.retryDelay);
|
||||||
return callback(new Error(err));
|
return callback(new Error(err));
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,8 @@ PrivateKey.prototype._getHK = function(path) {
|
||||||
if (typeof path === 'undefined') {
|
if (typeof path === 'undefined') {
|
||||||
return this.bip;
|
return this.bip;
|
||||||
}
|
}
|
||||||
return this.bip.derive(path);
|
var ret = this.bip.derive(path);
|
||||||
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
PrivateKey.prototype.getForPaths = function(paths) {
|
PrivateKey.prototype.getForPaths = function(paths) {
|
||||||
|
|
|
||||||
|
|
@ -151,6 +151,7 @@ PublicKeyRing.prototype.getPubKeys = function(index, isChange) {
|
||||||
pubKeys = pubKeys.map(function(s){return new Buffer(s,'hex');});
|
pubKeys = pubKeys.map(function(s){return new Buffer(s,'hex');});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return pubKeys;
|
return pubKeys;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ Wallet.prototype._handlePublicKeyRing = function(senderId, data, isInbound) {
|
||||||
try{
|
try{
|
||||||
hasChanged = this.publicKeyRing.merge(inPKR, true);
|
hasChanged = this.publicKeyRing.merge(inPKR, true);
|
||||||
} catch (e){
|
} catch (e){
|
||||||
console.log('## WALLET ERROR', e); //TODO
|
this.log('## WALLET ERROR', e); //TODO
|
||||||
this.emit('connectionError', e.message);
|
this.emit('connectionError', e.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,43 +17,42 @@ var fakeStorage = copay.FakeStorage;
|
||||||
var PrivateKey = copay.PrivateKey || require('../js/models/PrivateKey');
|
var PrivateKey = copay.PrivateKey || require('../js/models/PrivateKey');
|
||||||
var TxProposals = copay.TxProposals || require('../js/models/TxProposal');
|
var TxProposals = copay.TxProposals || require('../js/models/TxProposal');
|
||||||
var PublicKeyRing = is_browser ? copay.PublicKeyRing :
|
var PublicKeyRing = is_browser ? copay.PublicKeyRing :
|
||||||
require('soop').load('../js/models/core/PublicKeyRing', {Storage: fakeStorage});
|
require('soop').load('../js/models/core/PublicKeyRing', {
|
||||||
|
Storage: fakeStorage
|
||||||
|
});
|
||||||
var is_browser = (typeof process.versions === 'undefined')
|
var is_browser = (typeof process.versions === 'undefined')
|
||||||
|
|
||||||
var config = {
|
var config = {
|
||||||
networkName:'livenet',
|
networkName: 'testnet',
|
||||||
};
|
};
|
||||||
|
|
||||||
var unspentTest = [
|
var unspentTest = [{
|
||||||
{
|
|
||||||
"address": "dummy",
|
"address": "dummy",
|
||||||
"scriptPubKey": "dummy",
|
"scriptPubKey": "dummy",
|
||||||
"txid": "2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1",
|
"txid": "2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1",
|
||||||
"vout": 1,
|
"vout": 1,
|
||||||
"amount": 10,
|
"amount": 10,
|
||||||
"confirmations": 7
|
"confirmations": 7
|
||||||
}
|
}];
|
||||||
];
|
|
||||||
|
|
||||||
var createPKR = function(bip32s) {
|
var createPKR = function(bip32s) {
|
||||||
var w = new PublicKeyRing(config);
|
var w = new PublicKeyRing(config);
|
||||||
should.exist(w);
|
should.exist(w);
|
||||||
|
|
||||||
for (var i = 0; i < 5; i++) {
|
for (var i = 0; i < 5; i++) {
|
||||||
if (bip32s) {
|
if (bip32s && i < bip32s.length) {
|
||||||
var b = bip32s[i];
|
var b = bip32s[i];
|
||||||
w.addCopayer(b?b.deriveBIP45Branch().extendedPublicKeyString():null);
|
w.addCopayer(b.deriveBIP45Branch().extendedPublicKeyString());
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
w.addCopayer();
|
w.addCopayer();
|
||||||
}
|
}
|
||||||
w.generateAddress(true);
|
}
|
||||||
w.generateAddress(true);
|
|
||||||
w.generateAddress(true);
|
|
||||||
w.generateAddress(false);
|
w.generateAddress(false);
|
||||||
w.generateAddress(false);
|
w.generateAddress(false);
|
||||||
w.generateAddress(false);
|
w.generateAddress(false);
|
||||||
//3x3 indexes
|
w.generateAddress(true);
|
||||||
|
w.generateAddress(true);
|
||||||
|
w.generateAddress(true);
|
||||||
|
|
||||||
return w;
|
return w;
|
||||||
};
|
};
|
||||||
|
|
@ -75,7 +74,11 @@ describe('TxProposals model', function() {
|
||||||
var isChange = 0;
|
var isChange = 0;
|
||||||
var index = 0;
|
var index = 0;
|
||||||
var pkr = createPKR([priv, priv2, priv3]);
|
var pkr = createPKR([priv, priv2, priv3]);
|
||||||
var opts = {remainderOut: { address: pkr.generateAddress(true).toString() }};
|
var opts = {
|
||||||
|
remainderOut: {
|
||||||
|
address: pkr.generateAddress(true).toString()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var w = new TxProposals({
|
var w = new TxProposals({
|
||||||
networkName: config.networkName,
|
networkName: config.networkName,
|
||||||
|
|
@ -117,10 +120,10 @@ describe('TxProposals model', function() {
|
||||||
networkName: config.networkName
|
networkName: config.networkName
|
||||||
});
|
});
|
||||||
should.exist(w);
|
should.exist(w);
|
||||||
w.network.name.should.equal('livenet');
|
w.network.name.should.equal(config.networkName);
|
||||||
});
|
});
|
||||||
|
|
||||||
function createTx(toAddress, amountSatStr, utxos, opts, priv, pkr) {
|
var createTx = function(toAddress, amountSatStr, utxos, opts, priv, pkr) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
|
|
||||||
var amountSat = bitcore.bignum(amountSatStr);
|
var amountSat = bitcore.bignum(amountSatStr);
|
||||||
|
|
@ -130,18 +133,23 @@ describe('TxProposals model', function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!opts.remainderOut) {
|
if (!opts.remainderOut) {
|
||||||
opts.remainderOut ={ address: pkr.generateAddress(true).toString() };
|
opts.remainderOut = {
|
||||||
|
address: pkr.generateAddress(true).toString()
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var b = new Builder(opts)
|
var b = new Builder(opts)
|
||||||
.setUnspent(utxos)
|
.setUnspent(utxos)
|
||||||
.setHashToScriptMap(pkr.getRedeemScriptMap())
|
.setHashToScriptMap(pkr.getRedeemScriptMap())
|
||||||
.setOutputs([{address: toAddress, amountSat: amountSat}])
|
.setOutputs([{
|
||||||
;
|
address: toAddress,
|
||||||
|
amountSat: amountSat
|
||||||
|
}]);
|
||||||
|
|
||||||
var signRet;
|
var signRet;
|
||||||
if (priv) {
|
if (priv) {
|
||||||
b.sign( priv.getAll(pkr.indexes.getReceiveIndex(), pkr.indexes.getChangeIndex()) );
|
var pkeys = priv.getAll(pkr.indexes.getReceiveIndex(), pkr.indexes.getChangeIndex());
|
||||||
|
b.sign(pkeys);
|
||||||
}
|
}
|
||||||
var me = {};
|
var me = {};
|
||||||
if (priv) me[priv.id] = Date.now();
|
if (priv) me[priv.id] = Date.now();
|
||||||
|
|
@ -169,8 +177,7 @@ describe('TxProposals model', function() {
|
||||||
w.add(createTx(
|
w.add(createTx(
|
||||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||||
'123456789',
|
'123456789',
|
||||||
unspentTest,
|
unspentTest, {},
|
||||||
{},
|
|
||||||
priv,
|
priv,
|
||||||
pkr
|
pkr
|
||||||
));
|
));
|
||||||
|
|
@ -196,8 +203,7 @@ describe('TxProposals model', function() {
|
||||||
w.add(createTx(
|
w.add(createTx(
|
||||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||||
'123456789',
|
'123456789',
|
||||||
unspentTest,
|
unspentTest, {},
|
||||||
{},
|
|
||||||
priv,
|
priv,
|
||||||
pkr
|
pkr
|
||||||
));
|
));
|
||||||
|
|
@ -228,7 +234,11 @@ describe('TxProposals model', function() {
|
||||||
var isChange = 0;
|
var isChange = 0;
|
||||||
var index = 0;
|
var index = 0;
|
||||||
var pkr = createPKR([priv]);
|
var pkr = createPKR([priv]);
|
||||||
var opts = {remainderOut: { address: pkr.generateAddress(true).toString() }};
|
var opts = {
|
||||||
|
remainderOut: {
|
||||||
|
address: pkr.generateAddress(true).toString()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
var w = new TxProposals({
|
var w = new TxProposals({
|
||||||
|
|
@ -298,20 +308,38 @@ var _dumpChunks = function (scriptSig, label) {
|
||||||
|
|
||||||
it('#merge, merge signatures case 2', function() {
|
it('#merge, merge signatures case 2', function() {
|
||||||
|
|
||||||
var priv = new PrivateKey(config);
|
var o1 ={ extendedPrivateKeyString: 'tprv8ZgxMBicQKsPdSF1avR6mXyDj5Uv1XY2UyUHSDpAXQ5TvPN7prGeDppjy4562rBB9gMMAhRfFdJrNDpQ4t69kkqHNEEen3PX1zBJqSehJDH',
|
||||||
var priv2 = new PrivateKey(config);
|
networkName: 'testnet',
|
||||||
var priv3 = new PrivateKey(config);
|
privateKeyCache: {} };
|
||||||
|
var o2 ={ extendedPrivateKeyString: 'tprv8ZgxMBicQKsPdVeB5RzuxS9JQcACueZYgUaM5eWzaEBkHjW5Pg6Mqez1APSqoUP1jUdbT8WVG7ZJYTXvUL7XtPzFYBXjmdKuwSor1dcNQ8j',
|
||||||
|
networkName: 'testnet',
|
||||||
|
privateKeyCache: {} };
|
||||||
|
var o3 ={ extendedPrivateKeyString: 'tprv8ZgxMBicQKsPeHWNrPVZtQVgcCtXBr5TACNbDQ56rwqNJce9MEc64US6DJKxpWsrebEomxxWZFDtkvkZGkzA43uLvdF4XHiWqoNaL6Dq2Gd',
|
||||||
|
networkName: 'testnet',
|
||||||
|
privateKeyCache: {} };
|
||||||
|
|
||||||
|
|
||||||
|
var priv = PrivateKey.fromObj(o1);
|
||||||
|
var priv2 = PrivateKey.fromObj(o2);
|
||||||
|
var priv3 = PrivateKey.fromObj(o3);
|
||||||
|
|
||||||
var ts = Date.now();
|
var ts = Date.now();
|
||||||
var isChange = 0;
|
var isChange = 0;
|
||||||
var index = 0;
|
var index = 0;
|
||||||
var pkr = createPKR([priv, priv2]);
|
var pkr = createPKR([priv, priv2]);
|
||||||
var opts = {remainderOut: { address: pkr.generateAddress(true).toString() }};
|
var opts = {
|
||||||
|
remainderOut: {
|
||||||
|
address: '2MxK2m7cPtEwjZBB8Ksq7ppjkgJyFPJGemr'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var addressToSign = pkr.generateAddress(false);
|
||||||
|
unspentTest[0].address = addressToSign.toString();
|
||||||
|
unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange);
|
||||||
|
var tx, txb;
|
||||||
|
|
||||||
var w = new TxProposals({
|
var w = new TxProposals({
|
||||||
networkName: config.networkName,
|
networkName: config.networkName,
|
||||||
});
|
});
|
||||||
unspentTest[0].address = pkr.getAddress(index, isChange).toString();
|
|
||||||
unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange);
|
|
||||||
|
|
||||||
w.add(createTx(
|
w.add(createTx(
|
||||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||||
|
|
@ -322,21 +350,23 @@ var _dumpChunks = function (scriptSig, label) {
|
||||||
pkr
|
pkr
|
||||||
));
|
));
|
||||||
|
|
||||||
var k = Object.keys(w.txps)[0];
|
var ntxid = Object.keys(w.txps)[0];
|
||||||
var tx = w.txps[k].builder.build();
|
txb = w.txps[ntxid].builder;
|
||||||
|
txb.signaturesAdded.should.equal(0);
|
||||||
|
tx = txb.build();
|
||||||
|
|
||||||
tx.isComplete().should.equal(false);
|
tx.isComplete().should.equal(false);
|
||||||
tx.countInputMissingSignatures(0).should.equal(1);
|
tx.countInputMissingSignatures(0).should.equal(1);
|
||||||
|
|
||||||
Object.keys(w.txps[k].signedBy).length.should.equal(0);
|
Object.keys(w.txps[ntxid].signedBy).length.should.equal(0);
|
||||||
Object.keys(w.txps[k].seenBy).length.should.equal(1);
|
Object.keys(w.txps[ntxid].seenBy).length.should.equal(1);
|
||||||
|
|
||||||
|
|
||||||
var w2 = new TxProposals({
|
var w2 = new TxProposals({
|
||||||
networkName: config.networkName,
|
networkName: config.networkName,
|
||||||
});
|
});
|
||||||
|
|
||||||
unspentTest[0].address = pkr.getAddress(index, isChange).toString();
|
|
||||||
unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange);
|
|
||||||
w2.add(createTx(
|
w2.add(createTx(
|
||||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||||
'123456789',
|
'123456789',
|
||||||
|
|
@ -345,30 +375,31 @@ var _dumpChunks = function (scriptSig, label) {
|
||||||
priv,
|
priv,
|
||||||
pkr
|
pkr
|
||||||
));
|
));
|
||||||
var k = Object.keys(w2.txps)[0];
|
var ntxid = Object.keys(w2.txps)[0];
|
||||||
tx = w2.txps[k].builder.build();
|
txb = w2.txps[ntxid].builder;
|
||||||
|
tx = txb.build();
|
||||||
|
|
||||||
|
txb.signaturesAdded.should.equal(1);
|
||||||
tx.isComplete().should.equal(false);
|
tx.isComplete().should.equal(false);
|
||||||
tx.countInputMissingSignatures(0).should.equal(2);
|
tx.countInputMissingSignatures(0).should.equal(2);
|
||||||
|
|
||||||
(w2.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
|
(w2.txps[ntxid].signedBy[priv.id] - ts > 0).should.equal(true);
|
||||||
(w2.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
|
(w2.txps[ntxid].seenBy[priv.id] - ts > 0).should.equal(true);
|
||||||
|
|
||||||
w.merge(w2);
|
w.merge(w2);
|
||||||
Object.keys(w.txps).length.should.equal(1);
|
Object.keys(w.txps).length.should.equal(1);
|
||||||
|
|
||||||
tx = w.txps[k].builder.build();
|
tx = w.txps[ntxid].builder.build();
|
||||||
tx.isComplete().should.equal(false);
|
tx.isComplete().should.equal(false);
|
||||||
tx.countInputMissingSignatures(0).should.equal(2);
|
tx.countInputMissingSignatures(0).should.equal(2);
|
||||||
(w.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
|
(w.txps[ntxid].signedBy[priv.id] - ts > 0).should.equal(true);
|
||||||
(w.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
|
(w.txps[ntxid].seenBy[priv.id] - ts > 0).should.equal(true);
|
||||||
|
|
||||||
|
|
||||||
var w3 = new TxProposals({
|
var w3 = new TxProposals({
|
||||||
networkName: config.networkName,
|
networkName: config.networkName,
|
||||||
publicKeyRing: pkr,
|
publicKeyRing: pkr,
|
||||||
});
|
});
|
||||||
unspentTest[0].address = pkr.getAddress(index, isChange).toString();
|
|
||||||
unspentTest[0].scriptPubKey = pkr.getScriptPubKeyHex(index, isChange);
|
|
||||||
w3.add(createTx(
|
w3.add(createTx(
|
||||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||||
'123456789',
|
'123456789',
|
||||||
|
|
@ -377,25 +408,24 @@ var _dumpChunks = function (scriptSig, label) {
|
||||||
priv2,
|
priv2,
|
||||||
pkr
|
pkr
|
||||||
));
|
));
|
||||||
tx = w3.txps[k].builder.build();
|
tx = w3.txps[ntxid].builder.build();
|
||||||
tx.isComplete().should.equal(false);
|
tx.isComplete().should.equal(false);
|
||||||
tx.countInputMissingSignatures(0).should.equal(2);
|
tx.countInputMissingSignatures(0).should.equal(2);
|
||||||
|
|
||||||
(w3.txps[k].signedBy[priv2.id] - ts > 0).should.equal(true);
|
(w3.txps[ntxid].signedBy[priv2.id] - ts > 0).should.equal(true);
|
||||||
(w3.txps[k].seenBy[priv2.id] - ts > 0).should.equal(true);
|
(w3.txps[ntxid].seenBy[priv2.id] - ts > 0).should.equal(true);
|
||||||
|
|
||||||
w.merge(w3);
|
w.merge(w3);
|
||||||
Object.keys(w.txps).length.should.equal(1);
|
Object.keys(w.txps).length.should.equal(1);
|
||||||
|
|
||||||
(w.txps[k].signedBy[priv.id] - ts > 0).should.equal(true);
|
(w.txps[ntxid].signedBy[priv.id] - ts > 0).should.equal(true);
|
||||||
(w.txps[k].seenBy[priv.id] - ts > 0).should.equal(true);
|
(w.txps[ntxid].seenBy[priv.id] - ts > 0).should.equal(true);
|
||||||
(w.txps[k].signedBy[priv2.id] - ts > 0).should.equal(true);
|
(w.txps[ntxid].signedBy[priv2.id] - ts > 0).should.equal(true);
|
||||||
(w.txps[k].seenBy[priv2.id] - ts > 0).should.equal(true);
|
(w.txps[ntxid].seenBy[priv2.id] - ts > 0).should.equal(true);
|
||||||
|
|
||||||
tx = w.txps[k].builder.build();
|
tx = w.txps[ntxid].builder.build();
|
||||||
tx.isComplete().should.equal(false);
|
tx.isComplete().should.equal(false);
|
||||||
tx.countInputMissingSignatures(0).should.equal(1);
|
tx.countInputMissingSignatures(0).should.equal(1);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -408,7 +438,11 @@ var _dumpChunks = function (scriptSig, label) {
|
||||||
var isChange = 0;
|
var isChange = 0;
|
||||||
var index = 0;
|
var index = 0;
|
||||||
var pkr = createPKR([priv, priv2, priv3]);
|
var pkr = createPKR([priv, priv2, priv3]);
|
||||||
var opts = {remainderOut: { address: pkr.generateAddress(true).toString() }};
|
var opts = {
|
||||||
|
remainderOut: {
|
||||||
|
address: pkr.generateAddress(true).toString()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var w = new TxProposals({
|
var w = new TxProposals({
|
||||||
networkName: config.networkName,
|
networkName: config.networkName,
|
||||||
|
|
@ -513,8 +547,7 @@ var _dumpChunks = function (scriptSig, label) {
|
||||||
w.add(createTx(
|
w.add(createTx(
|
||||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||||
'123456789',
|
'123456789',
|
||||||
unspentTest,
|
unspentTest, {},
|
||||||
{},
|
|
||||||
priv,
|
priv,
|
||||||
pkr
|
pkr
|
||||||
));
|
));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue