Merge pull request 'Allow comments for LNURL-PAY invoices' (#65) from feature/lnurlp_memos into master
All checks were successful
continuous-integration/drone/push Build is passing

Reviewed-on: #65
This commit is contained in:
Râu Cao 2022-03-02 14:13:40 +00:00
commit 83e4dfa18f
2 changed files with 18 additions and 2 deletions

View File

@ -3,6 +3,7 @@ class LnurlpayController < ApplicationController
MIN_SATS = 100
MAX_SATS = 1_000_000
MAX_COMMENT_CHARS = 100
def index
render json: {
@ -12,22 +13,32 @@ class LnurlpayController < ApplicationController
maxSendable: MAX_SATS * 1000, # msat
minSendable: MIN_SATS * 1000, # msat
metadata: metadata(@user.address),
commentAllowed: 0
commentAllowed: MAX_COMMENT_CHARS
}
end
def invoice
amount = params[:amount].to_i / 1000 # msats
address = params[:address]
comment = params[:comment] || ""
if !valid_amount?(amount)
render json: { status: "ERROR", reason: "Invalid amount" }
return
end
if !valid_comment?(comment)
render json: { status: "ERROR", reason: "Comment too long" }
return
end
memo = "Sats for #{address}"
memo = "#{memo}: \"#{comment}\"" if comment.present?
payment_request = @user.ln_create_invoice({
amount: amount, # we create invoices in sats
description_hash: Digest::SHA2.hexdigest(metadata(address))
memo: memo,
description_hash: Digest::SHA2.hexdigest(metadata(address)),
})
render json: {
@ -57,4 +68,8 @@ class LnurlpayController < ApplicationController
amount_in_sats <= MAX_SATS && amount_in_sats >= MIN_SATS
end
def valid_comment?(comment)
comment.length <= MAX_COMMENT_CHARS
end
end

View File

@ -49,6 +49,7 @@ class Lndhub
def addinvoice(payload)
invoice = post "addinvoice", {
amt: payload[:amount],
memo: payload[:memo],
description_hash: payload[:description_hash]
}