Merge pull request #929 from matiu/feature/bitcore01
Updates model and tests to newest bitcore version
This commit is contained in:
commit
d7650f30ff
9 changed files with 182 additions and 83 deletions
|
|
@ -17,9 +17,9 @@ angular.module('copayApp.controllers').controller('ImportController',
|
|||
updateStatus('Importing wallet - Setting things up...');
|
||||
var w, errMsg;
|
||||
|
||||
// try to import encrypted wallet with passphrase
|
||||
try {
|
||||
w = walletFactory.import(encryptedObj, passphrase);
|
||||
|
||||
} catch (e) {
|
||||
errMsg = e.message;
|
||||
}
|
||||
|
|
@ -31,12 +31,14 @@ angular.module('copayApp.controllers').controller('ImportController',
|
|||
return;
|
||||
}
|
||||
|
||||
// if wallet was never used, we're done
|
||||
if (!w.isReady()) {
|
||||
$rootScope.wallet = w;
|
||||
controllerUtils.startNetwork($rootScope.wallet, $scope);
|
||||
return;
|
||||
}
|
||||
|
||||
// if it was used, we need to scan for indices
|
||||
w.updateIndexes(function(err) {
|
||||
updateStatus('Importing wallet - We are almost there...');
|
||||
if (err) {
|
||||
|
|
|
|||
26
js/models/core/BuilderMockV0.js
Normal file
26
js/models/core/BuilderMockV0.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
'use strict';
|
||||
|
||||
|
||||
var bitcore = require('bitcore');
|
||||
var Transaction = bitcore.Transaction;
|
||||
|
||||
function BuilderMockV0 (data) {
|
||||
this.vanilla = data;
|
||||
this.tx = new Transaction();
|
||||
this.tx.parse(new Buffer(data.tx, 'hex'));
|
||||
};
|
||||
|
||||
BuilderMockV0.prototype.build = function() {
|
||||
return this.tx;
|
||||
};
|
||||
|
||||
|
||||
BuilderMockV0.prototype.getSelectedUnspent = function() {
|
||||
return [];
|
||||
};
|
||||
|
||||
BuilderMockV0.prototype.toObj = function() {
|
||||
return this.vanilla;
|
||||
};
|
||||
|
||||
module.exports = BuilderMockV0;
|
||||
|
|
@ -6,6 +6,7 @@ var bitcore = require('bitcore');
|
|||
var util = bitcore.util;
|
||||
var Transaction = bitcore.Transaction;
|
||||
var Builder = bitcore.TransactionBuilder;
|
||||
var BuilderMockV0 = require('./BuilderMockV0');;
|
||||
var Script = bitcore.Script;
|
||||
var buffertools = bitcore.buffertools;
|
||||
|
||||
|
|
@ -42,8 +43,14 @@ TxProposal.prototype.setSent = function(sentTxid) {
|
|||
|
||||
TxProposal.fromObj = function(o) {
|
||||
var t = new TxProposal(o);
|
||||
var b = new Builder.fromObj(o.builderObj);
|
||||
t.builder = b;
|
||||
try {
|
||||
t.builder = new Builder.fromObj(o.builderObj);
|
||||
} catch (e) {
|
||||
if (!o.version) {
|
||||
t.builder = new BuilderMockV0(o.builderObj);
|
||||
t.readonly = 1;
|
||||
};
|
||||
}
|
||||
return t;
|
||||
};
|
||||
|
||||
|
|
@ -127,6 +134,17 @@ TxProposal.prototype.mergeMetadata = function(v1, author) {
|
|||
|
||||
};
|
||||
|
||||
//This should be on bitcore / Transaction
|
||||
TxProposal.prototype.countSignatures = function() {
|
||||
var tx = this.builder.build();
|
||||
|
||||
var ret = 0;
|
||||
for (var i in tx.ins) {
|
||||
ret += tx.countInputSignatures(i);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
module.exports = require('soop')(TxProposal);
|
||||
|
||||
|
||||
|
|
@ -145,8 +163,10 @@ TxProposals.fromObj = function(o) {
|
|||
});
|
||||
o.txps.forEach(function(o2) {
|
||||
var t = TxProposal.fromObj(o2);
|
||||
var id = t.builder.build().getNormalizedHash().toString('hex');
|
||||
ret.txps[id] = t;
|
||||
if (t.builder) {
|
||||
var id = t.builder.build().getNormalizedHash().toString('hex');
|
||||
ret.txps[id] = t;
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ function Wallet(opts) {
|
|||
self[k] = opts[k];
|
||||
});
|
||||
if (copayConfig.forceNetwork && this.getNetworkName() !== copayConfig.networkName)
|
||||
throw new Error('Network forced to '+copayConfig.networkName+
|
||||
' and tried to create a Wallet with network '+ this.getNetworkName());
|
||||
throw new Error('Network forced to ' + copayConfig.networkName +
|
||||
' and tried to create a Wallet with network ' + this.getNetworkName());
|
||||
|
||||
this.log('creating ' + opts.requiredCopayers + ' of ' + opts.totalCopayers + ' wallet');
|
||||
|
||||
|
|
@ -122,7 +122,6 @@ Wallet.prototype._handlePublicKeyRing = function(senderId, data, isInbound) {
|
|||
|
||||
|
||||
Wallet.prototype._handleTxProposal = function(senderId, data) {
|
||||
preconditions.checkArgument(senderId);
|
||||
this.log('RECV TXPROPOSAL:', data);
|
||||
|
||||
var inTxp = TxProposals.TxProposal.fromObj(data.txProposal);
|
||||
|
|
@ -489,7 +488,10 @@ Wallet.prototype.getTxProposals = function() {
|
|||
txp.finallyRejected = true;
|
||||
}
|
||||
|
||||
ret.push(txp);
|
||||
if (txp.readonly && !txp.finallyRejected && !txp.sentTs) {
|
||||
} else {
|
||||
ret.push(txp);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
|
@ -509,6 +511,7 @@ Wallet.prototype.reject = function(ntxid) {
|
|||
};
|
||||
|
||||
|
||||
|
||||
Wallet.prototype.sign = function(ntxid, cb) {
|
||||
preconditions.checkState(typeof this.getMyCopayerId() !== 'undefined');
|
||||
var self = this;
|
||||
|
|
@ -522,11 +525,11 @@ Wallet.prototype.sign = function(ntxid, cb) {
|
|||
var keys = self.privateKey.getForPaths(txp.inputChainPaths);
|
||||
|
||||
var b = txp.builder;
|
||||
var before = b.signaturesAdded;
|
||||
var before = txp.countSignatures();
|
||||
b.sign(keys);
|
||||
|
||||
var ret = false;
|
||||
if (b.signaturesAdded > before) {
|
||||
if (txp.countSignatures() > before) {
|
||||
txp.signedBy[myId] = Date.now();
|
||||
self.sendTxProposal(ntxid);
|
||||
self.store();
|
||||
|
|
@ -697,15 +700,9 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, comment, utxos
|
|||
var priv = this.privateKey;
|
||||
opts = opts || {};
|
||||
|
||||
var amountSat = bignum(amountSatStr);
|
||||
preconditions.checkArgument(new Address(toAddress).network().name === this.getNetworkName());
|
||||
if (!pkr.isComplete()) {
|
||||
throw new Error('publicKeyRing is not complete');
|
||||
}
|
||||
|
||||
if (comment && comment.length > 100) {
|
||||
throw new Error("comment can't be longer that 100 characters");
|
||||
}
|
||||
preconditions.checkState(pkr.isComplete());
|
||||
if (comment) preconditions.checkArgument(comment.length <= 100);
|
||||
|
||||
if (!opts.remainderOut) {
|
||||
opts.remainderOut = {
|
||||
|
|
@ -717,7 +714,7 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, comment, utxos
|
|||
.setUnspent(utxos)
|
||||
.setOutputs([{
|
||||
address: toAddress,
|
||||
amountSat: amountSat
|
||||
amountSatStr: amountSatStr,
|
||||
}]);
|
||||
|
||||
var selectedUtxos = b.getSelectedUnspent();
|
||||
|
|
@ -735,7 +732,9 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, comment, utxos
|
|||
var now = Date.now();
|
||||
|
||||
var me = {};
|
||||
if (priv && b.signaturesAdded) me[myId] = now;
|
||||
|
||||
var tx = b.build();
|
||||
if (priv && tx.countInputSignatures(0)) me[myId] = now;
|
||||
|
||||
var meSeen = {};
|
||||
if (priv) meSeen[myId] = now;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue