paypro: fix parseBitcoinURI. start using bitcoin uris in tests.

This commit is contained in:
Christopher Jeffrey 2014-07-29 11:14:07 -07:00 committed by Manuel Araoz
parent 283dec1f2e
commit e0ff9ca6bd
3 changed files with 21 additions and 4 deletions

View File

@ -86,8 +86,10 @@ angular.module('copayApp.controllers').controller('SendController',
$rootScope.pendingPayment = null;
}
if (~address.indexOf('://')) {
w.createTx(address, commentText, done);
var uri = address.indexOf('bitcoin:') === 0
&& copay.Structure.parseBitcoinURI(address);
if (uri && uri.merchant) {
w.createTx(uri.merchant, commentText, done);
} else {
w.createTx(address, amount, commentText, done);
}

View File

@ -5,6 +5,7 @@ var http = require('http');
var EventEmitter = imports.EventEmitter || require('events').EventEmitter;
var async = require('async');
var preconditions = require('preconditions').singleton();
var parseBitcoinURI = require('./Structure').parseBitcoinURI;
var bitcore = require('bitcore');
var bignum = bitcore.Bignum;
@ -774,6 +775,13 @@ Wallet.prototype.createPaymentTx = function(options, cb) {
options = { uri: options };
}
if (options.uri.indexOf('bitcoin:') === 0) {
options.uri = parseBitcoinURI(options.uri).merchant;
if (!options.uri) {
return cb(new Error('No URI.'));
}
}
return $http({
method: options.method || 'POST',
url: options.uri || options.url,

View File

@ -37,6 +37,12 @@ if (!is_browser) {
error: function(cb) {
this._error = cb;
return this;
},
_success: function() {
;
},
_error: function(_, err) {
throw err;
}
};
if (options.responseType === 'arraybuffer') {
@ -44,7 +50,7 @@ if (!is_browser) {
options.encoding = null;
}
_request(options, function(err, res, body) {
if (err) return ret._error(null, null, null, options);
if (err) return ret._error(null, err, null, options);
return ret._success(body, res.statusCode, res.headers, options);
});
return ret;
@ -62,6 +68,7 @@ function startServer(cb) {
var path = require('path');
var bc = path.dirname(require.resolve(__dirname + '/../../bitcore/package.json'));
//var bc = path.dirname(require.resolve('bitcore/package.json'));
var example = bc + '/examples/PayPro/server.js';
var server = require(example);
@ -206,7 +213,7 @@ describe('PayPro (in Wallet) model', function() {
return cb(null, unspentTest, []);
}, 1);
};
var address = server.uri + '/request';
var address = 'bitcoin:mq7se9wy2egettFxPbmn99cK8v5AFq55Lx?amount=0.11&r=' + server.uri + '/request';
var commentText = 'Hello, server. I\'d like to make a payment.';
w.createTx(address, commentText, function(ntxid, ca) {
if (w.totalCopayers > 1) {