Add keysend support for Lightning Address

Allow keysend payments to user addresses. Useful for Podcasting 2.0/v4v.
This commit is contained in:
Râu Cao 2023-02-19 17:45:27 +08:00
parent 84337c3a7d
commit c7fe1bc3bc
Signed by: raucao
GPG Key ID: 15E65F399D084BA9
4 changed files with 41 additions and 2 deletions

View File

@ -11,6 +11,7 @@ BTCPAY_API_URL='http://localhost:23001/api/v1'
LNDHUB_API_URL='http://localhost:3023'
LNDHUB_PUBLIC_URL='https://lndhub.kosmos.org'
LNDHUB_PUBLIC_KEY='0123d3be18617f39cf645851e3ba63f51fc13f0bb09e3bb25e6fd4de556486d946'
LNDHUB_ADMIN_UI=true
LNDHUB_PG_HOST=localhost
LNDHUB_PG_PORT=5432

View File

@ -1,4 +1,5 @@
class LnurlpayController < ApplicationController
before_action :check_feature_enabled
before_action :find_user_by_address
MIN_SATS = 10
@ -17,6 +18,20 @@ class LnurlpayController < ApplicationController
}
end
def keysend
http_status :not_found unless Setting.lndhub_keysend_enabled?
render json: {
status: "OK",
tag: "keysend",
pubkey: Setting.lndhub_public_key,
customData: [{
customKey: "696969",
customValue: @user.ln_account
}]
}
end
def invoice
amount = params[:amount].to_i / 1000 # msats
address = params[:address]
@ -72,4 +87,9 @@ class LnurlpayController < ApplicationController
comment.length <= MAX_COMMENT_CHARS
end
private
def check_feature_enabled
http_status :not_found if !Setting.lndhub_enabled?
end
end

View File

@ -2,10 +2,27 @@
class Setting < RailsSettings::Base
cache_prefix { "v1" }
#
# Registrations
#
field :reserved_usernames, type: :array, default: %w[
account accounts admin donations mail webmaster support
]
field :lndhub_enabled, default: (ENV["LNDHUB_API_URL"].present?.to_s || "false"), type: :boolean
field :lndhub_admin_enabled, default: (ENV["LNDHUB_ADMIN_UI"] || "false"), type: :boolean
#
# Lightning Network
#
field :lndhub_enabled, type: :boolean,
default: (ENV["LNDHUB_API_URL"].present?.to_s || false)
field :lndhub_admin_enabled, type: :boolean,
default: (ENV["LNDHUB_ADMIN_UI"] || false)
field :lndhub_public_key, type: :string,
default: (ENV["LNDHUB_PUBLIC_KEY"] || "")
field :lndhub_keysend_enabled, type: :boolean,
default: -> { self.lndhub_public_key.present?.to_s || false }
end

View File

@ -30,6 +30,7 @@ Rails.application.routes.draw do
get 'lnurlpay/:address', to: 'lnurlpay#index', constraints: { address: /[^\/]+/}
get 'lnurlpay/:address/invoice', to: 'lnurlpay#invoice', constraints: { address: /[^\/]+/}
get 'keysend/:address', to: 'lnurlpay#keysend', constraints: { address: /[^\/]+/}
post 'webhooks/lndhub', to: 'webhooks#lndhub'