bumi
39f97e69ca
...so much to learn :) |
||
---|---|---|
bin | ||
lib | ||
spec | ||
.gitignore | ||
.rspec | ||
Gemfile | ||
Gemfile.lock | ||
LICENSE.txt | ||
README.md | ||
Rakefile | ||
examples.rb | ||
lnrpc.gemspec |
README.md
Lnrpc - ruby gRPC client for LND
a gRPC client for LND, the Lightning Network Daemon packed as ruby gem.
Installation
Add this line to your application's Gemfile:
gem 'lnrpc'
And then execute:
$ bundle
Or install it yourself as:
$ gem install lnrpc
Usage
This gem makes the gRPC client classes created from the LND service defintions available.
require "lnrpc"
# the gRPC client is available under the Lnrpc namespace, e.g.
Lnrpc::Lightning::Stub
Lnrpc::GetInfoRequest
Learn more about gRPC on gRPC.io.
The LND API reference can be found here: https://api.lightning.community/
Example
require "lnrpc"
credentials = File.read("/path/to/tls.cert")
macaroon = File.read("/path/to/readonly.macaroon").unpack("H*")
# initialize a new client
client = Lnrpc::Lightning::Stub.new("localhost:10009", GRPC::Core::ChannelCredentials.new(self.credentials))
# perform a request
request = Lnrpc::GetInfoRequest.new
response = client.get_info(request, { metadata: { macaroon: macaroon } }) #=> Lnrpc::GetInfoResponse
puts response.alias
Client wrapper
An optional client wrapper (Lnrpc::Client) makes initializing the gRPC client easier and removes the need for some boilerplate code for calling RPC methods.
Example
lnd = Lnrpc::Client.new({credentials_path: '/path/to.cert.cls', macaroon_path: '/path/to/admin.macaroon'})
lnd.get_info
Also have a look at examples.rb
Initializing a new client
The Lnrpc::Client constructor allows the following options:
- credentials:
credentials
: the credentials data as stringcredentials_path
: the path to a credentials file (tls.cert) as string
- macaroon:
macaroon
: the macaroon as hex stringmacaroon_path
: the path to the macaroon file created by lnd as string
- address:
address
: lnd address as string. format: address:port, e.g. default: localhost:10009
require 'lnrpc'
lnd = Lnrpc::Client.new({
credentials_path: '/path/to.cert.cls',
macaroon_path: '/path/to/admin.macaroon',
address: 'host:port'
})
# the actual gRPC client is available through:
lnd.grpc_client
Calling RPC methods
The client wrapper passes any supported RPC method call to the gRPC client applying the following conventions:
If the first parameter is a hash or blank the corresponding gRPC request object will be instantiated.
Example:
client.get_info
# is the same as:
client.grpc_client.get_info(Lnrpc::GetInfoRequest.new)
client.list_channels(inactive_only: true)
# is the same as:
request = Lnrpc::ListChannelsRequest.new(inactive_only: true)
client.grpc_client.list_channels(request)
client.wallet_balance.total_balance
# is the same as:
request = Lnrpc::WalletBalanceRequest.new()
client.grpc_client.wallet_balance(request).total_balance
Versioning
This gem follows the LND versions and will update the gRPC service definitions accordingly. e.g. gem version 0.5.2 includes the gRPC service definitions from LND v0.5.2
Other resources
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/bumi/lnrpc.
License
The gem is available as open source under the terms of the MIT License.