1
0
mirror of https://github.com/bumi/rack-lightning synced 2026-02-25 12:20:51 +00:00

Support easier config loading from variables

This makes it easier to load credentials and macaroon options from a
(environment) variable instead of a file.
This commit is contained in:
2018-11-21 21:00:10 +01:00
parent b8f6a848cc
commit 0b9fe9179d
2 changed files with 23 additions and 2 deletions

View File

@@ -14,8 +14,10 @@ module Rack
@options[:address] ||= 'localhost:10009'
@options[:timeout] ||= 5
@options[:credentials] ||= ::File.read(::File.expand_path(@options[:credentials_path] || "~/.lnd/tls.cert"))
macaroon_binary ||= ::File.read(::File.expand_path(@options[:macaroon_path] || "~/.lnd/data/chain/bitcoin/testnet/admin.macaroon"))
@options[:macaroon] = macaroon_binary.each_byte.map { |b| b.to_s(16).rjust(2,'0') }.join
@options[:macaroon] ||= begin
macaroon_binary = ::File.read(::File.expand_path(@options[:macaroon_path] || "~/.lnd/data/chain/bitcoin/testnet/admin.macaroon"))
macaroon_binary.each_byte.map { |b| b.to_s(16).rjust(2,'0') }.join
end
@lnd_client = Lnrpc::Lightning::Stub.new(@options[:address], GRPC::Core::ChannelCredentials.new(@options[:credentials]))
end