Browse Source

fix(ln payments): update to new payreqs

renovate/lint-staged-8.x
Jack Mallers 7 years ago
parent
commit
31d6731c5d
  1. 26
      app/lnd/config/rpc.proto
  2. 2
      app/lnd/methods/index.js
  3. 12
      app/lnd/methods/invoicesController.js
  4. 8
      app/reducers/payform.js
  5. 2
      app/routes/app/containers/AppContainer.js

26
app/lnd/config/rpc.proto

@ -585,7 +585,6 @@ message HTLC {
int64 amount = 2 [json_name = "amount"]; int64 amount = 2 [json_name = "amount"];
bytes hash_lock = 3 [json_name = "hash_lock"]; bytes hash_lock = 3 [json_name = "hash_lock"];
uint32 expiration_height = 4 [json_name = "expiration_height"]; uint32 expiration_height = 4 [json_name = "expiration_height"];
uint32 revocation_delay = 5 [json_name = "revocation_delay"];
} }
message ActiveChannel { message ActiveChannel {
@ -1129,7 +1128,12 @@ message SetAliasResponse {
} }
message Invoice { message Invoice {
/// An optional memo to attach along with the invoice /**
An optional memo to attach along with the invoice. Used for record keeping
purposes for the invoice's creator, and will also be set in the description
field of the encoded payment request if the description_hash field is not
being used.
*/
string memo = 1 [json_name = "memo"]; string memo = 1 [json_name = "memo"];
/// An optional cryptographic receipt of payment /// An optional cryptographic receipt of payment
@ -1162,6 +1166,19 @@ message Invoice {
payment to the recipient. payment to the recipient.
*/ */
string payment_request = 9 [json_name = "payment_request"]; string payment_request = 9 [json_name = "payment_request"];
/**
Hash (SHA-256) of a description of the payment. Used if the description of
payment (memo) is too long to naturally fit within the description field
of an encoded payment request.
*/
bytes description_hash = 10 [json_name = "description_hash"];
/// Payment request expiry time in seconds. Default is 3600 (1 hour).
int64 expiry = 11 [json_name = "expiry"];
/// Fallback on-chain address.
string fallback_addr = 12 [json_name = "fallback_addr"];
} }
message AddInvoiceResponse { message AddInvoiceResponse {
bytes r_hash = 1 [json_name = "r_hash"]; bytes r_hash = 1 [json_name = "r_hash"];
@ -1241,6 +1258,11 @@ message PayReq {
string destination = 1 [json_name = "destination"]; string destination = 1 [json_name = "destination"];
string payment_hash = 2 [json_name = "payment_hash"]; string payment_hash = 2 [json_name = "payment_hash"];
int64 num_satoshis = 3 [json_name = "num_satoshis"]; int64 num_satoshis = 3 [json_name = "num_satoshis"];
int64 timestamp = 4 [json_name = "timestamp"];
int64 expiry = 5 [json_name = "expiry"];
string description = 6 [json_name = "description"];
string description_hash = 7 [json_name = "description_hash"];
string fallback_addr = 8 [json_name = "fallback_addr"];
} }
message FeeReportRequest {} message FeeReportRequest {}

2
app/lnd/methods/index.js

@ -75,7 +75,7 @@ export default function (lnd, event, msg, data) {
break break
case 'invoice': case 'invoice':
// Data looks like { invoices: [] } // Data looks like { invoices: [] }
invoicesController.getInvoice(data.payreq) invoicesController.getInvoice(lnd, { pay_req: data.payreq })
.then(invoiceData => event.sender.send('receiveInvoice', invoiceData)) .then(invoiceData => event.sender.send('receiveInvoice', invoiceData))
.catch(error => console.log('invoice error: ', error)) .catch(error => console.log('invoice error: ', error))
break break

12
app/lnd/methods/invoicesController.js

@ -37,13 +37,13 @@ export function listInvoices(lnd) {
* @param {[type]} payreq [description] * @param {[type]} payreq [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function getInvoice(payreq) { export function getInvoice(lnd, { pay_req }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
try { lnd.decodePayReq({ pay_req }, (err, data) => {
resolve(decodeInvoice(payreq)) if (err) { reject(err) }
} catch (error) {
reject(error) resolve(data)
} })
}) })
} }

8
app/reducers/payform.js

@ -97,7 +97,9 @@ payFormSelectors.isOnchain = createSelector(
// TODO: Add more robust logic to detect a LN payment request // TODO: Add more robust logic to detect a LN payment request
payFormSelectors.isLn = createSelector( payFormSelectors.isLn = createSelector(
payInputSelector, payInputSelector,
input => input.length === 124 input => {
return input.startsWith('ln')
}
) )
payFormSelectors.currentAmount = createSelector( payFormSelectors.currentAmount = createSelector(
@ -108,7 +110,7 @@ payFormSelectors.currentAmount = createSelector(
tickerSelectors.currentTicker, tickerSelectors.currentTicker,
(isLn, amount, invoice, currency, ticker) => { (isLn, amount, invoice, currency, ticker) => {
if (isLn) { if (isLn) {
return currency === 'usd' ? btc.satoshisToUsd(invoice.amount, ticker.price_usd) : btc.satoshisToBtc(invoice.amount) return currency === 'usd' ? btc.satoshisToUsd((invoice.num_satoshis || 0), ticker.price_usd) : btc.satoshisToBtc((invoice.num_satoshis || 0))
} }
return amount return amount
@ -118,7 +120,7 @@ payFormSelectors.currentAmount = createSelector(
payFormSelectors.inputCaption = createSelector( payFormSelectors.inputCaption = createSelector(
payFormSelectors.isOnchain, payFormSelectors.isOnchain,
payFormSelectors.isLn, payFormSelectors.isLn,
payAmountSelector, payFormSelectors.currentAmount,
currencySelector, currencySelector,
(isOnchain, isLn, amount, currency) => { (isOnchain, isLn, amount, currency) => {
if (!isOnchain && !isLn) { return '' } if (!isOnchain && !isLn) { return '' }

2
app/routes/app/containers/AppContainer.js

@ -92,7 +92,7 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
} }
if (stateProps.isLn) { if (stateProps.isLn) {
dispatchProps.payInvoice(stateProps.payform.invoice.amount) dispatchProps.payInvoice(stateProps.payform.payInput)
} }
} }
} }

Loading…
Cancel
Save