diff --git a/.env.example b/.env.example index c63d0bb..48b0fec 100644 --- a/.env.example +++ b/.env.example @@ -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 diff --git a/app/controllers/lnurlpay_controller.rb b/app/controllers/lnurlpay_controller.rb index b1326b1..f880151 100644 --- a/app/controllers/lnurlpay_controller.rb +++ b/app/controllers/lnurlpay_controller.rb @@ -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 diff --git a/app/models/setting.rb b/app/models/setting.rb index fb4dae5..d85b82e 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 7559393..fd8a40d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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'