lnrpc 0.8.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/Gemfile.lock +24 -24
  4. data/README.md +30 -16
  5. data/examples.rb +14 -12
  6. data/generate-grpc-service-files.sh +30 -0
  7. data/lib/grpc_services/autopilotrpc/autopilot_pb.rb +48 -0
  8. data/lib/grpc_services/autopilotrpc/autopilot_services_pb.rb +40 -0
  9. data/lib/grpc_services/chainrpc/chainnotifier_pb.rb +67 -0
  10. data/lib/grpc_services/chainrpc/chainnotifier_services_pb.rb +51 -0
  11. data/lib/grpc_services/invoicesrpc/invoices_pb.rb +48 -0
  12. data/lib/grpc_services/invoicesrpc/invoices_services_pb.rb +41 -0
  13. data/lib/grpc_services/lnclipb/lncli_pb.rb +18 -0
  14. data/lib/grpc_services/routerrpc/router_pb.rb +233 -0
  15. data/lib/grpc_services/routerrpc/router_services_pb.rb +86 -0
  16. data/lib/grpc_services/rpc_pb.rb +1347 -0
  17. data/lib/{lnrpc → grpc_services}/rpc_services_pb.rb +185 -175
  18. data/lib/grpc_services/signrpc/signer_pb.rb +84 -0
  19. data/lib/grpc_services/signrpc/signer_services_pb.rb +69 -0
  20. data/lib/grpc_services/verrpc/verrpc_pb.rb +27 -0
  21. data/lib/grpc_services/verrpc/verrpc_services_pb.rb +27 -0
  22. data/lib/grpc_services/walletrpc/walletkit_pb.rb +188 -0
  23. data/lib/grpc_services/walletrpc/walletkit_services_pb.rb +148 -0
  24. data/lib/grpc_services/walletunlocker_pb.rb +57 -0
  25. data/lib/grpc_services/walletunlocker_services_pb.rb +72 -0
  26. data/lib/grpc_services/watchtowerrpc/watchtower_pb.rb +21 -0
  27. data/lib/grpc_services/watchtowerrpc/watchtower_services_pb.rb +28 -0
  28. data/lib/grpc_services/wtclientrpc/wtclient_pb.rb +81 -0
  29. data/lib/grpc_services/wtclientrpc/wtclient_services_pb.rb +43 -0
  30. data/lib/lnrpc.rb +19 -3
  31. data/lib/lnrpc/client.rb +62 -46
  32. data/lib/lnrpc/grpc_wrapper.rb +43 -0
  33. data/lib/lnrpc/version.rb +1 -1
  34. data/lnrpc.gemspec +7 -5
  35. metadata +41 -17
  36. data/lib/lnrpc/rpc.proto +0 -2580
  37. data/lib/lnrpc/rpc_pb.rb +0 -938
@@ -0,0 +1,57 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: walletunlocker.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ require 'rpc_pb'
7
+ Google::Protobuf::DescriptorPool.generated_pool.build do
8
+ add_file("walletunlocker.proto", :syntax => :proto3) do
9
+ add_message "lnrpc.GenSeedRequest" do
10
+ optional :aezeed_passphrase, :bytes, 1
11
+ optional :seed_entropy, :bytes, 2
12
+ end
13
+ add_message "lnrpc.GenSeedResponse" do
14
+ repeated :cipher_seed_mnemonic, :string, 1
15
+ optional :enciphered_seed, :bytes, 2
16
+ end
17
+ add_message "lnrpc.InitWalletRequest" do
18
+ optional :wallet_password, :bytes, 1
19
+ repeated :cipher_seed_mnemonic, :string, 2
20
+ optional :aezeed_passphrase, :bytes, 3
21
+ optional :recovery_window, :int32, 4
22
+ optional :channel_backups, :message, 5, "lnrpc.ChanBackupSnapshot"
23
+ optional :stateless_init, :bool, 6
24
+ end
25
+ add_message "lnrpc.InitWalletResponse" do
26
+ optional :admin_macaroon, :bytes, 1
27
+ end
28
+ add_message "lnrpc.UnlockWalletRequest" do
29
+ optional :wallet_password, :bytes, 1
30
+ optional :recovery_window, :int32, 2
31
+ optional :channel_backups, :message, 3, "lnrpc.ChanBackupSnapshot"
32
+ optional :stateless_init, :bool, 4
33
+ end
34
+ add_message "lnrpc.UnlockWalletResponse" do
35
+ end
36
+ add_message "lnrpc.ChangePasswordRequest" do
37
+ optional :current_password, :bytes, 1
38
+ optional :new_password, :bytes, 2
39
+ optional :stateless_init, :bool, 3
40
+ optional :new_macaroon_root_key, :bool, 4
41
+ end
42
+ add_message "lnrpc.ChangePasswordResponse" do
43
+ optional :admin_macaroon, :bytes, 1
44
+ end
45
+ end
46
+ end
47
+
48
+ module Lnrpc
49
+ GenSeedRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("lnrpc.GenSeedRequest").msgclass
50
+ GenSeedResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("lnrpc.GenSeedResponse").msgclass
51
+ InitWalletRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("lnrpc.InitWalletRequest").msgclass
52
+ InitWalletResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("lnrpc.InitWalletResponse").msgclass
53
+ UnlockWalletRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("lnrpc.UnlockWalletRequest").msgclass
54
+ UnlockWalletResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("lnrpc.UnlockWalletResponse").msgclass
55
+ ChangePasswordRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("lnrpc.ChangePasswordRequest").msgclass
56
+ ChangePasswordResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("lnrpc.ChangePasswordResponse").msgclass
57
+ end
@@ -0,0 +1,72 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # Source: walletunlocker.proto for package 'lnrpc'
3
+
4
+ require 'grpc'
5
+ require 'walletunlocker_pb'
6
+
7
+ module Lnrpc
8
+ module WalletUnlocker
9
+ #
10
+ # Comments in this file will be directly parsed into the API
11
+ # Documentation as descriptions of the associated method, message, or field.
12
+ # These descriptions should go right above the definition of the object, and
13
+ # can be in either block or // comment format.
14
+ #
15
+ # An RPC method can be matched to an lncli command by placing a line in the
16
+ # beginning of the description in exactly the following format:
17
+ # lncli: `methodname`
18
+ #
19
+ # Failure to specify the exact name of the command will cause documentation
20
+ # generation to fail.
21
+ #
22
+ # More information on how exactly the gRPC documentation is generated from
23
+ # this proto file can be found here:
24
+ # https://github.com/lightninglabs/lightning-api
25
+ #
26
+ # WalletUnlocker is a service that is used to set up a wallet password for
27
+ # lnd at first startup, and unlock a previously set up wallet.
28
+ class Service
29
+
30
+ include ::GRPC::GenericService
31
+
32
+ self.marshal_class_method = :encode
33
+ self.unmarshal_class_method = :decode
34
+ self.service_name = 'lnrpc.WalletUnlocker'
35
+
36
+ #
37
+ # GenSeed is the first method that should be used to instantiate a new lnd
38
+ # instance. This method allows a caller to generate a new aezeed cipher seed
39
+ # given an optional passphrase. If provided, the passphrase will be necessary
40
+ # to decrypt the cipherseed to expose the internal wallet seed.
41
+ #
42
+ # Once the cipherseed is obtained and verified by the user, the InitWallet
43
+ # method should be used to commit the newly generated seed, and create the
44
+ # wallet.
45
+ rpc :GenSeed, ::Lnrpc::GenSeedRequest, ::Lnrpc::GenSeedResponse
46
+ #
47
+ # InitWallet is used when lnd is starting up for the first time to fully
48
+ # initialize the daemon and its internal wallet. At the very least a wallet
49
+ # password must be provided. This will be used to encrypt sensitive material
50
+ # on disk.
51
+ #
52
+ # In the case of a recovery scenario, the user can also specify their aezeed
53
+ # mnemonic and passphrase. If set, then the daemon will use this prior state
54
+ # to initialize its internal wallet.
55
+ #
56
+ # Alternatively, this can be used along with the GenSeed RPC to obtain a
57
+ # seed, then present it to the user. Once it has been verified by the user,
58
+ # the seed can be fed into this RPC in order to commit the new wallet.
59
+ rpc :InitWallet, ::Lnrpc::InitWalletRequest, ::Lnrpc::InitWalletResponse
60
+ # lncli: `unlock`
61
+ # UnlockWallet is used at startup of lnd to provide a password to unlock
62
+ # the wallet database.
63
+ rpc :UnlockWallet, ::Lnrpc::UnlockWalletRequest, ::Lnrpc::UnlockWalletResponse
64
+ # lncli: `changepassword`
65
+ # ChangePassword changes the password of the encrypted wallet. This will
66
+ # automatically unlock the wallet database if successful.
67
+ rpc :ChangePassword, ::Lnrpc::ChangePasswordRequest, ::Lnrpc::ChangePasswordResponse
68
+ end
69
+
70
+ Stub = Service.rpc_stub_class
71
+ end
72
+ end
@@ -0,0 +1,21 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: watchtowerrpc/watchtower.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_file("watchtowerrpc/watchtower.proto", :syntax => :proto3) do
8
+ add_message "watchtowerrpc.GetInfoRequest" do
9
+ end
10
+ add_message "watchtowerrpc.GetInfoResponse" do
11
+ optional :pubkey, :bytes, 1
12
+ repeated :listeners, :string, 2
13
+ repeated :uris, :string, 3
14
+ end
15
+ end
16
+ end
17
+
18
+ module Watchtowerrpc
19
+ GetInfoRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("watchtowerrpc.GetInfoRequest").msgclass
20
+ GetInfoResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("watchtowerrpc.GetInfoResponse").msgclass
21
+ end
@@ -0,0 +1,28 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # Source: watchtowerrpc/watchtower.proto for package 'watchtowerrpc'
3
+
4
+ require 'grpc'
5
+ require 'watchtowerrpc/watchtower_pb'
6
+
7
+ module Watchtowerrpc
8
+ module Watchtower
9
+ # Watchtower is a service that grants access to the watchtower server
10
+ # functionality of the daemon.
11
+ class Service
12
+
13
+ include ::GRPC::GenericService
14
+
15
+ self.marshal_class_method = :encode
16
+ self.unmarshal_class_method = :decode
17
+ self.service_name = 'watchtowerrpc.Watchtower'
18
+
19
+ # lncli: tower info
20
+ # GetInfo returns general information concerning the companion watchtower
21
+ # including its public key and URIs where the server is currently
22
+ # listening for clients.
23
+ rpc :GetInfo, ::Watchtowerrpc::GetInfoRequest, ::Watchtowerrpc::GetInfoResponse
24
+ end
25
+
26
+ Stub = Service.rpc_stub_class
27
+ end
28
+ end
@@ -0,0 +1,81 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: wtclientrpc/wtclient.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_file("wtclientrpc/wtclient.proto", :syntax => :proto3) do
8
+ add_message "wtclientrpc.AddTowerRequest" do
9
+ optional :pubkey, :bytes, 1
10
+ optional :address, :string, 2
11
+ end
12
+ add_message "wtclientrpc.AddTowerResponse" do
13
+ end
14
+ add_message "wtclientrpc.RemoveTowerRequest" do
15
+ optional :pubkey, :bytes, 1
16
+ optional :address, :string, 2
17
+ end
18
+ add_message "wtclientrpc.RemoveTowerResponse" do
19
+ end
20
+ add_message "wtclientrpc.GetTowerInfoRequest" do
21
+ optional :pubkey, :bytes, 1
22
+ optional :include_sessions, :bool, 2
23
+ end
24
+ add_message "wtclientrpc.TowerSession" do
25
+ optional :num_backups, :uint32, 1
26
+ optional :num_pending_backups, :uint32, 2
27
+ optional :max_backups, :uint32, 3
28
+ optional :sweep_sat_per_byte, :uint32, 4
29
+ end
30
+ add_message "wtclientrpc.Tower" do
31
+ optional :pubkey, :bytes, 1
32
+ repeated :addresses, :string, 2
33
+ optional :active_session_candidate, :bool, 3
34
+ optional :num_sessions, :uint32, 4
35
+ repeated :sessions, :message, 5, "wtclientrpc.TowerSession"
36
+ end
37
+ add_message "wtclientrpc.ListTowersRequest" do
38
+ optional :include_sessions, :bool, 1
39
+ end
40
+ add_message "wtclientrpc.ListTowersResponse" do
41
+ repeated :towers, :message, 1, "wtclientrpc.Tower"
42
+ end
43
+ add_message "wtclientrpc.StatsRequest" do
44
+ end
45
+ add_message "wtclientrpc.StatsResponse" do
46
+ optional :num_backups, :uint32, 1
47
+ optional :num_pending_backups, :uint32, 2
48
+ optional :num_failed_backups, :uint32, 3
49
+ optional :num_sessions_acquired, :uint32, 4
50
+ optional :num_sessions_exhausted, :uint32, 5
51
+ end
52
+ add_message "wtclientrpc.PolicyRequest" do
53
+ optional :policy_type, :enum, 1, "wtclientrpc.PolicyType"
54
+ end
55
+ add_message "wtclientrpc.PolicyResponse" do
56
+ optional :max_updates, :uint32, 1
57
+ optional :sweep_sat_per_byte, :uint32, 2
58
+ end
59
+ add_enum "wtclientrpc.PolicyType" do
60
+ value :LEGACY, 0
61
+ value :ANCHOR, 1
62
+ end
63
+ end
64
+ end
65
+
66
+ module Wtclientrpc
67
+ AddTowerRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("wtclientrpc.AddTowerRequest").msgclass
68
+ AddTowerResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("wtclientrpc.AddTowerResponse").msgclass
69
+ RemoveTowerRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("wtclientrpc.RemoveTowerRequest").msgclass
70
+ RemoveTowerResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("wtclientrpc.RemoveTowerResponse").msgclass
71
+ GetTowerInfoRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("wtclientrpc.GetTowerInfoRequest").msgclass
72
+ TowerSession = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("wtclientrpc.TowerSession").msgclass
73
+ Tower = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("wtclientrpc.Tower").msgclass
74
+ ListTowersRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("wtclientrpc.ListTowersRequest").msgclass
75
+ ListTowersResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("wtclientrpc.ListTowersResponse").msgclass
76
+ StatsRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("wtclientrpc.StatsRequest").msgclass
77
+ StatsResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("wtclientrpc.StatsResponse").msgclass
78
+ PolicyRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("wtclientrpc.PolicyRequest").msgclass
79
+ PolicyResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("wtclientrpc.PolicyResponse").msgclass
80
+ PolicyType = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("wtclientrpc.PolicyType").enummodule
81
+ end
@@ -0,0 +1,43 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # Source: wtclientrpc/wtclient.proto for package 'wtclientrpc'
3
+
4
+ require 'grpc'
5
+ require 'wtclientrpc/wtclient_pb'
6
+
7
+ module Wtclientrpc
8
+ module WatchtowerClient
9
+ # WatchtowerClient is a service that grants access to the watchtower client
10
+ # functionality of the daemon.
11
+ class Service
12
+
13
+ include ::GRPC::GenericService
14
+
15
+ self.marshal_class_method = :encode
16
+ self.unmarshal_class_method = :decode
17
+ self.service_name = 'wtclientrpc.WatchtowerClient'
18
+
19
+ #
20
+ # AddTower adds a new watchtower reachable at the given address and
21
+ # considers it for new sessions. If the watchtower already exists, then
22
+ # any new addresses included will be considered when dialing it for
23
+ # session negotiations and backups.
24
+ rpc :AddTower, ::Wtclientrpc::AddTowerRequest, ::Wtclientrpc::AddTowerResponse
25
+ #
26
+ # RemoveTower removes a watchtower from being considered for future session
27
+ # negotiations and from being used for any subsequent backups until it's added
28
+ # again. If an address is provided, then this RPC only serves as a way of
29
+ # removing the address from the watchtower instead.
30
+ rpc :RemoveTower, ::Wtclientrpc::RemoveTowerRequest, ::Wtclientrpc::RemoveTowerResponse
31
+ # ListTowers returns the list of watchtowers registered with the client.
32
+ rpc :ListTowers, ::Wtclientrpc::ListTowersRequest, ::Wtclientrpc::ListTowersResponse
33
+ # GetTowerInfo retrieves information for a registered watchtower.
34
+ rpc :GetTowerInfo, ::Wtclientrpc::GetTowerInfoRequest, ::Wtclientrpc::Tower
35
+ # Stats returns the in-memory statistics of the client since startup.
36
+ rpc :Stats, ::Wtclientrpc::StatsRequest, ::Wtclientrpc::StatsResponse
37
+ # Policy returns the active watchtower client policy configuration.
38
+ rpc :Policy, ::Wtclientrpc::PolicyRequest, ::Wtclientrpc::PolicyResponse
39
+ end
40
+
41
+ Stub = Service.rpc_stub_class
42
+ end
43
+ end
data/lib/lnrpc.rb CHANGED
@@ -1,10 +1,26 @@
1
- require "lnrpc/version"
2
- require "lnrpc/rpc_services_pb"
1
+ require 'lnrpc/version'
2
+
3
+ # require GRPC services
4
+ Dir[File.join(File.expand_path(File.dirname(__FILE__)), 'grpc_services/**/*_services_pb.rb')].each do |file|
5
+ require file
6
+ end
7
+
8
+ require 'securerandom'
3
9
 
4
10
  module Lnrpc
5
11
  class Error < StandardError; end
6
12
  autoload :Client, 'lnrpc/client'
13
+ autoload :GrpcWrapper, 'lnrpc/grpc_wrapper'
7
14
  autoload :MacaroonInterceptor, 'lnrpc/macaroon_interceptor'
8
- end
9
15
 
16
+ PREIMAGE_BYTE_LENGTH = 32
17
+ KEY_SEND_PREIMAGE_TYPE = 5482373484
18
+
19
+ def self.create_preimage
20
+ SecureRandom.random_bytes(PREIMAGE_BYTE_LENGTH)
21
+ end
10
22
 
23
+ def self.to_byte_array(str)
24
+ [str].pack("H*")
25
+ end
26
+ end
data/lib/lnrpc/client.rb CHANGED
@@ -3,37 +3,18 @@ require "lnrpc/macaroon_interceptor"
3
3
  module Lnrpc
4
4
  class Client
5
5
  attr_accessor :address, :credentials, :macaroon
6
- attr_writer :grpc_client
7
6
 
8
7
  LND_HOME_DIR = ENV['LND_HOME'] || "~/.lnd"
9
8
  DEFAULT_ADDRESS = 'localhost:10009'
10
9
  DEFAULT_CREDENTIALS_PATH = "#{LND_HOME_DIR}/tls.cert"
11
10
  DEFAULT_MACAROON_PATH = "#{LND_HOME_DIR}/data/chain/bitcoin/mainnet/admin.macaroon"
12
11
 
13
- NON_CONVENTION_REQUEST_CLASSES = {
14
- add_invoice: Lnrpc::Invoice,
15
- send_payment: Lnrpc::SendRequest,
16
- send_payment_sync: Lnrpc::SendRequest,
17
- open_channel_sync: Lnrpc::OpenChannelRequest,
18
- send_to_route_sync: Lnrpc::SendToRouteRequest,
19
- lookup_invoice: Lnrpc::PaymentHash,
20
- decode_pay_req: Lnrpc::PayReqString,
21
- describe_graph: Lnrpc::ChannelGraphRequest,
22
- get_chan_info: Lnrpc::ChanInfoRequest,
23
- get_node_info: Lnrpc::NodeInfoRequest,
24
- get_network_info: Lnrpc::NetworkInfoRequest,
25
- stop_daemon: Lnrpc::StopRequest,
26
- update_channel_policy: Lnrpc::PolicyUpdateResponse,
27
- subscribe_channel_graph: Lnrpc::GraphTopologySubscription,
28
- subscribe_invoices: Lnrpc::InvoiceSubscription,
29
- subscribe_transactions: Lnrpc::GetTransactionsRequest
30
- }
31
-
32
12
  def initialize(options={})
33
13
  self.address = options[:address] || DEFAULT_ADDRESS
34
14
 
35
15
  if options.has_key?(:credentials)
36
- self.credentials = options[:credentials]
16
+ # if there are non hex values prvided we assume it's the certificate file as string otherwise we assume it's the hex value
17
+ self.credentials = options[:credentials].match?(/\H/) ? options[:credentials] : [options[:credentials]].pack('H*')
37
18
  elsif File.exists?(::File.expand_path(options[:credentials_path] || DEFAULT_CREDENTIALS_PATH))
38
19
  self.credentials = ::File.read(::File.expand_path(options[:credentials_path] || DEFAULT_CREDENTIALS_PATH))
39
20
  else
@@ -46,42 +27,77 @@ module Lnrpc
46
27
  self.macaroon = options[:macaroon]
47
28
  end
48
29
 
49
- def grpc_client
50
- @grpc_client ||= Lnrpc::Lightning::Stub.new(self.address,
51
- GRPC::Core::ChannelCredentials.new(self.credentials),
52
- interceptors: [Lnrpc::MacaroonInterceptor.new(self.macaroon)]
53
- )
30
+ def lightning
31
+ @lightning ||= grpc_wrapper_for(Lnrpc::Lightning)
54
32
  end
55
33
 
56
- def pay(payreq)
57
- self.send_payment_sync(Lnrpc::SendRequest.new(payment_request: payreq))
34
+ def autopilot
35
+ @autopilot ||= grpc_wrapper_for(Autopilotrpc::Autopilot)
58
36
  end
59
37
 
60
- def method_missing(m, *args, &block)
61
- if self.grpc_client.respond_to?(m)
62
- params = args[0]
38
+ def chain_notifier
39
+ @chain_notifier ||= grpc_wrapper_for(Chainrpc::ChainNotifier)
40
+ end
63
41
 
64
- args[0] = params.nil? ? request_class_for(m).new : request_class_for(m).new(params)
65
- self.grpc_client.send(m, *args, &block)
66
- else
67
- super
68
- end
42
+ def invoices
43
+ @invoices ||= grpc_wrapper_for(Invoicesrpc::Invoices)
44
+ end
45
+
46
+ def router
47
+ @router ||= grpc_wrapper_for(Routerrpc::Router)
48
+ end
49
+
50
+ def signer
51
+ @signer ||= grpc_wrapper_for(Signrpc::Signer)
52
+ end
53
+
54
+ def versioner
55
+ @versioner ||= grpc_wrapper_for(Verrpc::Versioner)
56
+ end
57
+
58
+ def wallet_kit
59
+ @wallet_kit ||= grpc_wrapper_for(Walletrpc::WalletKit)
60
+ end
61
+
62
+ def wallet_unlocker
63
+ @wallet_unlocker ||= grpc_wrapper_for(Lnrpc::WalletUnlocker)
64
+ end
65
+
66
+ def watchtower
67
+ @watchtower ||= grpc_wrapper_for(Watchtowerrpc::Watchtower)
68
+ end
69
+
70
+ def watchtower_client
71
+ @watchtower_client ||= grpc_wrapper_for(Wtclientrpc::WatchtowerClient)
72
+ end
73
+
74
+ def keysend(args)
75
+ args[:dest_custom_records] ||= {}
76
+ args[:dest_custom_records][Lnrpc::KEY_SEND_PREIMAGE_TYPE] ||= Lnrpc.create_preimage
77
+ args[:payment_hash] ||= Digest::SHA256.digest(args[:dest_custom_records][Lnrpc::KEY_SEND_PREIMAGE_TYPE])
78
+ args[:timeout_seconds] ||= 60
79
+ router.send_payment_v2(args)
80
+ end
81
+
82
+ def pay(args)
83
+ args[:timeout_seconds] ||= 60
84
+ router.send_payment_v2(args)
69
85
  end
70
86
 
71
87
  def inspect
72
- "#{self.to_s} @address=\"#{self.address}\""
88
+ "#{self} @address=\"#{address}\""
73
89
  end
74
90
 
75
91
  private
76
- def request_class_for(method_name)
77
- if NON_CONVENTION_REQUEST_CLASSES.key?(method_name.to_sym)
78
- NON_CONVENTION_REQUEST_CLASSES[method_name.to_sym]
79
- else
80
- klass = method_name.to_s.sub(/^[a-z\d]*/) { |match| match.capitalize }
81
- klass.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
82
- Lnrpc.const_get("#{klass}Request")
83
- end
92
+
93
+ def grpc_wrapper_for(grpc_module)
94
+ stub = grpc_module.const_get(:Stub)
95
+ service = grpc_module.const_get(:Service)
96
+ GrpcWrapper.new(service: service,
97
+ grpc: stub.new(address,
98
+ GRPC::Core::ChannelCredentials.new(credentials),
99
+ interceptors: [Lnrpc::MacaroonInterceptor.new(macaroon)]
100
+ ))
84
101
  end
85
102
  end
86
103
  end
87
-