mirror of
https://github.com/bumi/lnrpc
synced 2025-07-14 15:11:47 +00:00
Add shortcut support for non convention requests
This commit is contained in:
parent
950e233f73
commit
85c50c4b9b
@ -7,6 +7,25 @@ module Lnrpc
|
|||||||
DEFAULT_CREDENTIALS_PATH = "#{LND_HOME_DIR}/tls.cert"
|
DEFAULT_CREDENTIALS_PATH = "#{LND_HOME_DIR}/tls.cert"
|
||||||
DEFAULT_MACAROON_PATH = "#{LND_HOME_DIR}/data/chain/bitcoin/mainnet/admin.macaroon"
|
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
|
||||||
|
}
|
||||||
|
|
||||||
def initialize(options={})
|
def initialize(options={})
|
||||||
self.address = options[:address] || DEFAULT_ADDRESS
|
self.address = options[:address] || DEFAULT_ADDRESS
|
||||||
|
|
||||||
@ -40,9 +59,13 @@ module Lnrpc
|
|||||||
|
|
||||||
private
|
private
|
||||||
def request_class_for(method_name)
|
def request_class_for(method_name)
|
||||||
string = method_name.to_s.sub(/^[a-z\d]*/) { |match| match.capitalize }
|
if NON_CONVENTION_REQUEST_CLASSES.key?(method_name.to_sym)
|
||||||
string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
|
NON_CONVENTION_REQUEST_CLASSES[method_name.to_sym]
|
||||||
Lnrpc.const_get("#{string}Request")
|
else
|
||||||
|
klass = method_name.to_s.sub(/^[a-z\d]*/) { |match| match.capitalize }
|
||||||
|
klass.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
|
||||||
|
Lnrpc.const_get("#{klass}Request")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user