Class: Lnrpc::Client
- Inherits:
-
Object
- Object
- Lnrpc::Client
- 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
-
#address ⇒ Object
Returns the value of attribute address.
-
#credentials ⇒ Object
Returns the value of attribute credentials.
-
#macaroon ⇒ Object
Returns the value of attribute macaroon.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
- #keysend(args) ⇒ Object
- #lightning ⇒ Object
- #pay(args) ⇒ Object
- #router ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/lnrpc/client.rb', line 12 def initialize(={}) self.address = [:address] || DEFAULT_ADDRESS if .has_key?(:credentials) self.credentials = [:credentials] elsif File.exists?(::File.([:credentials_path] || DEFAULT_CREDENTIALS_PATH)) self.credentials = ::File.read(::File.([:credentials_path] || DEFAULT_CREDENTIALS_PATH)) else self.credentials = nil end if !.has_key?(:macaroon) && File.exists?(::File.([:macaroon_path] || DEFAULT_MACAROON_PATH)) [:macaroon] = ::File.read(::File.([:macaroon_path] || DEFAULT_MACAROON_PATH)).unpack("H*") end self.macaroon = [:macaroon] end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
5 6 7 |
# File 'lib/lnrpc/client.rb', line 5 def address @address end |
#credentials ⇒ Object
Returns the value of attribute credentials.
5 6 7 |
# File 'lib/lnrpc/client.rb', line 5 def credentials @credentials end |
#macaroon ⇒ Object
Returns the value of attribute macaroon.
5 6 7 |
# File 'lib/lnrpc/client.rb', line 5 def macaroon @macaroon end |
Instance Method Details
#inspect ⇒ Object
56 57 58 |
# File 'lib/lnrpc/client.rb', line 56 def inspect "#{self.to_s} @address=\"#{self.address}\"" end |
#keysend(args) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/lnrpc/client.rb', line 43 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 ⇒ Object
29 30 31 32 33 34 |
# File 'lib/lnrpc/client.rb', line 29 def lightning @lightning ||= GrpcWrapper.new(Lnrpc::Lightning::Stub.new(address, GRPC::Core::ChannelCredentials.new(credentials), interceptors: [Lnrpc::MacaroonInterceptor.new(macaroon)] )) end |
#pay(args) ⇒ Object
51 52 53 54 |
# File 'lib/lnrpc/client.rb', line 51 def pay(args) args[:timeout_seconds] ||= 60 router.send_payment_v2(args) end |
#router ⇒ Object
36 37 38 39 40 41 |
# File 'lib/lnrpc/client.rb', line 36 def router @router ||= GrpcWrapper.new(Routerrpc::Router::Stub.new(address, GRPC::Core::ChannelCredentials.new(credentials), interceptors: [Lnrpc::MacaroonInterceptor.new(macaroon)] )) end |