mirror of
https://github.com/bumi/lnrpc
synced 2025-08-05 15:36:52 +00:00
Merge pull request #5 from bumi/support-for-system-certs
Add support for system/default certs/credentials
This commit is contained in:
commit
cee1f7589c
@ -75,7 +75,7 @@ Also have a look at [examples.rb](https://github.com/bumi/lnrpc/blob/master/exam
|
|||||||
The Lnrpc::Client constructor allows the following options:
|
The Lnrpc::Client constructor allows the following options:
|
||||||
|
|
||||||
* credentials:
|
* credentials:
|
||||||
- `credentials` : the credentials data as string
|
- `credentials` : the credentials data as string (pass nil if a "trusted" cert (e.g. from letsencrypt is used)
|
||||||
- `credentials_path` : the path to a credentials file (tls.cert) as string (default: `"#{LND_HOME_DIR}/tls.cert"` )
|
- `credentials_path` : the path to a credentials file (tls.cert) as string (default: `"#{LND_HOME_DIR}/tls.cert"` )
|
||||||
* macaroon:
|
* macaroon:
|
||||||
- `macaroon` : the macaroon as hex string
|
- `macaroon` : the macaroon as hex string
|
||||||
|
@ -2,7 +2,8 @@ require "grpc"
|
|||||||
require "lnrpc/macaroon_interceptor"
|
require "lnrpc/macaroon_interceptor"
|
||||||
module Lnrpc
|
module Lnrpc
|
||||||
class Client
|
class Client
|
||||||
attr_accessor :address, :credentials, :macaroon, :grpc_client
|
attr_accessor :address, :credentials, :macaroon
|
||||||
|
attr_writer :grpc_client
|
||||||
|
|
||||||
LND_HOME_DIR = ENV['LND_HOME'] || "~/.lnd"
|
LND_HOME_DIR = ENV['LND_HOME'] || "~/.lnd"
|
||||||
DEFAULT_ADDRESS = 'localhost:10009'
|
DEFAULT_ADDRESS = 'localhost:10009'
|
||||||
@ -31,19 +32,25 @@ module Lnrpc
|
|||||||
def initialize(options={})
|
def initialize(options={})
|
||||||
self.address = options[:address] || DEFAULT_ADDRESS
|
self.address = options[:address] || DEFAULT_ADDRESS
|
||||||
|
|
||||||
options[:credentials] ||= ::File.read(::File.expand_path(options[:credentials_path] || DEFAULT_CREDENTIALS_PATH))
|
if options.has_key?(:credentials)
|
||||||
self.credentials = options[:credentials]
|
self.credentials = options[:credentials]
|
||||||
|
elsif File.exists?(::File.expand_path(options[:credentials_path] || DEFAULT_CREDENTIALS_PATH))
|
||||||
|
self.credentials = ::File.read(::File.expand_path(options[:credentials_path] || DEFAULT_CREDENTIALS_PATH))
|
||||||
|
else
|
||||||
|
self.credentials = nil
|
||||||
|
end
|
||||||
|
|
||||||
options[:macaroon] ||= begin
|
unless options.has_key?(:macaroon)
|
||||||
macaroon_binary = ::File.read(::File.expand_path(options[:macaroon_path] || DEFAULT_MACAROON_PATH))
|
options[:macaroon] = ::File.read(::File.expand_path(options[:macaroon_path] || DEFAULT_MACAROON_PATH)).unpack("H*")
|
||||||
macaroon_binary.unpack("H*")
|
|
||||||
end
|
end
|
||||||
self.macaroon = options[:macaroon]
|
self.macaroon = options[:macaroon]
|
||||||
|
end
|
||||||
|
|
||||||
self.grpc_client = Lnrpc::Lightning::Stub.new(self.address,
|
def grpc_client
|
||||||
|
@grpc_client ||= Lnrpc::Lightning::Stub.new(self.address,
|
||||||
GRPC::Core::ChannelCredentials.new(self.credentials),
|
GRPC::Core::ChannelCredentials.new(self.credentials),
|
||||||
interceptors: [Lnrpc::MacaroonInterceptor.new(self.macaroon)]
|
interceptors: [Lnrpc::MacaroonInterceptor.new(self.macaroon)]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pay(payreq)
|
def pay(payreq)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user