Allow comments for LNURL-PAY invoices #65

Merged
raucao merged 3 commits from feature/lnurlp_memos into master 2022-03-02 14:13:40 +00:00
2 changed files with 16 additions and 3 deletions
Showing only changes of commit 4c51b9c966 - Show all commits

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,29 @@ 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
payment_request = @user.ln_create_invoice({
amount: amount, # we create invoices in sats
description_hash: Digest::SHA2.hexdigest(metadata(address))
description_hash: Digest::SHA2.hexdigest(metadata(address)),
memo: comment
})
render json: {
@ -57,4 +65,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,7 +49,8 @@ class Lndhub
def addinvoice(payload)
invoice = post "addinvoice", {
amt: payload[:amount],
description_hash: payload[:description_hash]
description_hash: payload[:description_hash],
memo: payload[:memo]
}
invoice["payment_request"]