test passing with new TxProposal checks
This commit is contained in:
parent
32f281fb82
commit
ae94139236
5 changed files with 24 additions and 28 deletions
|
|
@ -44,9 +44,6 @@ function TxProposal(opts) {
|
||||||
TxProposal.prototype._checkPayPro = function() {
|
TxProposal.prototype._checkPayPro = function() {
|
||||||
if (!this.merchant) return;
|
if (!this.merchant) return;
|
||||||
|
|
||||||
console.log('[TxProposal.js.46]',
|
|
||||||
this.paymentProtocolURL , this.merchant.request_url);
|
|
||||||
|
|
||||||
if (this.paymentProtocolURL !== this.merchant.request_url)
|
if (this.paymentProtocolURL !== this.merchant.request_url)
|
||||||
throw new Error('PayPro: Mismatch on Payment URLs');
|
throw new Error('PayPro: Mismatch on Payment URLs');
|
||||||
|
|
||||||
|
|
@ -59,12 +56,12 @@ console.log('[TxProposal.js.46]',
|
||||||
if (!this.merchant.total || !this.merchant.outs[0].amountSatStr || !this.merchant.outs[0].address)
|
if (!this.merchant.total || !this.merchant.outs[0].amountSatStr || !this.merchant.outs[0].address)
|
||||||
throw new Error('PayPro: Missing amount');
|
throw new Error('PayPro: Missing amount');
|
||||||
|
|
||||||
if (this.builder.vanilla.outs.length != 1)
|
var outs = JSON.parse(this.builder.vanilla.outs);
|
||||||
|
if (_.size(outs) != 1)
|
||||||
throw new Error('PayPro: Wrong outs in Tx');
|
throw new Error('PayPro: Wrong outs in Tx');
|
||||||
|
|
||||||
|
|
||||||
var ppOut = this.merchant.outs[0];
|
var ppOut = this.merchant.outs[0];
|
||||||
var txOut = this.builder.vanilla.outs[0];
|
var txOut = outs[0];
|
||||||
|
|
||||||
if (ppOut.address !== txOut.address)
|
if (ppOut.address !== txOut.address)
|
||||||
throw new Error('PayPro: Wrong out address in Tx');
|
throw new Error('PayPro: Wrong out address in Tx');
|
||||||
|
|
|
||||||
|
|
@ -1328,11 +1328,15 @@ Wallet.prototype.getTxProposals = function() {
|
||||||
var copayers = this.getRegisteredCopayerIds();
|
var copayers = this.getRegisteredCopayerIds();
|
||||||
for (var ntxid in this.txProposals.txps) {
|
for (var ntxid in this.txProposals.txps) {
|
||||||
var txp = this.txProposals.getTxProposal(ntxid, copayers);
|
var txp = this.txProposals.getTxProposal(ntxid, copayers);
|
||||||
|
|
||||||
txp.signedByUs = txp.signedBy[this.getMyCopayerId()] ? true : false;
|
txp.signedByUs = txp.signedBy[this.getMyCopayerId()] ? true : false;
|
||||||
txp.rejectedByUs = txp.rejectedBy[this.getMyCopayerId()] ? true : false;
|
txp.rejectedByUs = txp.rejectedBy[this.getMyCopayerId()] ? true : false;
|
||||||
txp.finallyRejected = this.totalCopayers - txp.rejectCount < this.requiredCopayers;
|
txp.finallyRejected = this.totalCopayers - txp.rejectCount < this.requiredCopayers;
|
||||||
txp.isPending = !txp.finallyRejected && !txp.sentTxid;
|
txp.isPending = !txp.finallyRejected && !txp.sentTxid;
|
||||||
|
|
||||||
|
// si no gastada
|
||||||
|
// y si no esta expirada;
|
||||||
|
|
||||||
if (!txp.readonly || txp.finallyRejected || txp.sentTs) {
|
if (!txp.readonly || txp.finallyRejected || txp.sentTs) {
|
||||||
ret.push(txp);
|
ret.push(txp);
|
||||||
}
|
}
|
||||||
|
|
@ -1682,21 +1686,17 @@ Wallet.prototype.receivePaymentRequest = function(options, pr, cb) {
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.getUnspent(function(err, safeUnspent, unspent) {
|
return this.getUnspent(function(err, safeUnspent, unspent) {
|
||||||
|
|
||||||
if (options.fetch) {
|
if (options.fetch) {
|
||||||
if (!unspent || !unspent.length) {
|
if (!unspent || !unspent.length) {
|
||||||
return cb(new Error('No unspent outputs available.'));
|
return cb(new Error('No unspent outputs available.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var err;
|
||||||
try {
|
try {
|
||||||
self.createPaymentTxSync(options, merchantData, safeUnspent);
|
self.createPaymentTxSync(options, merchantData, safeUnspent);
|
||||||
} catch (e) {
|
} catch (e) { err = e;}
|
||||||
var msg = e.message || '';
|
return cb(err, merchantData, pr);
|
||||||
if (msg.indexOf('not enough unspent tx outputs to fulfill')) {
|
|
||||||
e = new Error('No unspent outputs available.');
|
|
||||||
return cb(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cb(null, merchantData, pr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var ntxid = self.createPaymentTxSync(options, merchantData, safeUnspent);
|
var ntxid = self.createPaymentTxSync(options, merchantData, safeUnspent);
|
||||||
|
|
@ -1972,18 +1972,20 @@ Wallet.prototype.createPaymentTxSync = function(options, merchantData, unspent)
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (Object.keys(outs) > 1)
|
// TODO, for now we only support PayPro with 1 output.
|
||||||
|
if (_.size(outs) !== 1)
|
||||||
throw new Error('PayPro: Unsupported outputs');
|
throw new Error('PayPro: Unsupported outputs');
|
||||||
|
|
||||||
merchantData.outs = outs;
|
var out = _.pairs(outs)[0];
|
||||||
|
merchantData.outs = [{
|
||||||
|
address: out[0],
|
||||||
|
amountSatStr: out[1].toString(10),
|
||||||
|
}];
|
||||||
merchantData.total = merchantData.total.toString(10);
|
merchantData.total = merchantData.total.toString(10);
|
||||||
|
|
||||||
var b = new Builder(opts)
|
var b = new Builder(opts)
|
||||||
.setUnspent(unspent)
|
.setUnspent(unspent)
|
||||||
.setOutputs({
|
.setOutputs(merchantData.outs);
|
||||||
address: _.keys(outs)[0],
|
|
||||||
amountSatStr: _.values(outs)[0].toString(10),
|
|
||||||
});
|
|
||||||
|
|
||||||
merchantData.pr.pd.outputs.forEach(function(output, i) {
|
merchantData.pr.pd.outputs.forEach(function(output, i) {
|
||||||
var script = {
|
var script = {
|
||||||
|
|
@ -2031,7 +2033,6 @@ Wallet.prototype.createPaymentTxSync = function(options, merchantData, unspent)
|
||||||
var meSeen = {};
|
var meSeen = {};
|
||||||
if (priv) meSeen[myId] = now;
|
if (priv) meSeen[myId] = now;
|
||||||
|
|
||||||
console.log('[Wallet.js.2043]', options, merchantData); //TODO
|
|
||||||
var ntxid = this.txProposals.add(new TxProposal({
|
var ntxid = this.txProposals.add(new TxProposal({
|
||||||
inputChainPaths: inputChainPaths,
|
inputChainPaths: inputChainPaths,
|
||||||
signedBy: me,
|
signedBy: me,
|
||||||
|
|
|
||||||
|
|
@ -156,6 +156,8 @@ InsightStorage.prototype.setItem = function(name, value, callback) {
|
||||||
var passphrase = this.getPassphrase();
|
var passphrase = this.getPassphrase();
|
||||||
var authHeader = new buffers.Buffer(this.email + ':' + passphrase).toString('base64');
|
var authHeader = new buffers.Buffer(this.email + ':' + passphrase).toString('base64');
|
||||||
var registerUrl = this.storeUrl + '/save';
|
var registerUrl = this.storeUrl + '/save';
|
||||||
|
|
||||||
|
log.debug('setItem ' + name + ' size:'+ (value.length/1024).toFixed(1) + 'kb' );
|
||||||
this.request.post({
|
this.request.post({
|
||||||
url: registerUrl,
|
url: registerUrl,
|
||||||
headers: {
|
headers: {
|
||||||
|
|
|
||||||
|
|
@ -137,11 +137,7 @@ describe('PayPro (in Wallet) model', function() {
|
||||||
var w = cachedCreateW2();
|
var w = cachedCreateW2();
|
||||||
unspentTest[0].address = w.publicKeyRing.getAddress(1, true, w.publicKey).toString();
|
unspentTest[0].address = w.publicKeyRing.getAddress(1, true, w.publicKey).toString();
|
||||||
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true, w.publicKey);
|
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true, w.publicKey);
|
||||||
w.getUnspent = function(cb) {
|
w.getUnspent = sinon.stub().yields(null, unspentTest, unspentTest);
|
||||||
return setTimeout(function() {
|
|
||||||
return cb(null, unspentTest, unspentTest);
|
|
||||||
}, 1);
|
|
||||||
};
|
|
||||||
return w;
|
return w;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,10 @@ function FakeBuilder() {
|
||||||
|
|
||||||
this.vanilla = {
|
this.vanilla = {
|
||||||
scriptSig: [VALID_SCRIPTSIG_BUF],
|
scriptSig: [VALID_SCRIPTSIG_BUF],
|
||||||
outs: [{
|
outs: JSON.stringify([{
|
||||||
address: '2NDJbzwzsmRgD2o5HHXPhuq5g6tkKTjYkd6',
|
address: '2NDJbzwzsmRgD2o5HHXPhuq5g6tkKTjYkd6',
|
||||||
amountSatStr: '123',
|
amountSatStr: '123',
|
||||||
}]
|
}]),
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue