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"];
bytes hash_lock = 3 [json_name = "hash_lock"];
uint32 expiration_height = 4 [json_name = "expiration_height"];
uint32 revocation_delay = 5 [json_name = "revocation_delay"];
}
message ActiveChannel {
@ -1129,7 +1128,12 @@ message SetAliasResponse {
}
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"];
/// An optional cryptographic receipt of payment
@ -1162,6 +1166,19 @@ message Invoice {
payment to the recipient.
*/
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 {
bytes r_hash = 1 [json_name = "r_hash"];
@ -1241,6 +1258,11 @@ message PayReq {
string destination = 1 [json_name = "destination"];
string payment_hash = 2 [json_name = "payment_hash"];
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 {}

2
app/lnd/methods/index.js

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

12
app/lnd/methods/invoicesController.js

@ -37,13 +37,13 @@ export function listInvoices(lnd) {
* @param {[type]} payreq [description]
* @return {[type]} [description]
*/
export function getInvoice(payreq) {
export function getInvoice(lnd, { pay_req }) {
return new Promise((resolve, reject) => {
try {
resolve(decodeInvoice(payreq))
} catch (error) {
reject(error)
}
lnd.decodePayReq({ pay_req }, (err, data) => {
if (err) { reject(err) }
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
payFormSelectors.isLn = createSelector(
payInputSelector,
input => input.length === 124
input => {
return input.startsWith('ln')
}
)
payFormSelectors.currentAmount = createSelector(
@ -108,7 +110,7 @@ payFormSelectors.currentAmount = createSelector(
tickerSelectors.currentTicker,
(isLn, amount, invoice, currency, ticker) => {
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
@ -118,7 +120,7 @@ payFormSelectors.currentAmount = createSelector(
payFormSelectors.inputCaption = createSelector(
payFormSelectors.isOnchain,
payFormSelectors.isLn,
payAmountSelector,
payFormSelectors.currentAmount,
currencySelector,
(isOnchain, isLn, amount, currency) => {
if (!isOnchain && !isLn) { return '' }

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

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

Loading…
Cancel
Save