mirror of
https://github.com/bumi/lnrpc
synced 2024-06-03 21:09:06 +00:00
Merge 9b1499616d
into 449696fbb6
This commit is contained in:
commit
58260c7e35
|
@ -11,6 +11,7 @@ module Lnrpc
|
||||||
class Error < StandardError; end
|
class Error < StandardError; end
|
||||||
autoload :Client, 'lnrpc/client'
|
autoload :Client, 'lnrpc/client'
|
||||||
autoload :GrpcWrapper, 'lnrpc/grpc_wrapper'
|
autoload :GrpcWrapper, 'lnrpc/grpc_wrapper'
|
||||||
|
autoload :PaymentResponse, 'lnrpc/payment_response'
|
||||||
autoload :MacaroonInterceptor, 'lnrpc/macaroon_interceptor'
|
autoload :MacaroonInterceptor, 'lnrpc/macaroon_interceptor'
|
||||||
|
|
||||||
PREIMAGE_BYTE_LENGTH = 32
|
PREIMAGE_BYTE_LENGTH = 32
|
||||||
|
|
|
@ -77,12 +77,12 @@ module Lnrpc
|
||||||
args[:dest_custom_records][Lnrpc::KEY_SEND_PREIMAGE_TYPE] ||= Lnrpc.create_preimage
|
args[:dest_custom_records][Lnrpc::KEY_SEND_PREIMAGE_TYPE] ||= Lnrpc.create_preimage
|
||||||
args[:payment_hash] ||= Digest::SHA256.digest(args[:dest_custom_records][Lnrpc::KEY_SEND_PREIMAGE_TYPE])
|
args[:payment_hash] ||= Digest::SHA256.digest(args[:dest_custom_records][Lnrpc::KEY_SEND_PREIMAGE_TYPE])
|
||||||
args[:timeout_seconds] ||= 60
|
args[:timeout_seconds] ||= 60
|
||||||
router.send_payment_v2(args)
|
PaymentResponse.new(router.send_payment_v2(args))
|
||||||
end
|
end
|
||||||
|
|
||||||
def pay(args)
|
def pay(args)
|
||||||
args[:timeout_seconds] ||= 60
|
args[:timeout_seconds] ||= 60
|
||||||
router.send_payment_v2(args)
|
PaymentResponse.new(router.send_payment_v2(args))
|
||||||
end
|
end
|
||||||
|
|
||||||
def inspect
|
def inspect
|
||||||
|
|
30
lib/lnrpc/payment_response.rb
Normal file
30
lib/lnrpc/payment_response.rb
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
module Lnrpc
|
||||||
|
class PaymentResponse
|
||||||
|
attr_reader :grpc_response, :exception
|
||||||
|
|
||||||
|
def initialize(send_payment_response)
|
||||||
|
@grpc_response = send_payment_response
|
||||||
|
end
|
||||||
|
|
||||||
|
def states
|
||||||
|
@states ||= response_array.map(&:status)
|
||||||
|
end
|
||||||
|
|
||||||
|
def success?
|
||||||
|
return false if exception
|
||||||
|
|
||||||
|
@success ||= states.include?(:SUCCEEDED)
|
||||||
|
end
|
||||||
|
|
||||||
|
def fee
|
||||||
|
@fee ||= response_array.sum(&:fee)
|
||||||
|
end
|
||||||
|
|
||||||
|
def response_array
|
||||||
|
@response_array ||= @grpc_response.to_a
|
||||||
|
rescue GRPC::BadStatus => e
|
||||||
|
@exception = e
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user