Compare commits
13 Commits
v0.4.0
...
caea2d0121
| Author | SHA1 | Date | |
|---|---|---|---|
|
caea2d0121
|
|||
|
e1ff5c479e
|
|||
|
9b3386de30
|
|||
|
f2287c1186
|
|||
| b29197cf4e | |||
|
5c48055ac8
|
|||
|
5ead3476b7
|
|||
| fbf163740a | |||
|
|
1fc1457e97 | ||
| 1f57bbd9c2 | |||
|
2a2793ae44
|
|||
|
8773bf5f9e
|
|||
|
d9970c126a
|
@@ -1,3 +1,4 @@
|
||||
EJABBERD_API_URL='https://xmpp.kosmos.org/api'
|
||||
BTCPAY_API_URL='http://localhost:23001'
|
||||
LNDHUB_API_URL='http://localhost:3023'
|
||||
LNDHUB_PUBLIC_URL='https://lndhub.kosmos.org'
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
EJABBERD_API_URL='https://xmpp.kosmos.org:5443/api'
|
||||
BTCPAY_API_URL='http://10.1.1.163:23001'
|
||||
LNDHUB_API_URL='http://10.1.1.163:3023'
|
||||
LNDHUB_PUBLIC_URL='https://lndhub.kosmos.org'
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
EJABBERD_API_URL='http://xmpp.example.com/api'
|
||||
BTCPAY_API_URL='http://btcpay.example.com'
|
||||
LNDHUB_API_URL='http://localhost:3023'
|
||||
LNDHUB_PUBLIC_URL='https://lndhub.kosmos.org'
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
@layer base {
|
||||
html {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
body {
|
||||
@apply leading-none bg-cover bg-fixed;
|
||||
background-image: linear-gradient(35deg, rgba(255,0,255,0.2) 0, rgba(13,79,153,0.8) 100%), url('/img/bg-1.jpg');
|
||||
|
||||
5
app/controllers/api/base_controller.rb
Normal file
5
app/controllers/api/base_controller.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class Api::BaseController < ApplicationController
|
||||
|
||||
layout false
|
||||
|
||||
end
|
||||
12
app/controllers/api/kredits_controller.rb
Normal file
12
app/controllers/api/kredits_controller.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
class Api::KreditsController < Api::BaseController
|
||||
|
||||
def onchain_btc_balance
|
||||
btcpay = BtcPay.new
|
||||
balance = btcpay.onchain_wallet_balance
|
||||
render json: balance
|
||||
rescue
|
||||
render json: { error: 'Failed to fetch wallet balance' },
|
||||
status: 500
|
||||
end
|
||||
|
||||
end
|
||||
32
app/services/btc_pay.rb
Normal file
32
app/services/btc_pay.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
#
|
||||
# API Docs: https://docs.btcpayserver.org/API/Greenfield/v1/
|
||||
#
|
||||
class BtcPay
|
||||
def initialize
|
||||
@base_url = "#{ENV["BTCPAY_API_URL"]}/api/v1"
|
||||
@store_id = Rails.application.credentials.btcpay[:store_id]
|
||||
@auth_token = Rails.application.credentials.btcpay[:auth_token]
|
||||
end
|
||||
|
||||
def onchain_wallet_balance
|
||||
res = get "stores/#{@store_id}/payment-methods/onchain/BTC/wallet"
|
||||
|
||||
{
|
||||
balance: res["balance"].to_f,
|
||||
unconfirmed_balance: res["unconfirmedBalance"].to_f,
|
||||
confirmed_balance: res["confirmedBalance"].to_f
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get(endpoint)
|
||||
res = Faraday.get("#{@base_url}/#{endpoint}", {}, {
|
||||
"Content-Type" => "application/json",
|
||||
"Accept" => "application/json",
|
||||
"Authorization" => "token #{@auth_token}"
|
||||
})
|
||||
|
||||
JSON.parse(res.body)
|
||||
end
|
||||
end
|
||||
@@ -25,7 +25,7 @@
|
||||
</div>
|
||||
<div>
|
||||
<h3 class="mb-3.5">
|
||||
<span class="text-yellow-500">🗲</span>
|
||||
<%= render partial: "icons/zap", locals: { custom_class: "text-amber-500 h-4 w-4 inline" } %>
|
||||
<%= link_to "Lightning Wallet", wallet_path, class: "ks-text-link" %>
|
||||
</h3>
|
||||
<p class="text-gray-500">
|
||||
|
||||
@@ -1 +1 @@
|
||||
PRI1laGy6XiLpsII0ixFOTCpzz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|
||||
IIjYiPSeZeMFhH8i8v8akXN4JrtGU+OsMQ8GAao/gVdesggriCBAQ8z+Vd0cmTf1SKYeT3OQDgygEekupr325P4eD9fZ+yi56EA/UMXQXMDVZAvZw7iwvKaOXpqisbWdJnomr1GXrHyR415Ce/Fxft3fgXDwMHJW2u+dDJgpE09uORnB9GXycFwHQmoIdXo=--iQ/Vcm0VcwHgUkwQ--tKHQW/45gM/s/NplqGPaxw==
|
||||
@@ -46,11 +46,11 @@ test:
|
||||
# <<: *AUTHORIZATIONS
|
||||
|
||||
production:
|
||||
host: ldap.kosmos.org
|
||||
port: 636
|
||||
host: ldap.kosmos.local
|
||||
port: 389
|
||||
attribute: cn
|
||||
base: ou=kosmos.org,cn=users,dc=kosmos,dc=org
|
||||
admin_user: <%= Rails.application.credentials.ldap[:username] rescue nil %>
|
||||
admin_password: <%= Rails.application.credentials.ldap[:password] rescue nil %>
|
||||
ssl: simple_tls
|
||||
# ssl: false
|
||||
# <<: *AUTHORIZATIONS
|
||||
|
||||
@@ -25,6 +25,10 @@ Rails.application.routes.draw do
|
||||
get 'lnurlpay/:address', to: 'lnurlpay#index', constraints: { address: /[^\/]+/}
|
||||
get 'lnurlpay/:address/invoice', to: 'lnurlpay#invoice', constraints: { address: /[^\/]+/}
|
||||
|
||||
namespace :api do
|
||||
get 'kredits/onchain_btc_balance', to: 'kredits#onchain_btc_balance'
|
||||
end
|
||||
|
||||
namespace :admin do
|
||||
root to: 'dashboard#index'
|
||||
get 'invitations', to: 'invitations#index'
|
||||
|
||||
@@ -5,4 +5,20 @@ namespace :lndhub do
|
||||
CreateLndhubWalletJob.perform_later(user)
|
||||
end
|
||||
end
|
||||
|
||||
desc "List wallet balances"
|
||||
task :balances => :environment do |t, args|
|
||||
sum = 0
|
||||
User.all.each do |user|
|
||||
lndhub = Lndhub.new
|
||||
auth_token = lndhub.authenticate(user)
|
||||
data = lndhub.balance(auth_token)
|
||||
balance = data["BTC"]["AvailableBalance"] rescue nil
|
||||
if balance && balance > 0
|
||||
sum += balance
|
||||
puts "#{user.address}: #{balance} sats"
|
||||
end
|
||||
end
|
||||
puts "--\nSum of user balances: #{sum} sats"
|
||||
end
|
||||
end
|
||||
|
||||
43
spec/requests/api/kredits_spec.rb
Normal file
43
spec/requests/api/kredits_spec.rb
Normal file
@@ -0,0 +1,43 @@
|
||||
require 'rails_helper'
|
||||
require 'webmock/rspec'
|
||||
|
||||
RSpec.describe "/api/kredits", type: :request do
|
||||
|
||||
describe "GET /onchain_btc_balance" do
|
||||
before do
|
||||
stub_request(:get, "http://btcpay.example.com/api/v1/stores/123456/payment-methods/onchain/BTC/wallet")
|
||||
.to_return(status: 200, headers: {}, body: {
|
||||
balance: 0.91108606,
|
||||
unconfirmedBalance: 0,
|
||||
confirmedBalance: 0.91108606
|
||||
}.to_json)
|
||||
end
|
||||
|
||||
it "returns a formatted result for the onchain wallet balance" do
|
||||
get api_kredits_onchain_btc_balance_path
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
|
||||
res = JSON.parse(response.body)
|
||||
expect(res["balance"]).to eq(0.91108606)
|
||||
expect(res["unconfirmed_balance"]).to eq(0)
|
||||
expect(res["confirmed_balance"]).to eq(0.91108606)
|
||||
end
|
||||
|
||||
context "upstream request error" do
|
||||
before do
|
||||
stub_request(:get, "http://btcpay.example.com/api/v1/stores/123456/payment-methods/onchain/BTC/wallet")
|
||||
.to_return(status: 500, headers: {}, body: "")
|
||||
end
|
||||
|
||||
it "returns a formatted error" do
|
||||
get api_kredits_onchain_btc_balance_path
|
||||
|
||||
expect(response).to have_http_status(:server_error)
|
||||
|
||||
res = JSON.parse(response.body)
|
||||
expect(res["error"]).not_to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user