hodl-lightning 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3ec9c94356d8295384e200f5f75c3f6e31ecf3b51947eda2605553d469581112
4
+ data.tar.gz: 9ad2917008b21343a4249881f331a1b9a85a1da2160c73dd46885ecdf40ccd7a
5
+ SHA512:
6
+ metadata.gz: e5707f0604d4ebe373793603ad65613b04785e936f128529472f602ca7a40bab0101c22d18181a3aa95dd09c24a6b381f6a5f0cc07501113f45e5b0a0082e7ee
7
+ data.tar.gz: 67504ba53627539c89d76914575b995c4b65ebc5ad117d1902528cde20e35e88178ae8ce842ab0664833f0124ab8b88ee1fdaa9f6ea4f893aee75fb04b363455
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .rspec_status
10
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
6
+
7
+ gem 'hodl-lnd_grpc', '0.2.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,94 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hodl-lightning (0.2.0)
5
+ grpc (~> 1.22)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.4.0)
11
+ builder (3.2.3)
12
+ byebug (10.0.2)
13
+ descendants_tracker (0.0.4)
14
+ thread_safe (~> 0.3, >= 0.3.1)
15
+ diff-lcs (1.3)
16
+ faraday (0.9.2)
17
+ multipart-post (>= 1.2, < 3)
18
+ git (1.5.0)
19
+ github_api (0.16.0)
20
+ addressable (~> 2.4.0)
21
+ descendants_tracker (~> 0.0.4)
22
+ faraday (~> 0.8, < 0.10)
23
+ hashie (>= 3.4)
24
+ mime-types (>= 1.16, < 3.0)
25
+ oauth2 (~> 1.0)
26
+ google-protobuf (3.9.0)
27
+ googleapis-common-protos-types (1.0.4)
28
+ google-protobuf (~> 3.0)
29
+ grpc (1.22.0)
30
+ google-protobuf (~> 3.8)
31
+ googleapis-common-protos-types (~> 1.0)
32
+ hashie (3.6.0)
33
+ highline (2.0.1)
34
+ hodl-lnd_grpc (0.2.0)
35
+ grpc (~> 1.22)
36
+ jeweler (2.3.9)
37
+ builder
38
+ bundler
39
+ git (>= 1.2.5)
40
+ github_api (~> 0.16.0)
41
+ highline (>= 1.6.15)
42
+ nokogiri (>= 1.5.10)
43
+ psych
44
+ rake
45
+ rdoc
46
+ semver2
47
+ jwt (2.1.0)
48
+ mime-types (2.99.3)
49
+ mini_portile2 (2.4.0)
50
+ multi_json (1.13.1)
51
+ multi_xml (0.6.0)
52
+ multipart-post (2.0.0)
53
+ nokogiri (1.10.1)
54
+ mini_portile2 (~> 2.4.0)
55
+ oauth2 (1.4.1)
56
+ faraday (>= 0.8, < 0.16.0)
57
+ jwt (>= 1.0, < 3.0)
58
+ multi_json (~> 1.3)
59
+ multi_xml (~> 0.5)
60
+ rack (>= 1.2, < 3)
61
+ psych (3.1.0)
62
+ rack (2.0.6)
63
+ rake (10.5.0)
64
+ rdoc (6.1.1)
65
+ rspec (3.8.0)
66
+ rspec-core (~> 3.8.0)
67
+ rspec-expectations (~> 3.8.0)
68
+ rspec-mocks (~> 3.8.0)
69
+ rspec-core (3.8.0)
70
+ rspec-support (~> 3.8.0)
71
+ rspec-expectations (3.8.2)
72
+ diff-lcs (>= 1.2.0, < 2.0)
73
+ rspec-support (~> 3.8.0)
74
+ rspec-mocks (3.8.0)
75
+ diff-lcs (>= 1.2.0, < 2.0)
76
+ rspec-support (~> 3.8.0)
77
+ rspec-support (3.8.0)
78
+ semver2 (3.4.2)
79
+ thread_safe (0.3.6)
80
+
81
+ PLATFORMS
82
+ ruby
83
+
84
+ DEPENDENCIES
85
+ bundler (~> 1.16)
86
+ byebug
87
+ hodl-lightning!
88
+ hodl-lnd_grpc (= 0.2.0)
89
+ jeweler
90
+ rake (~> 10.0)
91
+ rspec (~> 3.0)
92
+
93
+ BUNDLED WITH
94
+ 1.17.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 dsalamau
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ ## Installation
2
+
3
+ Add this line to your application's Gemfile:
4
+
5
+ ```ruby
6
+ gem 'hodl-lightning'
7
+ ```
8
+
9
+ And then execute:
10
+
11
+ $ bundle
12
+
13
+ Or install it yourself as:
14
+
15
+ $ gem install hodl-lightning
16
+
17
+ ## Usage
18
+
19
+ Configure:
20
+
21
+ ```ruby
22
+ Hodl::Lightning.configure do |config|
23
+ config.tls_cert_path = "path_to_certificate"
24
+ config.host = "LND host"
25
+ config.port = "LND port"
26
+ config.logger[:level] = :fatal
27
+ end
28
+ ```
29
+
30
+ Find information how to get certificate here - "TODO: Add link to LND docs"
31
+
32
+ You can call any lnd library method like this:
33
+
34
+ ```ruby
35
+ Hodl::Lightning.server.wallet_balance
36
+ ```
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bin/setup` to install dependencies.
41
+ Then, run `rake spec` to run the tests.
42
+ You could also configure Hodl::Lightning sevrer in `bin/console` file and run `bin/console` for an interactive prompt that will allow you to experiment.
43
+
44
+ ## License
45
+
46
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hodl/lightning"
5
+ require "irb"
6
+
7
+ # Setup server with your credentials
8
+ Hodl::Lightning.configure do |config|
9
+ config.tls_cert_path = "spec/vendor/tls.cert"
10
+ config.host = "127.0.0.1"
11
+ config.port = "10001"
12
+ config.logger[:level] = :fatal
13
+ end
14
+
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,36 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "hodl/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hodl-lightning"
8
+ spec.version = Hodl::Lightning::VERSION
9
+ spec.authors = ["dsalamau"]
10
+ spec.email = ["salamaudavid@gmail.com"]
11
+
12
+ spec.summary = %q{gRPC client for Lighntning Network Daemon }
13
+ spec.license = "MIT"
14
+
15
+ if spec.respond_to?(:metadata)
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+ else
18
+ raise "RubyGems 2.0 or newer is required to protect against " \
19
+ "public gem pushes."
20
+ end
21
+
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "grpc", "~> 1.22"
30
+
31
+ spec.add_development_dependency "bundler", "~> 1.16"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rspec", "~> 3.0"
34
+ spec.add_development_dependency "byebug"
35
+ spec.add_development_dependency "jeweler"
36
+ end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ module Hodl
4
+ module Lightning
5
+ class Configuration
6
+ attr_accessor :tls_cert_path
7
+ attr_accessor :macaroon_path
8
+ attr_accessor :host
9
+ attr_accessor :port
10
+ attr_accessor :logger
11
+
12
+ def initialize
13
+ # Path to automatically generated cert e.g.: "/Users/dsalamau/Library/Application Support/Lnd/tls.cert"
14
+ @tls_cert_path = ""
15
+ # Default host "127.0.0.1"
16
+ @host = ""
17
+ # Default port "10009"
18
+ @port = ""
19
+ # "nil" for unsafe connection
20
+ @macaroon_path = nil
21
+ @logger = {
22
+ device: $stdout,
23
+ level: :info,
24
+ formatter: nil,
25
+ }
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+ require "logger"
5
+
6
+ require_relative "configuration"
7
+ require_relative "server"
8
+ require_relative "version"
9
+
10
+ module Hodl
11
+ module Lightning
12
+ class << self
13
+ attr_writer :configuration
14
+
15
+ def configuration
16
+ @configuration ||= Configuration.new
17
+ end
18
+
19
+ def configure
20
+ yield(configuration)
21
+ end
22
+
23
+ def logger
24
+ return @logger if @logger
25
+ @logger = Logger.new(configuration.logger[:device])
26
+ @logger.progname = "Hodl::Lightning"
27
+ @logger.level = configuration.logger[:level]
28
+ @logger.formatter = configuration.logger[:formatter] if configuration.logger[:formatter]
29
+ @logger
30
+ end
31
+
32
+ def server
33
+ @server ||= Server.new(tls_cert_path: configuration.tls_cert_path, host: configuration.host, port: configuration.port)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "lnd_grpc_services_pb"
4
+ require_relative "server/macaroon_interceptor"
5
+ require_relative "server/services"
6
+
7
+ module Hodl
8
+ module Lightning
9
+ class Server
10
+ include Hodl::Server::Services
11
+
12
+ attr_accessor :tls_cert_path
13
+ attr_accessor :macaroon_path
14
+ attr_accessor :host
15
+ attr_accessor :port
16
+ attr_accessor :stub
17
+
18
+ def initialize(tls_cert_path: nil, host: nil, port: nil, macaroon_path: nil)
19
+ @tls_cert_path = tls_cert_path || Hodl::Lightning.configuration.tls_cert_path
20
+ @macaroon_path = macaroon_path || Hodl::Lightning.configuration.macaroon_path
21
+ @host = host || Hodl::Lightning.configuration.host
22
+ @port = port || Hodl::Lightning.configuration.port
23
+
24
+ @stub = stub || start_server
25
+ end
26
+
27
+ private
28
+
29
+ def start_server
30
+ ENV['GRPC_SSL_CIPHER_SUITES'] = "HIGH+ECDSA"
31
+
32
+ if macaroon_path
33
+ macaroon_binary = File.read(File.expand_path(macaroon_path))
34
+ macaroon = macaroon_binary.each_byte.map { |b| b.to_s(16).rjust(2,'0') }.join
35
+ end
36
+
37
+ certificate = File.read(File.expand_path(tls_cert_path))
38
+ credentials = GRPC::Core::ChannelCredentials.new(certificate)
39
+
40
+ Lnrpc::Lightning::Stub.new("#{host}:#{port}",
41
+ credentials,
42
+ interceptors: macaroon ? [Hodl::Server::MacaroonInterceptor.new(macaroon)] : [])
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ module Hodl
4
+ module Server
5
+ class MacaroonInterceptor < GRPC::ClientInterceptor
6
+ attr_reader :macaroon
7
+
8
+ def initialize(macaroon)
9
+ @macaroon = macaroon
10
+ super
11
+ end
12
+
13
+ def request_response(request:, call:, method:, metadata:)
14
+ metadata["macaroon"] = macaroon
15
+ yield
16
+ end
17
+
18
+ def server_streamer(request:, call:, method:, metadata:)
19
+ metadata["macaroon"] = macaroon
20
+ yield
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,398 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ module Hodl
4
+ module Server
5
+ module Services
6
+ # WalletBalance returns total unspent outputs(confirmed and unconfirmed), all confirmed unspent outputs and
7
+ # all unconfirmed unspent outputs under control of the wallet.
8
+ def wallet_balance
9
+ stub.wallet_balance(Lnrpc::WalletBalanceRequest.new)
10
+ end
11
+
12
+ # ChannelBalance returns the total funds available across all open channels in satoshis.
13
+ def channel_balance
14
+ stub.channel_balance(Lnrpc::ChannelBalanceRequest.new)
15
+ end
16
+
17
+ # GetTransactions returns a list describing all the known transactions relevant to the wallet.
18
+ def get_transactions
19
+ stub.get_transactions(Lnrpc::GetTransactionsRequest.new)
20
+ end
21
+
22
+ # SendCoins executes a request to send coins to a particular address.
23
+ # Unlike SendMany, this RPC call only allows creating a single output at a time.
24
+ # If neither target_conf, or sat_per_byte are set, then the internal wallet will consult its fee model
25
+ # to determine a fee for the default confirmation target.
26
+
27
+ # Parameters:
28
+ # addr string The address to send coins to
29
+ # amount int64 The amount in satoshis to send
30
+ # target_conf int32 The target number of blocks that this transaction should be confirmed by.
31
+ # sat_per_byte int64 A manual fee rate set in sat/byte that should be used when crafting the transaction.
32
+ # send_all bool If set, then the amount field will be ignored, and lnd will attempt to send all the coins
33
+ # under control of the internal wallet to the specified address.
34
+ def send_coins(addr:, amount:, target_conf:nil, sat_per_byte:nil, send_all:nil)
35
+ stub.send_coins(Lnrpc::SendCoinsRequest.new(addr: addr,
36
+ amount: amount,
37
+ target_conf: target_conf,
38
+ sat_per_byte:sat_per_byte,
39
+ send_all: send_all))
40
+ end
41
+
42
+
43
+ # SendMany handles a request for a transaction that creates multiple specified outputs in parallel.
44
+ # If neither target_conf, or sat_per_byte are set, then the internal wallet will consult its fee model to determine a fee for the default confirmation target.
45
+
46
+ # Parameters:
47
+ # AddrToAmount array AddrToAmountEntry The map from addresses to amounts
48
+ # target_conf int32 The target number of blocks that this transaction should be confirmed by.
49
+ # sat_per_byte int64 A manual fee rate set in sat/byte that should be used when crafting the transaction.
50
+ def send_many(addr_to_amount_array, target_conf:nil, sat_per_byte:nil)
51
+ stub.send_many(Lnrpc::SendManyRequest.new(addr_to_amount: addr_to_amount_array,
52
+ target_conf: target_conf,
53
+ sat_per_byte: sat_per_byte))
54
+ end
55
+
56
+
57
+ # ListUnspent returns a list of all utxos spendable by the wallet with a number of confirmations between the specified minimum and maximum.
58
+
59
+ # Parameters:
60
+ # min_confs int32 The minimum number of confirmations to be included.
61
+ # max_confs int32 The maximum number of confirmations to be included.
62
+ def list_unspent(min_confs:, max_confs:)
63
+ stub.list_unspent(Lnrpc::ListUnspentRequest.new(min_confs: min_confs, max_confs: max_confs))
64
+ end
65
+
66
+ # NewAddress creates a new address under control of the local wallet.
67
+
68
+ # Parameters:
69
+ # type AddressType The address type
70
+ def new_address(type:)
71
+ stub.new_address(Lnrpc::NewAddressRequest.new(type: type))
72
+ end
73
+
74
+ # ConnectPeer attempts to establish a connection to a remote peer.
75
+ # This is at the networking level, and is used for communication between nodes.
76
+ # This is distinct from establishing a channel with a peer.
77
+
78
+ # Parameters:
79
+ # addr LightningAddress Lightning address of the peer, in the format <pubkey>@host
80
+ # perm bool If set, the daemon will attempt to persistently connect to the target peer.
81
+ # Otherwise, the call will be synchronous.
82
+ def connect_peer(addr:, perm:nil)
83
+ stub.connect_peer(Lnrpc::ConnectPeerRequest.new(addr: addr, perm: perm))
84
+ end
85
+
86
+ # DisconnectPeer attempts to disconnect one peer from another identified by a given pubKey.
87
+ # In the case that we currently have a pending or active channel with the target peer, then this action will be not be allowed.
88
+
89
+ # Parameters:
90
+ # pub_key string The pubkey of the node to disconnect from
91
+ def disconnect_peer(pub_key:)
92
+ stub.disconnect_peer(Lnrpc::DisconnectPeerRequest.new(pub_key: pub_key))
93
+ end
94
+
95
+ #ListPeers returns a verbose listing of all currently active peers.
96
+ def list_peers
97
+ stub.list_peers(Lnrpc::ListPeersRequest.new)
98
+ end
99
+
100
+ # GetInfo returns general information concerning the lightning node including
101
+ # it’s identity pubkey, alias, the chains it is connected to, and information concerning the number of open+pending channels.
102
+ def get_info
103
+ stub.get_info(Lnrpc::GetInfoRequest.new)
104
+ end
105
+
106
+ # PendingChannels returns a list of all the channels that are currently considered “pending”.
107
+ # A channel is pending if it has finished the funding workflow and is waiting for confirmations for the funding txn,
108
+ # or is in the process of closure, either initiated cooperatively or non-cooperatively.
109
+ def pending_channels
110
+ stub.pending_channels(Lnrpc::PendingChannelsRequest.new)
111
+ end
112
+
113
+ # ListChannels returns a description of all the open channels that this node is a participant in.
114
+
115
+ # Parameters:
116
+ # active_only bool
117
+ # inactive_only bool
118
+ # public_only bool
119
+ # private_only bool
120
+ def list_channels(active_only:nil, inactive_only:nil, public_only:nil, private_only:nil)
121
+ stub.list_channels(Lnrpc::ListChannelsRequest.new(active_only: active_only,
122
+ inactive_only: inactive_only,
123
+ public_only: public_only,
124
+ private_only: private_only))
125
+ end
126
+
127
+ # ClosedChannels returns a description of all the closed channels that this node was a participant in.
128
+
129
+ # Parameters:
130
+ # cooperative bool
131
+ # local_force bool
132
+ # remote_force bool
133
+ # breach bool
134
+ # funding_canceled bool
135
+ # abandoned bool
136
+ def closed_channels(cooperative:nil, local_force:nil, remote_force:nil, breach:nil, funding_canceled:nil, abandoned:nil)
137
+ stub.closed_channels(Lnrpc::ClosedChannelsRequest.new(cooperative: cooperative,
138
+ local_force: local_force,
139
+ remote_force: remote_force,
140
+ breach: breach,
141
+ funding_canceled: funding_canceled,
142
+ abandoned: abandoned))
143
+ end
144
+
145
+ #OpenChannel attempts to open a singly funded channel specified in the request to a remote peer.
146
+ # Users are able to specify a target number of blocks that the funding transaction should be confirmed in,
147
+ # or a manual fee rate to us for the funding transaction. If neither are specified, then a lax block confirmation target is used.
148
+
149
+ # Parameters:
150
+ # node_pubkey bytes The pubkey of the node to open a channel with
151
+ # node_pubkey_string string The hex encoded pubkey of the node to open a channel with
152
+ # local_funding_amount int64 The number of satoshis the wallet should commit to the channel
153
+ # push_sat int64 The number of satoshis to push to the remote side as part of the initial commitment state
154
+ # target_conf int32 The target number of blocks that the funding transaction should be confirmed by.
155
+ # sat_per_byte int64 A manual fee rate set in sat/byte that should be used when crafting the funding transaction.
156
+ # private bool Whether this channel should be private, not announced to the greater network.
157
+ # min_htlc_msat int64 The minimum value in millisatoshi we will require for incoming HTLCs on the channel.
158
+ # remote_csv_delay uint32 The delay we require on the remote’s commitment transaction. If this is not set, it will be scaled automatically with the channel size.
159
+ # min_confs int32 The minimum number of confirmations each one of your outputs used for the funding transaction must satisfy.
160
+ # spend_unconfirmed bool Whether unconfirmed outputs should be use
161
+ def open_channel(node_pubkey:nil, node_pubkey_string:, local_funding_amount:, push_sat:nil, target_conf:nil,
162
+ sat_per_byte:nil, private_channel:nil, min_htlc_msat:nil, remote_csv_delay:nil, min_confs:nil, spend_unconfirmed:nil)
163
+ stub.open_channel(Lnrpc::OpenChannelRequest.new(node_pubkey: node_pubkey,
164
+ node_pubkey_string: node_pubkey_string,
165
+ local_funding_amount: local_funding_amount,
166
+ push_sat: push_sat,
167
+ target_conf: target_conf,
168
+ sat_per_byte: sat_per_byte,
169
+ private: private_channel,
170
+ min_htlc_msat: min_htlc_msat,
171
+ remote_csv_delay: remote_csv_delay,
172
+ min_confs: min_confs,
173
+ spend_unconfirmed: spend_unconfirmed))
174
+ end
175
+
176
+ # CloseChannel attempts to close an active channel identified by its channel outpoint (ChannelPoint).
177
+ # The actions of this method can additionally be augmented to attempt a force close after a timeout period
178
+ # in the case of an inactive peer. If a non-force close (cooperative closure) is requested,
179
+ # then the user can specify either a target number of blocks until the closure transaction is confirmed,
180
+ # or a manual fee rate. If neither are specified, then a default lax, block confirmation target is used.
181
+
182
+ # Parameters:
183
+ # channel_point ChannelPoint The outpoint (txid:index) of the funding transaction. With this value, Bob will be able to generate a signature for Alice’s version of the commitment transaction.
184
+ # force bool If true, then the channel will be closed forcibly. This means the current commitment transaction will be signed and broadcast.
185
+ # target_conf int32 The target number of blocks that the closure transaction should be confirmed by.
186
+ # sat_per_byte int64 A manual fee rate set in sat/byte that should be used when crafting the closure transaction.
187
+ def close_channel(channel_point:, force:nil, target_conf:nil, sat_per_byte:nil)
188
+ stub.close_channel(Lnrpc::CloseChannelRequest.new(channel_point: channel_point,
189
+ force: force,
190
+ target_conf: target_conf,
191
+ sat_per_byte: sat_per_byte))
192
+ end
193
+
194
+ #AbandonChannel removes all channel state from the database except for a close summary.
195
+ # This method can be used to get rid of permanently unusable channels due to bugs fixed in newer versions of lnd.
196
+ # Only available when in debug builds of lnd.
197
+
198
+ # Parameters:
199
+ # channel_point ChannelPoint
200
+ def abandon_channel(channel_point:)
201
+ stub.abandon_channel(Lnrpc::AbandonChannelRequest.new(channel_point: channel_point))
202
+ end
203
+
204
+ # SendPaymentSync is the synchronous non-streaming version of SendPayment.
205
+ # This RPC is intended to be consumed by clients of the REST proxy.
206
+ # Additionally, this RPC expects the destination’s public key and the payment hash (if any) to be encoded as hex strings.
207
+
208
+ # Parameters:
209
+ # dest bytes The identity pubkey of the payment recipient
210
+ # dest_string string The hex-encoded identity pubkey of the payment recipient
211
+ # amt int64 Number of satoshis to send.
212
+ # payment_hash bytes The hash to use within the payment’s HTLC
213
+ # payment_hash_string string The hex-encoded hash to use within the payment’s HTLC
214
+ # payment_request string A bare-bones invoice for a payment within the Lightning Network. With the details of the invoice, the sender has all the data necessary to send a payment to the recipient.
215
+ # final_cltv_delta int32 The CLTV delta from the current height that should be used to set the timelock for the final hop.
216
+ # fee_limit FeeLimit The maximum number of satoshis that will be paid as a fee of the payment. This value can be represented either as a percentage of the amount being sent, or as a fixed amount of the maximum fee the user is willing the pay to send the payment.
217
+ # outgoing_chan_id uint64 The channel id of the channel that must be taken to the first hop. If zero, any channel may be used.
218
+ # cltv_limit uint32 An optional maximum total time lock for the route. If zero, there is no maximum enforced.
219
+ def send_payment_sync(dest:nil, dest_string:nil, amt:nil, payment_hash:nil, payment_hash_string:nil, payment_request:nil,
220
+ final_cltv_delta:nil, fee_limit:nil, outgoing_chan_id:nil, cltv_limit:nil)
221
+ stub.send_payment_sync(Lnrpc::SendRequest.new(dest: dest,
222
+ dest_string: dest_string,
223
+ amt: amt,
224
+ payment_hash: payment_hash,
225
+ payment_hash_string: payment_hash_string,
226
+ payment_request: payment_request,
227
+ final_cltv_delta: final_cltv_delta,
228
+ fee_limit: Lnrpc::FeeLimit.new(fixed: fee_limit)))
229
+ end
230
+
231
+ # AddInvoice attempts to add a new invoice to the invoice database.
232
+ # Any duplicated invoices are rejected, therefore all invoices must have a unique payment preimage.
233
+
234
+ # Parameters:
235
+ # memo string An optional memo to attach along with the invoice. Used for record keeping purposes for the invoice’s creator, and will also be set in the description field of the encoded payment request if the description_hash field is not being used.
236
+ # r_preimage bytes The hex-encoded preimage (32 byte) which will allow settling an incoming HTLC payable to this preimage
237
+ # r_hash bytes The hash of the preimage
238
+ # value int64 The value of this invoice in satoshis
239
+ # settled bool Whether this invoice has been fulfilled
240
+ # creation_date int64 When this invoice was created
241
+ # settle_date int64 When this invoice was settled
242
+ # payment_request string A bare-bones invoice for a payment within the Lightning Network. With the details of the invoice, the sender has all the data necessary to send a payment to the recipient.
243
+ # description_hash bytes Hash (SHA-256) of a description of the payment. Used if the description of payment (memo) is too long to naturally fit within the description field of an encoded payment request.
244
+ # expiry int64 Payment request expiry time in seconds. Default is 3600 (1 hour).
245
+ # fallback_addr string Fallback on-chain address.
246
+ # cltv_expiry uint64 Delta to use for the time-lock of the CLTV extended to the final hop.
247
+ # route_hints array RouteHint Route hints that can each be individually used to assist in reaching the invoice’s destination.
248
+ # private bool Whether this invoice should include routing hints for private channels.
249
+ # add_index uint64 The “add” index of this invoice. Each newly created invoice will increment this index making it monotonically increasing. Callers to the SubscribeInvoices call can use this to instantly get notified of all added invoices with an add_index greater than this one.
250
+ # settle_index uint64 The “settle” index of this invoice. Each newly settled invoice will increment this index making it monotonically increasing. Callers to the SubscribeInvoices call can use this to instantly get notified of all settled invoices with an settle_index greater than this one.
251
+ # amt_paid_sat int64 The amount that was accepted for this invoice, in satoshis. This will ONLY be set if this invoice has been settled. We provide this field as if the invoice was created with a zero value, then we need to record what amount was ultimately accepted. Additionally, it’s possible that the sender paid MORE that was specified in the original invoice. So we’ll record that here as well.
252
+ # amt_paid_msat int64 The amount that was accepted for this invoice, in millisatoshis. This will ONLY be set if this invoice has been settled. We provide this field as if the invoice was created with a zero value, then we need to record what amount was ultimately accepted. Additionally, it’s possible that the sender paid MORE that was specified in the original invoice. So we’ll record that here as well.
253
+ # state InvoiceState
254
+ def add_invoice(memo:nil, r_preimage:nil, r_hash:nil, value:nil, settled:nil, creation_date:nil, settle_date:nil, payment_request:nil, description_hash:nil, expiry:nil,
255
+ fallback_addr:nil, cltv_expiry:nil, route_hints:nil, private_invoice:nil, add_index:nil, settle_index:nil, amt_paid_sat:nil, amt_paid_msat:nil, state:nil)
256
+ stub.add_invoice(Lnrpc::Invoice.new(memo: memo,
257
+ r_preimage: r_preimage,
258
+ r_hash: r_hash,
259
+ value: value,
260
+ settled: settled,
261
+ creation_date: creation_date,
262
+ settle_date: settle_date,
263
+ payment_request: payment_request,
264
+ description_hash: description_hash,
265
+ expiry: expiry,
266
+ fallback_addr: fallback_addr,
267
+ cltv_expiry: cltv_expiry,
268
+ route_hints: route_hints,
269
+ private: private_invoice,
270
+ add_index: add_index,
271
+ settle_index: settle_index,
272
+ amt_paid_sat: amt_paid_sat,
273
+ amt_paid_msat: amt_paid_msat,
274
+ state: state))
275
+ end
276
+
277
+ # ListInvoices returns a list of all the invoices currently stored within the database.
278
+ # Any active debug invoices are ignored. It has full support for paginated responses,
279
+ # allowing users to query for specific invoices through their add_index.
280
+ # This can be done by using either the first_index_offset or last_index_offset fields included
281
+ # in the response as the index_offset of the next request. By default, the first 100 invoices created will be returned.
282
+ # Backwards pagination is also supported through the Reversed flag.
283
+
284
+ # Parameters:
285
+ # pending_only bool If set, only unsettled invoices will be returned in the response.
286
+ # index_offset uint64 The index of an invoice that will be used as either the start or end of a query to determine which invoices should be returned in the response.
287
+ # um_max_invoices uint64 The max number of invoices to return in the response to this query.
288
+ # reversed bool If set, the invoices returned will result from seeking backwards from the specified index offset. This can be used to paginate backwards.
289
+ def list_invoices(pending_only:nil, index_offset:nil, um_max_invoices:nil, reversed: nil)
290
+ stub.list_invoices(Lnrpc::ListInvoiceRequest.new(pending_only: pending_only,
291
+ index_offset: index_offset,
292
+ um_max_invoices: um_max_invoices,
293
+ reversed: reversed))
294
+ end
295
+
296
+ # LookupInvoice attempts to look up an invoice according to its payment hash.
297
+ # The passed payment hash must be exactly 32 bytes, if not, an error is returned.
298
+
299
+ # Parameters
300
+ # r_hash_str string The hex-encoded payment hash of the invoice to be looked up. The passed payment hash must be exactly 32 bytes, otherwise an error is returned.
301
+ # r_hash bytes The payment hash of the invoice to be looked up.
302
+ def lookup_invoice(r_hash_str: nil, r_hash: nil)
303
+ stub.lookup_invoice(Lnrpc::PaymentHash.new(r_hash_str: r_hash_str,
304
+ r_hash: r_hash))
305
+ end
306
+
307
+ # DecodePayReq takes an encoded payment request string and attempts to decode it,
308
+ # returning a full description of the conditions encoded within the payment request.
309
+
310
+ # Parameters
311
+ # pay_req string The payment request string to be decoded
312
+ def decode_pay_req(pay_req:)
313
+ stub.decode_pay_req(Lnrpc::PayReqString.new(pay_req: pay_req))
314
+ end
315
+
316
+ # ListPayments returns a list of all outgoing payments.
317
+ def list_payments
318
+ stub.list_payments(Lnrpc::PayReqString.new)
319
+ end
320
+
321
+ # DeleteAllPayments deletes all outgoing payments from DB.
322
+ def delete_all_payments(confirmed:false)
323
+ stub.delete_all_payments(Lnrpc::DeleteAllPaymentsRequest.new) if confirmed
324
+ end
325
+
326
+ # GetChanInfo returns the latest authenticated network announcement for the given channel
327
+ # identified by its channel ID: an 8-byte integer which uniquely identifies the location of transaction’s
328
+ # funding output within the blockchain.
329
+
330
+ # Parameters
331
+ # chan_id uint64 The unique channel ID for the channel. The first 3 bytes are the block height, the next 3 the index within the block, and the last 2 bytes are the output index for the channel.
332
+ def get_chan_info(chan_id:)
333
+ stub.get_chan_info(Lnrpc::ChanInfoRequest.new(chan_id: chan_id))
334
+ end
335
+
336
+ # GetNodeInfo returns the latest advertised, aggregated, and authenticated channel information
337
+ # for the specified node identified by its public key.
338
+
339
+ # Parameters
340
+ # pub_key string The 33-byte hex-encoded compressed public of the target node
341
+ def get_node_info(pub_key:)
342
+ stub.get_node_info(Lnrpc::NodeInfoRequest.new(pub_key: pub_key))
343
+ end
344
+
345
+ # QueryRoutes attempts to query the daemon’s Channel Router for a possible route to a target destination capable of carrying a specific amount of satoshis.
346
+ # The retuned route contains the full details required to craft and send an HTLC, also including the necessary information that should be present within the Sphinx packet encapsulated within the HTLC.
347
+
348
+ # Parameters
349
+ # pub_key string The 33-byte hex-encoded public key for the payment destination
350
+ # amt int64 The amount to send expressed in satoshis
351
+ # final_cltv_delta int32 An optional CLTV delta from the current height that should be used for the timelock of the final hop
352
+ # fee_limit FeeLimit The maximum number of satoshis that will be paid as a fee of the payment. This value can be represented either as a percentage of the amount being sent, or as a fixed amount of the maximum fee the user is willing the pay to send the payment.
353
+ # ignored_nodes array bytes A list of nodes to ignore during path finding.
354
+ # ignored_edges array EdgeLocator A list of edges to ignore during path finding.
355
+ # source_pub_key string The source node where the request route should originated from. If empty, self is assumed.
356
+ def query_routes(pub_key:nil, amt:nil, final_cltv_delta:nil, fee_limit:nil, ignored_edges:nil, source_pub_key:nil, ignored_nodes:nil)
357
+ stub.query_routes(Lnrpc::QueryRoutesRequest.new(pub_key: pub_key,
358
+ amt: amt,
359
+ final_cltv_delta: final_cltv_delta,
360
+ fee_limit: fee_limit,
361
+ ignored_nodes: ignored_nodes,
362
+ ignored_edges: ignored_edges,
363
+ source_pub_key: source_pub_key))
364
+ end
365
+
366
+ # GetNetworkInfo returns some basic stats about the known channel graph from the point of view of the node.
367
+ def get_network_info
368
+ stub.get_network_info(Lnrpc::NetworkInfoRequest.new)
369
+ end
370
+
371
+ # StopDaemon will send a shutdown request to the interrupt handler, triggering a graceful shutdown of the daemon.
372
+ def stop_daemon(confirmed:false)
373
+ stub.stop_daemon(Lnrpc::StopRequest.new) if confirmed
374
+ end
375
+
376
+ # FeeReport allows the caller to obtain a report detailing the current fee schedule enforced by the node globally for each channel.
377
+ def fee_report
378
+ stub.fee_report(Lnrpc::FeeReportRequest.new)
379
+ end
380
+
381
+ # UpdateChannelPolicy allows the caller to update the fee schedule and channel policies for all channels globally, or a particular channel.
382
+
383
+ # Parameters
384
+ # global bool If set, then this update applies to all currently active channels.
385
+ # chan_point ChannelPoint If set, this update will target a specific channel.
386
+ # base_fee_msat int64 The base fee charged regardless of the number of milli-satoshis sent.
387
+ # fee_rate double The effective fee rate in milli-satoshis. The precision of this value goes up to 6 decimal places, so 1e-6.
388
+ # time_lock_delta uint32 The required timelock delta for HTLCs forwarded over the channel.
389
+ def update_channel_policy(global:nil, chan_point:nil, base_fee_msat:nil, fee_rate:nil, time_lock_delta:nil)
390
+ stub.update_channel_policy(Lnrpc::PolicyUpdateRequest.new(global: global,
391
+ chan_point: chan_point,
392
+ base_fee_msat: base_fee_msat,
393
+ fee_rate: fee_rate,
394
+ time_lock_delta: time_lock_delta))
395
+ end
396
+ end
397
+ end
398
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ module Hodl
4
+ module Lightning
5
+ VERSION = "0.2.0"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hodl-lightning
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - dsalamau
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-10-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: grpc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.22'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.22'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: jeweler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - salamaudavid@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - hodl-lightning.gemspec
114
+ - lib/hodl/configuration.rb
115
+ - lib/hodl/lightning.rb
116
+ - lib/hodl/server.rb
117
+ - lib/hodl/server/macaroon_interceptor.rb
118
+ - lib/hodl/server/services.rb
119
+ - lib/hodl/version.rb
120
+ homepage:
121
+ licenses:
122
+ - MIT
123
+ metadata:
124
+ allowed_push_host: https://rubygems.org
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubygems_version: 3.0.3
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: gRPC client for Lighntning Network Daemon
144
+ test_files: []