class Lnrpc::Client

Constants

DEFAULT_ADDRESS
DEFAULT_CREDENTIALS_PATH
DEFAULT_MACAROON_PATH
LND_HOME_DIR

Attributes

address[RW]
credentials[RW]
macaroon[RW]

Public Class Methods

new(options={}) click to toggle source
# File lib/lnrpc/client.rb, line 12
def initialize(options={})
  self.address = options[:address] || DEFAULT_ADDRESS

  if options.has_key?(:credentials)
    # if there are non hex values prvided we assume it's the certificate file as string otherwise we assume it's the hex value
    self.credentials = options[:credentials].match?(/\H/) ? options[:credentials] : [options[:credentials]].pack('H*')
  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

  if !options.has_key?(:macaroon) && File.exists?(::File.expand_path(options[:macaroon_path] || DEFAULT_MACAROON_PATH))
    options[:macaroon] = ::File.read(::File.expand_path(options[:macaroon_path] || DEFAULT_MACAROON_PATH)).unpack("H*")
  end
  self.macaroon = options[:macaroon]
end

Public Instance Methods

autopilot() click to toggle source
# File lib/lnrpc/client.rb, line 34
def autopilot
  @autopilot ||= grpc_wrapper_for(Autopilotrpc::Autopilot)
end
chain_notifier() click to toggle source
# File lib/lnrpc/client.rb, line 38
def chain_notifier
  @chain_notifier ||= grpc_wrapper_for(Chainrpc::ChainNotifier)
end
inspect() click to toggle source
# File lib/lnrpc/client.rb, line 87
def inspect
  "#{self} @address=\"#{address}\""
end
invoices() click to toggle source
# File lib/lnrpc/client.rb, line 42
def invoices
  @invoices ||= grpc_wrapper_for(Invoicesrpc::Invoices)
end
keysend(args) click to toggle source
# File lib/lnrpc/client.rb, line 74
def keysend(args)
  args[:dest_custom_records] ||= {}
  args[:dest_custom_records][Lnrpc::KEY_SEND_PREIMAGE_TYPE] ||= Lnrpc.create_preimage
  args[:payment_hash] ||= Digest::SHA256.digest(args[:dest_custom_records][Lnrpc::KEY_SEND_PREIMAGE_TYPE])
  args[:timeout_seconds] ||= 60
  router.send_payment_v2(args)
end
lightning() click to toggle source
# File lib/lnrpc/client.rb, line 30
def lightning
  @lightning ||= grpc_wrapper_for(Lnrpc::Lightning)
end
pay(args) click to toggle source
# File lib/lnrpc/client.rb, line 82
def pay(args)
  args[:timeout_seconds] ||= 60
  router.send_payment_v2(args)
end
router() click to toggle source
# File lib/lnrpc/client.rb, line 46
def router
  @router ||= grpc_wrapper_for(Routerrpc::Router)
end
signer() click to toggle source
# File lib/lnrpc/client.rb, line 50
def signer
  @signer ||= grpc_wrapper_for(Signrpc::Signer)
end
versioner() click to toggle source
# File lib/lnrpc/client.rb, line 54
def versioner
  @versioner ||= grpc_wrapper_for(Verrpc::Versioner)
end
wallet_kit() click to toggle source
# File lib/lnrpc/client.rb, line 58
def wallet_kit
  @wallet_kit ||= grpc_wrapper_for(Walletrpc::WalletKit)
end
wallet_unlocker() click to toggle source
# File lib/lnrpc/client.rb, line 62
def wallet_unlocker
  @wallet_unlocker ||= grpc_wrapper_for(Lnrpc::WalletUnlocker)
end
watchtower() click to toggle source
# File lib/lnrpc/client.rb, line 66
def watchtower
  @watchtower ||= grpc_wrapper_for(Watchtowerrpc::Watchtower)
end
watchtower_client() click to toggle source
# File lib/lnrpc/client.rb, line 70
def watchtower_client
  @watchtower_client ||= grpc_wrapper_for(Wtclientrpc::WatchtowerClient)
end

Private Instance Methods

grpc_wrapper_for(grpc_module) click to toggle source
# File lib/lnrpc/client.rb, line 93
def grpc_wrapper_for(grpc_module)
  stub = grpc_module.const_get(:Stub)
  service = grpc_module.const_get(:Service)
  GrpcWrapper.new(service: service,
                  grpc: stub.new(address,
                            GRPC::Core::ChannelCredentials.new(credentials),
                            interceptors: [Lnrpc::MacaroonInterceptor.new(macaroon)]
                          ))
end