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"
- NON_CONVENTION_REQUEST_CLASSES =
{ add_invoice: Lnrpc::Invoice, send_payment: Lnrpc::SendRequest, send_payment_sync: Lnrpc::SendRequest, open_channel_sync: Lnrpc::OpenChannelRequest, send_to_route_sync: Lnrpc::SendToRouteRequest, lookup_invoice: Lnrpc::PaymentHash, decode_pay_req: Lnrpc::PayReqString, describe_graph: Lnrpc::ChannelGraphRequest, get_chan_info: Lnrpc::ChanInfoRequest, get_node_info: Lnrpc::NodeInfoRequest, get_network_info: Lnrpc::NetworkInfoRequest, stop_daemon: Lnrpc::StopRequest, update_channel_policy: Lnrpc::PolicyUpdateResponse, subscribe_channel_graph: Lnrpc::GraphTopologySubscription, subscribe_invoices: Lnrpc::InvoiceSubscription, subscribe_transactions: Lnrpc::GetTransactionsRequest }
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#credentials ⇒ Object
Returns the value of attribute credentials.
- #grpc_client ⇒ Object
-
#macaroon ⇒ Object
Returns the value of attribute macaroon.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
- #method_missing(m, *args, &block) ⇒ Object
- #pay(payreq) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/lnrpc/client.rb', line 32 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/lnrpc/client.rb', line 60 def method_missing(m, *args, &block) if self.grpc_client.respond_to?(m) params = args[0] args[0] = params.nil? ? request_class_for(m).new : request_class_for(m).new(params) self.grpc_client.send(m, *args, &block) else super end 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 |
#grpc_client ⇒ Object
49 50 51 52 53 54 |
# File 'lib/lnrpc/client.rb', line 49 def grpc_client @grpc_client ||= Lnrpc::Lightning::Stub.new(self.address, GRPC::Core::ChannelCredentials.new(self.credentials), interceptors: [Lnrpc::MacaroonInterceptor.new(self.macaroon)] ) 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
71 72 73 |
# File 'lib/lnrpc/client.rb', line 71 def inspect "#{self.to_s} @address=\"#{self.address}\"" end |
#pay(payreq) ⇒ Object
56 57 58 |
# File 'lib/lnrpc/client.rb', line 56 def pay(payreq) self.send_payment_sync(Lnrpc::SendRequest.new(payment_request: payreq)) end |