mirror of https://github.com/bumi/lnrpc
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_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={})
|
||||
self.address = options[:address] || DEFAULT_ADDRESS
|
||||
|
||||
|
@ -40,9 +59,13 @@ module Lnrpc
|
|||
|
||||
private
|
||||
def request_class_for(method_name)
|
||||
string = method_name.to_s.sub(/^[a-z\d]*/) { |match| match.capitalize }
|
||||
string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
|
||||
Lnrpc.const_get("#{string}Request")
|
||||
if NON_CONVENTION_REQUEST_CLASSES.key?(method_name.to_sym)
|
||||
NON_CONVENTION_REQUEST_CLASSES[method_name.to_sym]
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue