tests again!
This commit is contained in:
parent
f3f9ca3e33
commit
9b327cd458
5 changed files with 79 additions and 74 deletions
|
|
@ -11,6 +11,7 @@ var Key = bitcore.Key;
|
|||
var buffertools = bitcore.buffertools;
|
||||
var preconditions = require('preconditions').instance();
|
||||
|
||||
var TX_MAX_SIZE_KB = 50;
|
||||
var VERSION = 1;
|
||||
var CORE_FIELDS = ['builderObj', 'inputChainPaths', 'version', 'comment', 'paymentProtocolURL'];
|
||||
|
||||
|
|
@ -44,10 +45,14 @@ function TxProposal(opts) {
|
|||
var me = {};
|
||||
me[opts.creator] = now;
|
||||
|
||||
this.signedBy = me;
|
||||
this.signedBy = _.clone(me);
|
||||
this.seenBy = me;
|
||||
this.signedBy = {};
|
||||
this.creator = opts.creator;
|
||||
this.createdTs = now;
|
||||
if (opts.signWith) {
|
||||
if (!this.sign(opts.signWith, opts.creator))
|
||||
throw new Error('Could not sign generated tx');
|
||||
}
|
||||
}
|
||||
|
||||
this._sync();
|
||||
|
|
@ -99,8 +104,6 @@ TxProposal.prototype.sign = function(keys, signerId) {
|
|||
return signaturesAdded;
|
||||
};
|
||||
|
||||
|
||||
|
||||
TxProposal.prototype._check = function() {
|
||||
|
||||
if (this.builder.signhash && this.builder.signhash !== Transaction.SIGHASH_ALL) {
|
||||
|
|
@ -108,6 +111,11 @@ TxProposal.prototype._check = function() {
|
|||
}
|
||||
|
||||
var tx = this.builder.build();
|
||||
|
||||
var txSize = tx.getSize();
|
||||
if (txSize / 1024 > TX_MAX_SIZE_KB)
|
||||
throw new Error('BIG: Invalid TX proposal. Too big: ' + txSize + ' bytes');
|
||||
|
||||
if (!tx.ins.length)
|
||||
throw new Error('Invalid tx proposal: no ins');
|
||||
|
||||
|
|
@ -301,17 +309,6 @@ TxProposal._infoFromRedeemScript = function(s) {
|
|||
};
|
||||
};
|
||||
|
||||
TxProposal.prototype.mergeBuilder = function(incoming) {
|
||||
var b0 = this.builder;
|
||||
var b1 = incoming.builder;
|
||||
|
||||
var before = JSON.stringify(b0.toObj());
|
||||
b0.merge(b1);
|
||||
var after = JSON.stringify(b0.toObj());
|
||||
return after !== before;
|
||||
};
|
||||
|
||||
|
||||
TxProposal.prototype.getSeen = function(copayerId) {
|
||||
return this.seenBy[copayerId];
|
||||
};
|
||||
|
|
@ -421,9 +418,14 @@ TxProposal.prototype.setCopayers = function(senderId, keyMap, readOnlyPeers) {
|
|||
|
||||
// merge will not merge any metadata.
|
||||
TxProposal.prototype.merge = function(incoming) {
|
||||
var hasChanged = this.mergeBuilder(incoming);
|
||||
// Note that all inputs must have the same number of signatures, so checking
|
||||
// one (0) is OK.
|
||||
var before = this._inputSigners[0].length;
|
||||
this.builder.merge(incoming.builder);
|
||||
this._sync();
|
||||
return hasChanged;
|
||||
|
||||
var after = this._inputSigners[0].length;
|
||||
return after !== before;
|
||||
};
|
||||
|
||||
//This should be on bitcore / Transaction
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ var Async = require('./Async');
|
|||
var Insight = module.exports.Insight = require('./Insight');
|
||||
var copayConfig = require('../../config');
|
||||
|
||||
var TX_MAX_SIZE_KB = 50;
|
||||
var TX_MAX_INS = 70;
|
||||
|
||||
|
||||
|
|
@ -527,7 +526,6 @@ Wallet.prototype._onTxProposal = function(senderId, data) {
|
|||
var self = this;
|
||||
var m;
|
||||
|
||||
console.log('[Wallet.js.533]a', this.txProposals.txps); //TODO
|
||||
try {
|
||||
m = this.txProposals.merge(data.txProposal, Wallet.builderOpts);
|
||||
var keyMap = this._getKeyMap(m.txp);
|
||||
|
|
@ -538,7 +536,6 @@ console.log('[Wallet.js.533]a', this.txProposals.txps); //TODO
|
|||
this.txProposals.deleteOne(m.ntxid);
|
||||
m = null;
|
||||
}
|
||||
console.log('[Wallet.js.533]a', this.txProposals.txps); //TODO
|
||||
|
||||
this._processIncomingTxProposal(m, function(err) {
|
||||
if (err) {
|
||||
|
|
@ -546,6 +543,9 @@ console.log('[Wallet.js.533]a', this.txProposals.txps); //TODO
|
|||
if (m && m.ntxid)
|
||||
self.txProposals.deleteOne(m.ntxid);
|
||||
m = null;
|
||||
} else {
|
||||
if (m && m.hasChanged)
|
||||
self.sendTxProposal(m.ntxid);
|
||||
}
|
||||
self._processProposalEvents(senderId, m);
|
||||
});
|
||||
|
|
@ -1166,7 +1166,7 @@ Wallet.fromObj = function(o, readOpts) {
|
|||
Wallet.prototype._sendToPeers = function(recipients, obj) {
|
||||
if (!this.isShared()) return;
|
||||
|
||||
log.info('Wallet:' + this.getName() + ' ### SENDING ' + obj.type);
|
||||
log.info('Wallet:' + this.getName() + ' ### Sending ' + obj.type);
|
||||
log.debug('Sending obj', obj);
|
||||
|
||||
this.network.send(recipients, obj);
|
||||
|
|
@ -2086,7 +2086,7 @@ Wallet.prototype.spend = function(opts, cb) {
|
|||
opts.merchantData = merchantData;
|
||||
opts.toAddress = merchantData.outs[0].address;
|
||||
opts.amountSat = parseInt(merchantData.outs[0].amountSatStr);
|
||||
return self.createTx(opts, cb);
|
||||
return self.spend(opts, cb);
|
||||
});
|
||||
};
|
||||
preconditions.checkArgument(amountSat, 'no amount');
|
||||
|
|
@ -2095,7 +2095,7 @@ Wallet.prototype.spend = function(opts, cb) {
|
|||
this.getUnspent(function(err, safeUnspent) {
|
||||
if (err) {
|
||||
log.info(err);
|
||||
return cb(new Error('CreateTx: Could not get list of UTXOs'));
|
||||
return cb(new Error('Spend: Could not get list of UTXOs'));
|
||||
}
|
||||
|
||||
var ntxid, txp;
|
||||
|
|
@ -2212,28 +2212,21 @@ Wallet.prototype._createTxProposal = function(toAddress, amountSat, comment, utx
|
|||
var inputChainPaths = selectedUtxos.map(function(utxo) {
|
||||
return pkr.pathForAddress(utxo.address);
|
||||
});
|
||||
|
||||
b.setHashToScriptMap(pkr.getRedeemScriptMap(inputChainPaths));
|
||||
|
||||
var keys = priv.getForPaths(inputChainPaths);
|
||||
b.sign(keys);
|
||||
|
||||
|
||||
var tx = b.build();
|
||||
if (!tx.countInputSignatures(0))
|
||||
throw new Error('Could not sign generated tx');
|
||||
|
||||
var txSize = tx.getSize();
|
||||
if (txSize /
|
||||
1024 > TX_MAX_SIZE_KB)
|
||||
throw new Error('BIG: Resulting TX is too big ' + txSize + ' bytes. Aborting');
|
||||
|
||||
return new TxProposal({
|
||||
var myId = this.getMyCopayerId();
|
||||
var keys = priv.getForPaths(inputChainPaths);
|
||||
return new TxProposal({
|
||||
inputChainPaths: inputChainPaths,
|
||||
comment: comment,
|
||||
builder: b,
|
||||
creator: this.getMyCopayerId(),
|
||||
creator: myId,
|
||||
signWith: keys,
|
||||
});
|
||||
|
||||
return txp;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue