akkounts/lib/tasks/lndhub.rake
Sebastian Kippe 2a2793ae44
All checks were successful
continuous-integration/drone/pr Build is passing
Print sum of user balances
2022-04-12 16:05:46 +02:00

25 lines
672 B
Ruby

namespace :lndhub do
desc "Generate wallets for all users"
task :generate_wallets => :environment do |t, args|
User.all.each do |user|
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