Class: Lnrpc::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/lnrpc/client.rb

Constant Summary collapse

LND_HOME_DIR =
ENV['LND_HOME'] || "~/.lnd"
DEFAULT_ADDRESS =
'localhost:10009'
DEFAULT_CREDENTIALS_PATH =
"#{LND_HOME_DIR}/tls.cert"
DEFAULT_MACAROON_PATH =
"#{LND_HOME_DIR}/data/chain/bitcoin/mainnet/admin.macaroon"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lnrpc/client.rb', line 13

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

Instance Attribute Details

#addressObject

Returns the value of attribute address.



6
7
8
# File 'lib/lnrpc/client.rb', line 6

def address
  @address
end

#credentialsObject

Returns the value of attribute credentials.



6
7
8
# File 'lib/lnrpc/client.rb', line 6

def credentials
  @credentials
end

#macaroonObject

Returns the value of attribute macaroon.



6
7
8
# File 'lib/lnrpc/client.rb', line 6

def macaroon
  @macaroon
end

Instance Method Details

#autopilotObject



35
36
37
# File 'lib/lnrpc/client.rb', line 35

def autopilot
  @autopilot ||= grpc_wrapper_for(Autopilotrpc::Autopilot)
end

#chain_notifierObject



39
40
41
# File 'lib/lnrpc/client.rb', line 39

def chain_notifier
  @chain_notifier ||= grpc_wrapper_for(Chainrpc::ChainNotifier)
end

#inspectObject



88
89
90
# File 'lib/lnrpc/client.rb', line 88

def inspect
  "#{self} @address=\"#{address}\""
end

#invoicesObject



43
44
45
# File 'lib/lnrpc/client.rb', line 43

def invoices
  @invoices ||= grpc_wrapper_for(Invoicesrpc::Invoices)
end

#keysend(args) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/lnrpc/client.rb', line 75

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

#lightningObject



31
32
33
# File 'lib/lnrpc/client.rb', line 31

def lightning
  @lightning ||= grpc_wrapper_for(Lnrpc::Lightning)
end

#pay(args) ⇒ Object



83
84
85
86
# File 'lib/lnrpc/client.rb', line 83

def pay(args)
  args[:timeout_seconds] ||= 60
  router.send_payment_v2(args)
end

#routerObject



47
48
49
# File 'lib/lnrpc/client.rb', line 47

def router
  @router ||= grpc_wrapper_for(Routerrpc::Router)
end

#signerObject



51
52
53
# File 'lib/lnrpc/client.rb', line 51

def signer
  @signer ||= grpc_wrapper_for(Signrpc::Signer)
end

#versionerObject



55
56
57
# File 'lib/lnrpc/client.rb', line 55

def versioner
  @versioner ||= grpc_wrapper_for(Verrpc::Versioner)
end

#wallet_kitObject



59
60
61
# File 'lib/lnrpc/client.rb', line 59

def wallet_kit
  @wallet_kit ||= grpc_wrapper_for(Walletrpc::WalletKit)
end

#wallet_unlockerObject



63
64
65
# File 'lib/lnrpc/client.rb', line 63

def wallet_unlocker
  @wallet_unlocker ||= grpc_wrapper_for(Lnrpc::WalletUnlocker)
end

#watchtowerObject



67
68
69
# File 'lib/lnrpc/client.rb', line 67

def watchtower
  @watchtower ||= grpc_wrapper_for(Watchtowerrpc::Watchtower)
end

#watchtower_clientObject



71
72
73
# File 'lib/lnrpc/client.rb', line 71

def watchtower_client
  @watchtower_client ||= grpc_wrapper_for(Wtclientrpc::WatchtowerClient)
end