paypro: maintain received payment requests.

This commit is contained in:
Christopher Jeffrey 2014-07-31 12:23:06 -07:00 committed by Manuel Araoz
commit af12b56678
2 changed files with 36 additions and 9 deletions

View file

@ -94,10 +94,14 @@ angular.module('copayApp.controllers').controller('SendController',
&& copay.HDPath.parseBitcoinURI(address); && copay.HDPath.parseBitcoinURI(address);
if (uri && uri.merchant) { if (uri && uri.merchant) {
w.createPaymentTx({ var data = w.paymentRequests[uri.merchant];
uri: uri.merchant, if (data) {
memo: commentText } else {
}, done); w.createPaymentTx({
uri: uri.merchant,
memo: commentText
}, done);
}
} else { } else {
w.createTx(address, amount, commentText, done); w.createTx(address, amount, commentText, done);
} }

View file

@ -150,6 +150,8 @@ function Wallet(opts) {
this.addressBook = opts.addressBook || {}; this.addressBook = opts.addressBook || {};
this.publicKey = this.privateKey.publicHex; this.publicKey = this.privateKey.publicHex;
this.paymentRequests = opts.paymentRequests || {};
//network nonces are 8 byte buffers, representing a big endian number //network nonces are 8 byte buffers, representing a big endian number
//one nonce for oneself, and then one nonce for each copayer //one nonce for oneself, and then one nonce for each copayer
this.network.setHexNonce(opts.networkNonce); this.network.setHexNonce(opts.networkNonce);
@ -899,12 +901,30 @@ Wallet.prototype.createPaymentTx = function(options, cb) {
}; };
Wallet.prototype.fetchPaymentTx = function(options, cb) { Wallet.prototype.fetchPaymentTx = function(options, cb) {
var self = this;
options = options || {}; options = options || {};
if (typeof options === 'string') { if (typeof options === 'string') {
options = { uri: options }; options = { uri: options };
} }
options.fetch = true; options.fetch = true;
return this.createPaymentTx(options, cb); return this.createPaymentTx(options, function(err, merchantData, options, pr) {
var id = self.hashMerchantData(merchantData);
self.paymentRequests[id] = {
id: id,
merchantData: merchantData,
options: options,
pr: pr
};
return cb(null, merchantData);
});
};
Wallet.hashMerchantData =
Wallet.prototype.hashMerchantData = function(merchantData) {
return merchantData.request_url
+ ':' + merchantData.pr.payment_url
+ ':' + merchantData.total
+ ':' + merchantData.pr.pd.merchant_data;
}; };
Wallet.prototype.receivePaymentRequest = function(options, pr, cb) { Wallet.prototype.receivePaymentRequest = function(options, pr, cb) {
@ -989,11 +1009,12 @@ Wallet.prototype.receivePaymentRequest = function(options, pr, cb) {
total: bignum('0', 10).toString(10) total: bignum('0', 10).toString(10)
}; };
if (options.fetch) {
return cb(null, merchantData);
}
return this.getUnspent(function(err, unspent) { return this.getUnspent(function(err, unspent) {
if (options.fetch) {
self.createPaymentTxSync(options, merchantData, unspent);
return cb(null, merchantData, options, pr);
}
var ntxid = self.createPaymentTxSync(options, merchantData, unspent); var ntxid = self.createPaymentTxSync(options, merchantData, unspent);
if (ntxid) { if (ntxid) {
self.sendIndexes(); self.sendIndexes();
@ -1195,6 +1216,8 @@ Wallet.prototype.createPaymentTxSync = function(options, merchantData, unspent)
merchantData.total = merchantData.total.toString(10); merchantData.total = merchantData.total.toString(10);
if (options.fetch) return;
this.log(''); this.log('');
this.log('Created transaction:'); this.log('Created transaction:');
this.log(b.tx.getStandardizedObject()); this.log(b.tx.getStandardizedObject());