history check
This commit is contained in:
parent
421873a7de
commit
2cc4a3d0c7
20 changed files with 5230 additions and 4714 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -17,3 +17,4 @@ data/
|
|||
.admin_enroll
|
||||
admin.npub
|
||||
app.nprofile
|
||||
.admin_connect
|
||||
|
|
@ -125,6 +125,11 @@ The nostr server will send back a message response, and inside the body there wi
|
|||
- input: [PayInvoiceRequest](#PayInvoiceRequest)
|
||||
- output: [PayInvoiceResponse](#PayInvoiceResponse)
|
||||
|
||||
- GetPaymentState
|
||||
- auth type: __User__
|
||||
- input: [GetPaymentStateRequest](#GetPaymentStateRequest)
|
||||
- output: [PaymentState](#PaymentState)
|
||||
|
||||
- OpenChannel
|
||||
- auth type: __User__
|
||||
- input: [OpenChannelRequest](#OpenChannelRequest)
|
||||
|
|
@ -193,8 +198,8 @@ The nostr server will send back a message response, and inside the body there wi
|
|||
|
||||
- __GuestWithPub__:
|
||||
- expected context content
|
||||
- __app_id__: _string_
|
||||
- __pub__: _string_
|
||||
- __app_id__: _string_
|
||||
|
||||
## HTTP Methods
|
||||
### These are the http methods the client implements to communicate with the API
|
||||
|
|
@ -516,6 +521,13 @@ The nostr server will send back a message response, and inside the body there wi
|
|||
- input: [PayInvoiceRequest](#PayInvoiceRequest)
|
||||
- output: [PayInvoiceResponse](#PayInvoiceResponse)
|
||||
|
||||
- GetPaymentState
|
||||
- auth type: __User__
|
||||
- http method: __post__
|
||||
- http route: __/api/user/payment/state__
|
||||
- input: [GetPaymentStateRequest](#GetPaymentStateRequest)
|
||||
- output: [PaymentState](#PaymentState)
|
||||
|
||||
- OpenChannel
|
||||
- auth type: __User__
|
||||
- http method: __post__
|
||||
|
|
@ -577,187 +589,49 @@ The nostr server will send back a message response, and inside the body there wi
|
|||
## Messages
|
||||
### The content of requests and response from the methods
|
||||
|
||||
### AuthApp
|
||||
- __auth_token__: _string_
|
||||
- __app__: _[Application](#Application)_
|
||||
### LnurlPayInfoResponse
|
||||
- __allowsNostr__: _boolean_
|
||||
- __nostrPubkey__: _string_
|
||||
- __tag__: _string_
|
||||
- __callback__: _string_
|
||||
- __maxSendable__: _number_
|
||||
- __minSendable__: _number_
|
||||
- __metadata__: _string_
|
||||
|
||||
### UserInfo
|
||||
- __balance__: _number_
|
||||
- __max_withdrawable__: _number_
|
||||
- __user_identifier__: _string_
|
||||
- __service_fee_bps__: _number_
|
||||
- __network_max_fee_bps__: _number_
|
||||
- __network_max_fee_fixed__: _number_
|
||||
- __userId__: _string_
|
||||
|
||||
### UserOperations
|
||||
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
|
||||
- __fromIndex__: _number_
|
||||
- __toIndex__: _number_
|
||||
|
||||
### CreateOneTimeInviteLinkResponse
|
||||
- __invitation_link__: _string_
|
||||
|
||||
### LndGetInfoRequest
|
||||
- __nodeId__: _number_
|
||||
|
||||
### Application
|
||||
- __npub__: _string_
|
||||
- __name__: _string_
|
||||
- __id__: _string_
|
||||
- __balance__: _number_
|
||||
|
||||
### LiveUserOperation
|
||||
- __operation__: _[UserOperation](#UserOperation)_
|
||||
|
||||
### UsageMetric
|
||||
- __auth_in_nano__: _number_
|
||||
- __validate_in_nano__: _number_
|
||||
- __handle_in_nano__: _number_
|
||||
- __batch__: _boolean_
|
||||
- __nostr__: _boolean_
|
||||
- __batch_size__: _number_
|
||||
- __processed_at_ms__: _number_
|
||||
- __rpc_name__: _string_
|
||||
- __parsed_in_nano__: _number_
|
||||
|
||||
### Product
|
||||
- __id__: _string_
|
||||
- __name__: _string_
|
||||
- __price_sats__: _number_
|
||||
### GetUserOperationsResponse
|
||||
- __latestIncomingTxOperations__: _[UserOperations](#UserOperations)_
|
||||
- __latestOutgoingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
|
||||
- __latestIncomingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
|
||||
- __latestOutgoingInvoiceOperations__: _[UserOperations](#UserOperations)_
|
||||
- __latestIncomingInvoiceOperations__: _[UserOperations](#UserOperations)_
|
||||
- __latestOutgoingTxOperations__: _[UserOperations](#UserOperations)_
|
||||
|
||||
### RequestNPubLinkingTokenResponse
|
||||
- __token__: _string_
|
||||
|
||||
### EnrollAdminTokenRequest
|
||||
- __admin_token__: _string_
|
||||
### LndGetInfoResponse
|
||||
- __alias__: _string_
|
||||
|
||||
### UsersInfo
|
||||
- __no_balance__: _number_
|
||||
- __negative_balance__: _number_
|
||||
- __always_been_inactive__: _number_
|
||||
- __balance_avg__: _number_
|
||||
- __balance_median__: _number_
|
||||
- __total__: _number_
|
||||
### NewAddressResponse
|
||||
- __address__: _string_
|
||||
|
||||
### MigrationUpdate
|
||||
- __relays__: _[RelaysMigration](#RelaysMigration)_ *this field is optional
|
||||
- __closure__: _[ClosureMigration](#ClosureMigration)_ *this field is optional
|
||||
|
||||
### SetMockInvoiceAsPaidRequest
|
||||
- __invoice__: _string_
|
||||
### PayInvoiceRequest
|
||||
- __amount__: _number_
|
||||
|
||||
### BannedAppUser
|
||||
- __app_name__: _string_
|
||||
- __app_id__: _string_
|
||||
- __user_identifier__: _string_
|
||||
- __nostr_pub__: _string_
|
||||
|
||||
### AppUser
|
||||
- __identifier__: _string_
|
||||
- __info__: _[UserInfo](#UserInfo)_
|
||||
- __max_withdrawable__: _number_
|
||||
|
||||
### PayAddressResponse
|
||||
- __service_fee__: _number_
|
||||
- __network_fee__: _number_
|
||||
- __txId__: _string_
|
||||
- __operation_id__: _string_
|
||||
|
||||
### UserOperation
|
||||
- __inbound__: _boolean_
|
||||
- __confirmed__: _boolean_
|
||||
- __tx_hash__: _string_
|
||||
- __paidAtUnix__: _number_
|
||||
- __type__: _[UserOperationType](#UserOperationType)_
|
||||
- __operationId__: _string_
|
||||
- __service_fee__: _number_
|
||||
- __network_fee__: _number_
|
||||
- __internal__: _boolean_
|
||||
- __amount__: _number_
|
||||
- __identifier__: _string_
|
||||
|
||||
### AddProductRequest
|
||||
- __name__: _string_
|
||||
- __price_sats__: _number_
|
||||
|
||||
### AppMetrics
|
||||
- __users__: _[UsersInfo](#UsersInfo)_
|
||||
- __spent__: _number_
|
||||
- __fees__: _number_
|
||||
- __invoices__: _number_
|
||||
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
|
||||
- __app__: _[Application](#Application)_
|
||||
- __received__: _number_
|
||||
- __available__: _number_
|
||||
- __total_fees__: _number_
|
||||
|
||||
### LndMetricsRequest
|
||||
- __from_unix__: _number_ *this field is optional
|
||||
- __to_unix__: _number_ *this field is optional
|
||||
|
||||
### PayAppUserInvoiceRequest
|
||||
- __user_identifier__: _string_
|
||||
- __invoice__: _string_
|
||||
- __amount__: _number_
|
||||
|
||||
### SendAppUserToAppUserPaymentRequest
|
||||
- __from_user_identifier__: _string_
|
||||
- __to_user_identifier__: _string_
|
||||
- __amount__: _number_
|
||||
|
||||
### GetAppUserLNURLInfoRequest
|
||||
- __user_identifier__: _string_
|
||||
- __base_url_override__: _string_
|
||||
|
||||
### SetMockAppBalanceRequest
|
||||
- __amount__: _number_
|
||||
|
||||
### NewInvoiceResponse
|
||||
- __invoice__: _string_
|
||||
|
||||
### BanUserResponse
|
||||
- __balance_sats__: _number_
|
||||
- __banned_app_users__: ARRAY of: _[BannedAppUser](#BannedAppUser)_
|
||||
|
||||
### AddAppUserInvoiceRequest
|
||||
- __receiver_identifier__: _string_
|
||||
- __payer_identifier__: _string_
|
||||
- __http_callback_url__: _string_
|
||||
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
|
||||
|
||||
### UseInviteLinkRequest
|
||||
- __invite_token__: _string_
|
||||
|
||||
### LndMetrics
|
||||
- __nodes__: ARRAY of: _[LndNodeMetrics](#LndNodeMetrics)_
|
||||
|
||||
### AddAppUserRequest
|
||||
- __identifier__: _string_
|
||||
- __fail_if_exists__: _boolean_
|
||||
- __balance__: _number_
|
||||
|
||||
### ChainBalanceEvent
|
||||
- __total_balance__: _number_
|
||||
- __block_height__: _number_
|
||||
- __confirmed_balance__: _number_
|
||||
- __unconfirmed_balance__: _number_
|
||||
|
||||
### GetInviteTokenStateResponse
|
||||
- __used__: _boolean_
|
||||
|
||||
### NewAddressRequest
|
||||
- __addressType__: _[AddressType](#AddressType)_
|
||||
|
||||
### HandleLnurlPayResponse
|
||||
- __pr__: _string_
|
||||
- __routes__: ARRAY of: _[Empty](#Empty)_
|
||||
|
||||
### AppsMetricsRequest
|
||||
- __from_unix__: _number_ *this field is optional
|
||||
- __to_unix__: _number_ *this field is optional
|
||||
- __include_operations__: _boolean_ *this field is optional
|
||||
### RoutingEvent
|
||||
- __failure_string__: _string_
|
||||
- __settled__: _boolean_
|
||||
- __offchain__: _boolean_
|
||||
- __timestamp_ns__: _number_
|
||||
- __incoming_amt_msat__: _number_
|
||||
- __outgoing_amt_msat__: _number_
|
||||
- __outgoing_htlc_id__: _number_
|
||||
- __event_type__: _string_
|
||||
- __forward_fail_event__: _boolean_
|
||||
- __incoming_channel_id__: _number_
|
||||
- __incoming_htlc_id__: _number_
|
||||
- __outgoing_channel_id__: _number_
|
||||
|
||||
### ChannelBalanceEvent
|
||||
- __block_height__: _number_
|
||||
|
|
@ -765,125 +639,144 @@ The nostr server will send back a message response, and inside the body there wi
|
|||
- __local_balance_sats__: _number_
|
||||
- __remote_balance_sats__: _number_
|
||||
|
||||
### GetAppUserRequest
|
||||
- __user_identifier__: _string_
|
||||
### AddAppRequest
|
||||
- __name__: _string_
|
||||
- __allow_user_creation__: _boolean_
|
||||
|
||||
### PayInvoiceRequest
|
||||
- __invoice__: _string_
|
||||
### LndGetInfoRequest
|
||||
- __nodeId__: _number_
|
||||
|
||||
### AddAppUserRequest
|
||||
- __identifier__: _string_
|
||||
- __fail_if_exists__: _boolean_
|
||||
- __balance__: _number_
|
||||
|
||||
### SetMockAppBalanceRequest
|
||||
- __amount__: _number_
|
||||
|
||||
### OpenChannelResponse
|
||||
- __channelId__: _string_
|
||||
### GetPaymentStateRequest
|
||||
- __invoice__: _string_
|
||||
|
||||
### GetUserOperationsResponse
|
||||
- __latestOutgoingInvoiceOperations__: _[UserOperations](#UserOperations)_
|
||||
- __latestIncomingInvoiceOperations__: _[UserOperations](#UserOperations)_
|
||||
- __latestOutgoingTxOperations__: _[UserOperations](#UserOperations)_
|
||||
- __latestIncomingTxOperations__: _[UserOperations](#UserOperations)_
|
||||
- __latestOutgoingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
|
||||
- __latestIncomingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
|
||||
|
||||
### Empty
|
||||
### HttpCreds
|
||||
- __token__: _string_
|
||||
- __url__: _string_
|
||||
|
||||
### UsageMetrics
|
||||
- __metrics__: ARRAY of: _[UsageMetric](#UsageMetric)_
|
||||
|
||||
### RequestNPubLinkingTokenRequest
|
||||
### AppMetrics
|
||||
- __app__: _[Application](#Application)_
|
||||
- __spent__: _number_
|
||||
- __available__: _number_
|
||||
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
|
||||
- __users__: _[UsersInfo](#UsersInfo)_
|
||||
- __received__: _number_
|
||||
- __fees__: _number_
|
||||
- __invoices__: _number_
|
||||
- __total_fees__: _number_
|
||||
|
||||
### LndMetricsRequest
|
||||
- __from_unix__: _number_ *this field is optional
|
||||
- __to_unix__: _number_ *this field is optional
|
||||
|
||||
### UseInviteLinkRequest
|
||||
- __invite_token__: _string_
|
||||
|
||||
### UserInfo
|
||||
- __user_identifier__: _string_
|
||||
- __service_fee_bps__: _number_
|
||||
- __network_max_fee_bps__: _number_
|
||||
- __network_max_fee_fixed__: _number_
|
||||
- __userId__: _string_
|
||||
- __balance__: _number_
|
||||
- __max_withdrawable__: _number_
|
||||
|
||||
### UserOperations
|
||||
- __fromIndex__: _number_
|
||||
- __toIndex__: _number_
|
||||
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
|
||||
|
||||
### GetInviteTokenStateRequest
|
||||
- __invite_token__: _string_
|
||||
|
||||
### HttpCreds
|
||||
- __url__: _string_
|
||||
- __token__: _string_
|
||||
### UsageMetric
|
||||
- __parsed_in_nano__: _number_
|
||||
- __handle_in_nano__: _number_
|
||||
- __batch__: _boolean_
|
||||
- __nostr__: _boolean_
|
||||
- __processed_at_ms__: _number_
|
||||
- __auth_in_nano__: _number_
|
||||
- __validate_in_nano__: _number_
|
||||
- __rpc_name__: _string_
|
||||
- __batch_size__: _number_
|
||||
|
||||
### AppUser
|
||||
- __identifier__: _string_
|
||||
- __info__: _[UserInfo](#UserInfo)_
|
||||
- __max_withdrawable__: _number_
|
||||
|
||||
### SendAppUserToAppUserPaymentRequest
|
||||
- __amount__: _number_
|
||||
- __from_user_identifier__: _string_
|
||||
- __to_user_identifier__: _string_
|
||||
|
||||
### Application
|
||||
- __id__: _string_
|
||||
- __balance__: _number_
|
||||
- __npub__: _string_
|
||||
- __name__: _string_
|
||||
|
||||
### DecodeInvoiceRequest
|
||||
- __invoice__: _string_
|
||||
|
||||
### LnurlWithdrawInfoResponse
|
||||
- __maxWithdrawable__: _number_
|
||||
- __balanceCheck__: _string_
|
||||
- __payLink__: _string_
|
||||
- __tag__: _string_
|
||||
- __callback__: _string_
|
||||
- __k1__: _string_
|
||||
- __defaultDescription__: _string_
|
||||
- __minWithdrawable__: _number_
|
||||
|
||||
### GetUserOperationsRequest
|
||||
- __latestIncomingTx__: _number_
|
||||
- __latestOutgoingTx__: _number_
|
||||
- __latestIncomingUserToUserPayment__: _number_
|
||||
- __latestOutgoingUserToUserPayment__: _number_
|
||||
- __max_size__: _number_
|
||||
- __latestIncomingInvoice__: _number_
|
||||
- __latestOutgoingInvoice__: _number_
|
||||
|
||||
### EncryptionExchangeRequest
|
||||
- __publicKey__: _string_
|
||||
- __deviceId__: _string_
|
||||
|
||||
### LnurlPayInfoResponse
|
||||
- __tag__: _string_
|
||||
- __callback__: _string_
|
||||
- __maxSendable__: _number_
|
||||
- __minSendable__: _number_
|
||||
- __metadata__: _string_
|
||||
- __allowsNostr__: _boolean_
|
||||
- __nostrPubkey__: _string_
|
||||
### AppsMetrics
|
||||
- __apps__: ARRAY of: _[AppMetrics](#AppMetrics)_
|
||||
|
||||
### AuthAppRequest
|
||||
- __name__: _string_
|
||||
- __allow_user_creation__: _boolean_ *this field is optional
|
||||
|
||||
### SetMockAppUserBalanceRequest
|
||||
### PayAppUserInvoiceRequest
|
||||
- __user_identifier__: _string_
|
||||
- __amount__: _number_
|
||||
|
||||
### DecodeInvoiceRequest
|
||||
- __invoice__: _string_
|
||||
|
||||
### DecodeInvoiceResponse
|
||||
- __amount__: _number_
|
||||
|
||||
### LnurlWithdrawInfoResponse
|
||||
- __callback__: _string_
|
||||
- __k1__: _string_
|
||||
- __defaultDescription__: _string_
|
||||
- __minWithdrawable__: _number_
|
||||
- __maxWithdrawable__: _number_
|
||||
- __balanceCheck__: _string_
|
||||
- __payLink__: _string_
|
||||
- __tag__: _string_
|
||||
|
||||
### ChannelRouting
|
||||
- __receive_errors__: _number_
|
||||
- __forward_errors_as_input__: _number_
|
||||
- __forward_fee_as_output__: _number_
|
||||
- __channel_id__: _string_
|
||||
- __send_errors__: _number_
|
||||
- __missed_forward_fee_as_output__: _number_
|
||||
- __forward_fee_as_input__: _number_
|
||||
- __events_number__: _number_
|
||||
- __forward_errors_as_output__: _number_
|
||||
- __missed_forward_fee_as_input__: _number_
|
||||
|
||||
### LndNodeMetrics
|
||||
- __chain_balance_events__: ARRAY of: _[ChainBalanceEvent](#ChainBalanceEvent)_
|
||||
- __closing_channels__: _number_
|
||||
- __channel_routing__: ARRAY of: _[ChannelRouting](#ChannelRouting)_
|
||||
- __channels_balance_events__: ARRAY of: _[ChannelBalanceEvent](#ChannelBalanceEvent)_
|
||||
- __offline_channels__: _number_
|
||||
- __online_channels__: _number_
|
||||
- __pending_channels__: _number_
|
||||
- __open_channels__: ARRAY of: _[OpenChannel](#OpenChannel)_
|
||||
- __closed_channels__: ARRAY of: _[ClosedChannel](#ClosedChannel)_
|
||||
|
||||
### GetProductBuyLinkResponse
|
||||
- __link__: _string_
|
||||
|
||||
### CreateOneTimeInviteLinkRequest
|
||||
- __sats__: _number_ *this field is optional
|
||||
|
||||
### SendAppUserToAppPaymentRequest
|
||||
- __from_user_identifier__: _string_
|
||||
- __amount__: _number_
|
||||
|
||||
### OpenChannelRequest
|
||||
- __pushAmount__: _number_
|
||||
- __closeAddress__: _string_
|
||||
- __destination__: _string_
|
||||
- __fundingAmount__: _number_
|
||||
### GetAppUserLNURLInfoRequest
|
||||
- __user_identifier__: _string_
|
||||
- __base_url_override__: _string_
|
||||
|
||||
### LndGetInfoResponse
|
||||
- __alias__: _string_
|
||||
### RequestNPubLinkingTokenRequest
|
||||
- __user_identifier__: _string_
|
||||
|
||||
### AddAppInvoiceRequest
|
||||
- __payer_identifier__: _string_
|
||||
- __http_callback_url__: _string_
|
||||
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
|
||||
|
||||
### NewAddressResponse
|
||||
- __address__: _string_
|
||||
### LinkNPubThroughTokenRequest
|
||||
- __token__: _string_
|
||||
|
||||
### OpenChannel
|
||||
- __channel_id__: _string_
|
||||
|
|
@ -893,72 +786,200 @@ The nostr server will send back a message response, and inside the body there wi
|
|||
- __local_balance__: _number_
|
||||
- __remote_balance__: _number_
|
||||
|
||||
### ClosedChannel
|
||||
### BanUserResponse
|
||||
- __banned_app_users__: ARRAY of: _[BannedAppUser](#BannedAppUser)_
|
||||
- __balance_sats__: _number_
|
||||
|
||||
### AuthApp
|
||||
- __app__: _[Application](#Application)_
|
||||
- __auth_token__: _string_
|
||||
|
||||
### EnrollAdminTokenRequest
|
||||
- __admin_token__: _string_
|
||||
|
||||
### PayAddressResponse
|
||||
- __txId__: _string_
|
||||
- __operation_id__: _string_
|
||||
- __service_fee__: _number_
|
||||
- __network_fee__: _number_
|
||||
|
||||
### OpenChannelResponse
|
||||
- __channelId__: _string_
|
||||
|
||||
### AddAppUserInvoiceRequest
|
||||
- __payer_identifier__: _string_
|
||||
- __http_callback_url__: _string_
|
||||
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
|
||||
- __receiver_identifier__: _string_
|
||||
|
||||
### DecodeInvoiceResponse
|
||||
- __amount__: _number_
|
||||
|
||||
### HandleLnurlPayResponse
|
||||
- __pr__: _string_
|
||||
- __routes__: ARRAY of: _[Empty](#Empty)_
|
||||
|
||||
### GetProductBuyLinkResponse
|
||||
- __link__: _string_
|
||||
|
||||
### AppsMetricsRequest
|
||||
- __to_unix__: _number_ *this field is optional
|
||||
- __include_operations__: _boolean_ *this field is optional
|
||||
- __from_unix__: _number_ *this field is optional
|
||||
|
||||
### ChannelRouting
|
||||
- __send_errors__: _number_
|
||||
- __receive_errors__: _number_
|
||||
- __forward_errors_as_input__: _number_
|
||||
- __missed_forward_fee_as_input__: _number_
|
||||
- __forward_fee_as_input__: _number_
|
||||
- __forward_fee_as_output__: _number_
|
||||
- __channel_id__: _string_
|
||||
- __capacity__: _number_
|
||||
- __closed_height__: _number_
|
||||
- __forward_errors_as_output__: _number_
|
||||
- __missed_forward_fee_as_output__: _number_
|
||||
- __events_number__: _number_
|
||||
|
||||
### LndMetrics
|
||||
- __nodes__: ARRAY of: _[LndNodeMetrics](#LndNodeMetrics)_
|
||||
|
||||
### NewAddressRequest
|
||||
- __addressType__: _[AddressType](#AddressType)_
|
||||
|
||||
### PayAddressRequest
|
||||
- __satsPerVByte__: _number_
|
||||
- __address__: _string_
|
||||
- __amoutSats__: _number_
|
||||
|
||||
### PaymentState
|
||||
- __service_fee__: _number_
|
||||
- __network_fee__: _number_
|
||||
- __paid_at_unix__: _number_
|
||||
- __amount__: _number_
|
||||
|
||||
### OpenChannelRequest
|
||||
- __closeAddress__: _string_
|
||||
- __destination__: _string_
|
||||
- __fundingAmount__: _number_
|
||||
- __pushAmount__: _number_
|
||||
|
||||
### CreateOneTimeInviteLinkRequest
|
||||
- __sats__: _number_ *this field is optional
|
||||
|
||||
### GetInviteTokenStateResponse
|
||||
- __used__: _boolean_
|
||||
|
||||
### BannedAppUser
|
||||
- __app_name__: _string_
|
||||
- __app_id__: _string_
|
||||
- __user_identifier__: _string_
|
||||
- __nostr_pub__: _string_
|
||||
|
||||
### AddAppInvoiceRequest
|
||||
- __payer_identifier__: _string_
|
||||
- __http_callback_url__: _string_
|
||||
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
|
||||
|
||||
### SetMockAppUserBalanceRequest
|
||||
- __user_identifier__: _string_
|
||||
- __amount__: _number_
|
||||
|
||||
### ClosureMigration
|
||||
- __closes_at_unix__: _number_
|
||||
|
||||
### RelaysMigration
|
||||
- __relays__: ARRAY of: _string_
|
||||
|
||||
### AppsMetrics
|
||||
- __apps__: ARRAY of: _[AppMetrics](#AppMetrics)_
|
||||
|
||||
### LnurlLinkResponse
|
||||
- __k1__: _string_
|
||||
- __lnurl__: _string_
|
||||
|
||||
### AddAppRequest
|
||||
- __name__: _string_
|
||||
- __allow_user_creation__: _boolean_
|
||||
|
||||
### PayAddressRequest
|
||||
- __address__: _string_
|
||||
- __amoutSats__: _number_
|
||||
- __satsPerVByte__: _number_
|
||||
|
||||
### NewInvoiceRequest
|
||||
- __amountSats__: _number_
|
||||
- __memo__: _string_
|
||||
|
||||
### PayInvoiceResponse
|
||||
- __amount_paid__: _number_
|
||||
- __operation_id__: _string_
|
||||
### UserOperation
|
||||
- __internal__: _boolean_
|
||||
- __type__: _[UserOperationType](#UserOperationType)_
|
||||
- __amount__: _number_
|
||||
- __identifier__: _string_
|
||||
- __service_fee__: _number_
|
||||
- __confirmed__: _boolean_
|
||||
- __paidAtUnix__: _number_
|
||||
- __inbound__: _boolean_
|
||||
- __operationId__: _string_
|
||||
- __network_fee__: _number_
|
||||
- __preimage__: _string_
|
||||
- __tx_hash__: _string_
|
||||
|
||||
### LinkNPubThroughTokenRequest
|
||||
- __token__: _string_
|
||||
### Product
|
||||
- __id__: _string_
|
||||
- __name__: _string_
|
||||
- __price_sats__: _number_
|
||||
|
||||
### RoutingEvent
|
||||
- __incoming_amt_msat__: _number_
|
||||
- __offchain__: _boolean_
|
||||
- __forward_fail_event__: _boolean_
|
||||
- __outgoing_channel_id__: _number_
|
||||
- __outgoing_htlc_id__: _number_
|
||||
- __timestamp_ns__: _number_
|
||||
- __outgoing_amt_msat__: _number_
|
||||
- __failure_string__: _string_
|
||||
- __settled__: _boolean_
|
||||
- __incoming_channel_id__: _number_
|
||||
- __incoming_htlc_id__: _number_
|
||||
- __event_type__: _string_
|
||||
### GetAppUserRequest
|
||||
- __user_identifier__: _string_
|
||||
|
||||
### MigrationUpdate
|
||||
- __closure__: _[ClosureMigration](#ClosureMigration)_ *this field is optional
|
||||
- __relays__: _[RelaysMigration](#RelaysMigration)_ *this field is optional
|
||||
|
||||
### CreateOneTimeInviteLinkResponse
|
||||
- __invitation_link__: _string_
|
||||
|
||||
### Empty
|
||||
|
||||
### ClosedChannel
|
||||
- __channel_id__: _string_
|
||||
- __capacity__: _number_
|
||||
- __closed_height__: _number_
|
||||
|
||||
### BanUserRequest
|
||||
- __user_id__: _string_
|
||||
|
||||
### GetUserOperationsRequest
|
||||
- __latestIncomingUserToUserPayment__: _number_
|
||||
- __latestOutgoingUserToUserPayment__: _number_
|
||||
- __max_size__: _number_
|
||||
- __latestIncomingInvoice__: _number_
|
||||
- __latestOutgoingInvoice__: _number_
|
||||
- __latestIncomingTx__: _number_
|
||||
- __latestOutgoingTx__: _number_
|
||||
### LiveUserOperation
|
||||
- __operation__: _[UserOperation](#UserOperation)_
|
||||
|
||||
### ClosureMigration
|
||||
- __closes_at_unix__: _number_
|
||||
### ChainBalanceEvent
|
||||
- __block_height__: _number_
|
||||
- __confirmed_balance__: _number_
|
||||
- __unconfirmed_balance__: _number_
|
||||
- __total_balance__: _number_
|
||||
|
||||
### LndNodeMetrics
|
||||
- __online_channels__: _number_
|
||||
- __closing_channels__: _number_
|
||||
- __open_channels__: ARRAY of: _[OpenChannel](#OpenChannel)_
|
||||
- __closed_channels__: ARRAY of: _[ClosedChannel](#ClosedChannel)_
|
||||
- __channel_routing__: ARRAY of: _[ChannelRouting](#ChannelRouting)_
|
||||
- __channels_balance_events__: ARRAY of: _[ChannelBalanceEvent](#ChannelBalanceEvent)_
|
||||
- __offline_channels__: _number_
|
||||
- __chain_balance_events__: ARRAY of: _[ChainBalanceEvent](#ChainBalanceEvent)_
|
||||
- __pending_channels__: _number_
|
||||
|
||||
### AddProductRequest
|
||||
- __name__: _string_
|
||||
- __price_sats__: _number_
|
||||
|
||||
### PayInvoiceResponse
|
||||
- __preimage__: _string_
|
||||
- __amount_paid__: _number_
|
||||
- __operation_id__: _string_
|
||||
- __service_fee__: _number_
|
||||
- __network_fee__: _number_
|
||||
|
||||
### LnurlLinkResponse
|
||||
- __lnurl__: _string_
|
||||
- __k1__: _string_
|
||||
|
||||
### UsersInfo
|
||||
- __always_been_inactive__: _number_
|
||||
- __balance_avg__: _number_
|
||||
- __balance_median__: _number_
|
||||
- __total__: _number_
|
||||
- __no_balance__: _number_
|
||||
- __negative_balance__: _number_
|
||||
|
||||
### SetMockInvoiceAsPaidRequest
|
||||
- __invoice__: _string_
|
||||
- __amount__: _number_
|
||||
|
||||
### NewInvoiceResponse
|
||||
- __invoice__: _string_
|
||||
## Enums
|
||||
### The enumerators used in the messages
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -947,6 +947,28 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
|||
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
||||
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
||||
})
|
||||
if (!opts.allowNotImplementedMethods && !methods.GetPaymentState) throw new Error('method: GetPaymentState is not implemented')
|
||||
app.post('/api/user/payment/state', async (req, res) => {
|
||||
const info: Types.RequestInfo = { rpcName: 'GetPaymentState', batch: false, nostr: false, batchSize: 0}
|
||||
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
||||
let authCtx: Types.AuthContext = {}
|
||||
try {
|
||||
if (!methods.GetPaymentState) throw new Error('method: GetPaymentState is not implemented')
|
||||
const authContext = await opts.UserAuthGuard(req.headers['authorization'])
|
||||
authCtx = authContext
|
||||
stats.guard = process.hrtime.bigint()
|
||||
const request = req.body
|
||||
const error = Types.GetPaymentStateRequestValidate(request)
|
||||
stats.validate = process.hrtime.bigint()
|
||||
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
||||
const query = req.query
|
||||
const params = req.params
|
||||
const response = await methods.GetPaymentState({rpcName:'GetPaymentState', ctx:authContext , req: request})
|
||||
stats.handle = process.hrtime.bigint()
|
||||
res.json({status: 'OK', ...response})
|
||||
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
||||
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
||||
})
|
||||
if (!opts.allowNotImplementedMethods && !methods.OpenChannel) throw new Error('method: OpenChannel is not implemented')
|
||||
app.post('/api/user/open/channel', async (req, res) => {
|
||||
const info: Types.RequestInfo = { rpcName: 'OpenChannel', batch: false, nostr: false, batchSize: 0}
|
||||
|
|
@ -1173,6 +1195,18 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
|||
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
||||
}
|
||||
break
|
||||
case 'GetPaymentState':
|
||||
if (!methods.GetPaymentState) {
|
||||
throw new Error('method GetPaymentState not found' )
|
||||
} else {
|
||||
const error = Types.GetPaymentStateRequestValidate(operation.req)
|
||||
opStats.validate = process.hrtime.bigint()
|
||||
if (error !== null) throw error
|
||||
const res = await methods.GetPaymentState({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
||||
opStats.handle = process.hrtime.bigint()
|
||||
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
||||
}
|
||||
break
|
||||
case 'OpenChannel':
|
||||
if (!methods.OpenChannel) {
|
||||
throw new Error('method OpenChannel not found' )
|
||||
|
|
|
|||
|
|
@ -594,6 +594,20 @@ export default (params: ClientParams) => ({
|
|||
}
|
||||
return { status: 'ERROR', reason: 'invalid response' }
|
||||
},
|
||||
GetPaymentState: async (request: Types.GetPaymentStateRequest): Promise<ResultError | ({ status: 'OK' }& Types.PaymentState)> => {
|
||||
const auth = await params.retrieveUserAuth()
|
||||
if (auth === null) throw new Error('retrieveUserAuth() returned null')
|
||||
let finalRoute = '/api/user/payment/state'
|
||||
const { data } = await axios.post(params.baseUrl + finalRoute, request, { headers: { 'authorization': auth } })
|
||||
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||
if (data.status === 'OK') {
|
||||
const result = data
|
||||
if(!params.checkResult) return { status: 'OK', ...result }
|
||||
const error = Types.PaymentStateValidate(result)
|
||||
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
|
||||
}
|
||||
return { status: 'ERROR', reason: 'invalid response' }
|
||||
},
|
||||
OpenChannel: async (request: Types.OpenChannelRequest): Promise<ResultError | ({ status: 'OK' }& Types.OpenChannelResponse)> => {
|
||||
const auth = await params.retrieveUserAuth()
|
||||
if (auth === null) throw new Error('retrieveUserAuth() returned null')
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@ export type ResultError = { status: 'ERROR', reason: string }
|
|||
|
||||
export type NostrClientParams = {
|
||||
pubDestination: string
|
||||
retrieveNostrGuestWithPubAuth: () => Promise<string | null>
|
||||
retrieveNostrAdminAuth: () => Promise<string | null>
|
||||
retrieveNostrMetricsAuth: () => Promise<string | null>
|
||||
retrieveNostrUserAuth: () => Promise<string | null>
|
||||
retrieveNostrGuestWithPubAuth: () => Promise<string | null>
|
||||
checkResult?: true
|
||||
}
|
||||
export default (params: NostrClientParams, send: (to:string, message: NostrRequest) => Promise<any>, subscribe: (to:string, message: NostrRequest, cb:(res:any)=> void) => void) => ({
|
||||
|
|
@ -327,6 +327,21 @@ export default (params: NostrClientParams, send: (to:string, message: NostrRequ
|
|||
}
|
||||
return { status: 'ERROR', reason: 'invalid response' }
|
||||
},
|
||||
GetPaymentState: async (request: Types.GetPaymentStateRequest): Promise<ResultError | ({ status: 'OK' }& Types.PaymentState)> => {
|
||||
const auth = await params.retrieveNostrUserAuth()
|
||||
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
|
||||
const nostrRequest: NostrRequest = {}
|
||||
nostrRequest.body = request
|
||||
const data = await send(params.pubDestination, {rpcName:'GetPaymentState',authIdentifier:auth, ...nostrRequest })
|
||||
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||
if (data.status === 'OK') {
|
||||
const result = data
|
||||
if(!params.checkResult) return { status: 'OK', ...result }
|
||||
const error = Types.PaymentStateValidate(result)
|
||||
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
|
||||
}
|
||||
return { status: 'ERROR', reason: 'invalid response' }
|
||||
},
|
||||
OpenChannel: async (request: Types.OpenChannelRequest): Promise<ResultError | ({ status: 'OK' }& Types.OpenChannelResponse)> => {
|
||||
const auth = await params.retrieveNostrUserAuth()
|
||||
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
|
||||
|
|
|
|||
|
|
@ -372,6 +372,22 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
|||
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
||||
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
||||
break
|
||||
case 'GetPaymentState':
|
||||
try {
|
||||
if (!methods.GetPaymentState) throw new Error('method: GetPaymentState is not implemented')
|
||||
const authContext = await opts.NostrUserAuthGuard(req.appId, req.authIdentifier)
|
||||
stats.guard = process.hrtime.bigint()
|
||||
authCtx = authContext
|
||||
const request = req.body
|
||||
const error = Types.GetPaymentStateRequestValidate(request)
|
||||
stats.validate = process.hrtime.bigint()
|
||||
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback)
|
||||
const response = await methods.GetPaymentState({rpcName:'GetPaymentState', ctx:authContext , req: request})
|
||||
stats.handle = process.hrtime.bigint()
|
||||
res({status: 'OK', ...response})
|
||||
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
||||
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
||||
break
|
||||
case 'OpenChannel':
|
||||
try {
|
||||
if (!methods.OpenChannel) throw new Error('method: OpenChannel is not implemented')
|
||||
|
|
@ -611,6 +627,18 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
|||
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
||||
}
|
||||
break
|
||||
case 'GetPaymentState':
|
||||
if (!methods.GetPaymentState) {
|
||||
throw new Error('method not defined: GetPaymentState')
|
||||
} else {
|
||||
const error = Types.GetPaymentStateRequestValidate(operation.req)
|
||||
opStats.validate = process.hrtime.bigint()
|
||||
if (error !== null) throw error
|
||||
const res = await methods.GetPaymentState({...operation, ctx}); responses.push({ status: 'OK', ...res })
|
||||
opStats.handle = process.hrtime.bigint()
|
||||
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
||||
}
|
||||
break
|
||||
case 'OpenChannel':
|
||||
if (!methods.OpenChannel) {
|
||||
throw new Error('method not defined: OpenChannel')
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -387,6 +387,13 @@ service LightningPub {
|
|||
option (nostr) = true;
|
||||
}
|
||||
|
||||
rpc GetPaymentState(structs.GetPaymentStateRequest) returns (structs.PaymentState){
|
||||
option (auth_type) = "User";
|
||||
option (http_method) = "post";
|
||||
option (http_route) = "/api/user/payment/state";
|
||||
option (nostr) = true;
|
||||
}
|
||||
|
||||
rpc OpenChannel(structs.OpenChannelRequest) returns (structs.OpenChannelResponse){
|
||||
option (auth_type) = "User";
|
||||
option (http_method) = "post";
|
||||
|
|
|
|||
|
|
@ -304,6 +304,18 @@ message PayInvoiceResponse{
|
|||
int64 network_fee = 5;
|
||||
}
|
||||
|
||||
message GetPaymentStateRequest{
|
||||
string invoice = 1;
|
||||
|
||||
}
|
||||
|
||||
message PaymentState{
|
||||
int64 paid_at_unix = 1;
|
||||
int64 amount = 2;
|
||||
int64 service_fee = 3;
|
||||
int64 network_fee = 4;
|
||||
}
|
||||
|
||||
message OpenChannelRequest{
|
||||
string destination = 1;
|
||||
int64 fundingAmount = 2;
|
||||
|
|
|
|||
|
|
@ -298,7 +298,7 @@ export default class {
|
|||
const r = res.response
|
||||
return { local: r.localBalance ? Number(r.localBalance.sat) : 0, remote: r.remoteBalance ? Number(r.remoteBalance.sat) : 0 }
|
||||
}
|
||||
async PayInvoice(invoice: string, amount: number, feeLimit: number, decodedAmount: number, { useProvider, from }: TxActionOptions): Promise<PaidInvoice> {
|
||||
async PayInvoice(invoice: string, amount: number, feeLimit: number, decodedAmount: number, { useProvider, from }: TxActionOptions, paymentIndexCb?: (index: number) => void): Promise<PaidInvoice> {
|
||||
if (this.outgoingOpsLocked) {
|
||||
this.log("outgoing ops locked, rejecting payment request")
|
||||
throw new Error("lnd node is currently out of sync")
|
||||
|
|
@ -318,8 +318,13 @@ export default class {
|
|||
this.log("invoice payment failed", error)
|
||||
rej(error)
|
||||
})
|
||||
let indexSent = false
|
||||
stream.responses.onMessage(payment => {
|
||||
console.log("payment", payment)
|
||||
const indexNum = Number(payment.paymentIndex)
|
||||
if (!indexSent && indexNum > 0) {
|
||||
indexSent = true
|
||||
paymentIndexCb?.(Number(payment.paymentIndex))
|
||||
}
|
||||
switch (payment.status) {
|
||||
case Payment_PaymentStatus.FAILED:
|
||||
this.log("invoice payment failed", payment.failureReason)
|
||||
|
|
@ -427,6 +432,25 @@ export default class {
|
|||
return res.response
|
||||
}
|
||||
|
||||
async GetPayment(paymentIndex: number) {
|
||||
const indexOffset = BigInt(paymentIndex - 1)
|
||||
const res = await this.lightning.listPayments({
|
||||
countTotalPayments: false, includeIncomplete: true, indexOffset, maxPayments: 1n, reversed: false
|
||||
}, DeadLineMetadata())
|
||||
return res.response
|
||||
}
|
||||
|
||||
async GetLatestPaymentIndex(from = 0) {
|
||||
let indexOffset = BigInt(from)
|
||||
while (true) {
|
||||
const res = await this.lightning.listPayments({ countTotalPayments: false, includeIncomplete: false, indexOffset, maxPayments: 0n, reversed: false }, DeadLineMetadata())
|
||||
if (res.response.payments.length === 0) {
|
||||
return Number(indexOffset)
|
||||
}
|
||||
indexOffset = res.response.lastIndexOffset
|
||||
}
|
||||
}
|
||||
|
||||
async ConnectPeer(addr: { pubkey: string, host: string }) {
|
||||
const res = await this.lightning.connectPeer({
|
||||
addr,
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ export const initMainHandler = async (log: PubLogger, mainSettings: MainSettings
|
|||
if (stop) {
|
||||
return
|
||||
}
|
||||
mainHandler.paymentManager.checkPendingPayments()
|
||||
mainHandler.paymentManager.watchDog.Start()
|
||||
return { mainHandler, apps, liquidityProviderInfo, liquidityProviderApp, wizard, adminManager }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -212,6 +212,18 @@ export class LiquidityProvider {
|
|||
}
|
||||
}
|
||||
|
||||
GetPaymentState = async (invoice: string) => {
|
||||
if (!this.ready) {
|
||||
throw new Error("liquidity provider is not ready yet")
|
||||
}
|
||||
const res = await this.client.GetPaymentState({ invoice })
|
||||
if (res.status === 'ERROR') {
|
||||
this.log("error getting payment state", res.reason)
|
||||
throw new Error(res.reason)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
GetOperations = async () => {
|
||||
if (!this.ready) {
|
||||
throw new Error("liquidity provider is not ready yet")
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ import { MainSettings } from './settings.js'
|
|||
import { InboundOptionals, defaultInvoiceExpiry } from '../storage/paymentStorage.js'
|
||||
import LND from '../lnd/lnd.js'
|
||||
import { Application } from '../storage/entity/Application.js'
|
||||
import { getLogger } from '../helpers/logger.js'
|
||||
import { getLogger, PubLogger } from '../helpers/logger.js'
|
||||
import { UserReceivingAddress } from '../storage/entity/UserReceivingAddress.js'
|
||||
import { AddressPaidCb, InvoicePaidCb, PaidInvoice } from '../lnd/settings.js'
|
||||
import { UserReceivingInvoice, ZapInfo } from '../storage/entity/UserReceivingInvoice.js'
|
||||
import { SendCoinsResponse } from '../../../proto/lnd/lightning.js'
|
||||
import { Payment_PaymentStatus, SendCoinsResponse } from '../../../proto/lnd/lightning.js'
|
||||
import { Event, verifiedSymbol, verifySignature } from '../nostr/tools/event.js'
|
||||
import { AddressReceivingTransaction } from '../storage/entity/AddressReceivingTransaction.js'
|
||||
import { UserTransactionPayment } from '../storage/entity/UserTransactionPayment.js'
|
||||
|
|
@ -66,6 +66,122 @@ export default class {
|
|||
this.watchDog.Stop()
|
||||
}
|
||||
|
||||
checkPendingPayments = async () => {
|
||||
const log = getLogger({ component: 'pendingPaymentsOnStart' })
|
||||
const pendingPayments = await this.storage.paymentStorage.GetPendingPayments()
|
||||
for (const p of pendingPayments) {
|
||||
if (p.internal) {
|
||||
log("found pending internal payment", p.serial_id)
|
||||
return
|
||||
} else if (p.liquidityProvider) {
|
||||
log("found pending liquidity provider payment", p.serial_id)
|
||||
await this.checkPendingProviderPayment(log, p)
|
||||
return
|
||||
} else {
|
||||
log("found pending external payment", p.serial_id)
|
||||
await this.checkPendingLndPayment(log, p)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
checkPendingProviderPayment = async (log: PubLogger, p: UserInvoicePayment) => {
|
||||
const state = await this.lnd.liquidProvider.GetPaymentState(p.invoice)
|
||||
if (state.paid_at_unix < 0) {
|
||||
const fullAmount = p.paid_amount + p.service_fees + p.routing_fees
|
||||
log("found a failed provider payment, refunding", fullAmount, "sats to user", p.user.user_id)
|
||||
await this.storage.txQueue.PushToQueue({
|
||||
dbTx: true, description: "refund failed provider payment", exec: async tx => {
|
||||
await this.storage.userStorage.IncrementUserBalance(p.user.user_id, fullAmount, "payment_refund:" + p.invoice, tx)
|
||||
await this.storage.paymentStorage.UpdateExternalPayment(p.serial_id, 0, 0, false)
|
||||
}
|
||||
})
|
||||
return
|
||||
} else if (state.paid_at_unix > 0) {
|
||||
log("provider payment succeeded", p.serial_id, "updating payment info")
|
||||
const routingFeeLimit = p.routing_fees
|
||||
const serviceFee = p.service_fees
|
||||
const actualFee = state.network_fee + state.service_fee
|
||||
await this.storage.txQueue.PushToQueue({
|
||||
dbTx: true, description: "pending provider payment success after restart", exec: async tx => {
|
||||
if (routingFeeLimit - actualFee > 0) {
|
||||
this.log("refund pending provider payment routing fee", routingFeeLimit, actualFee, "sats")
|
||||
await this.storage.userStorage.IncrementUserBalance(p.user.user_id, routingFeeLimit - actualFee, "routing_fee_refund:" + p.invoice)
|
||||
}
|
||||
await this.storage.paymentStorage.UpdateExternalPayment(p.serial_id, actualFee, p.service_fees, true)
|
||||
}
|
||||
})
|
||||
if (p.linkedApplication && p.user.user_id !== p.linkedApplication.owner.user_id && serviceFee > 0) {
|
||||
await this.storage.userStorage.IncrementUserBalance(p.linkedApplication.owner.user_id, serviceFee, "fees")
|
||||
}
|
||||
const user = await this.storage.userStorage.GetUser(p.user.user_id)
|
||||
this.storage.eventsLog.LogEvent({ type: 'invoice_payment', userId: p.user.user_id, appId: p.linkedApplication?.app_id || "", appUserId: "", balance: user.balance_sats, data: p.invoice, amount: p.paid_amount })
|
||||
return
|
||||
}
|
||||
log("provider payment still pending", p.serial_id, "no action will be performed")
|
||||
|
||||
|
||||
}
|
||||
|
||||
checkPendingLndPayment = async (log: PubLogger, p: UserInvoicePayment) => {
|
||||
if (p.paymentIndex === 0) {
|
||||
const fullAmount = p.paid_amount + p.service_fees + p.routing_fees
|
||||
log("found a pending payment with no payment index, refunding", fullAmount, "sats to user", p.user.user_id)
|
||||
await this.storage.txQueue.PushToQueue({
|
||||
dbTx: true, description: "refund failed pending payment", exec: async tx => {
|
||||
await this.storage.userStorage.IncrementUserBalance(p.user.user_id, fullAmount, "payment_refund:" + p.invoice, tx)
|
||||
await this.storage.paymentStorage.UpdateExternalPayment(p.serial_id, 0, 0, false)
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
const paymentRes = await this.lnd.GetPayment(p.paymentIndex)
|
||||
const payment = paymentRes.payments[0]
|
||||
if (!payment || Number(payment.paymentIndex) !== p.paymentIndex) {
|
||||
log("lnd payment not found for pending payment", p.serial_id, "with index", p.paymentIndex)
|
||||
return
|
||||
}
|
||||
|
||||
switch (payment.status) {
|
||||
case Payment_PaymentStatus.UNKNOWN:
|
||||
log("pending payment in unknown state", p.serial_id, "no action will be performed")
|
||||
return
|
||||
case Payment_PaymentStatus.IN_FLIGHT:
|
||||
log("pending payment in flight", p.serial_id, "no action will be performed")
|
||||
return
|
||||
case Payment_PaymentStatus.SUCCEEDED:
|
||||
log("pending payment succeeded", p.serial_id, "updating payment info")
|
||||
const routingFeeLimit = p.routing_fees
|
||||
const serviceFee = p.service_fees
|
||||
const actualFee = Number(payment.feeSat)
|
||||
await this.storage.txQueue.PushToQueue({
|
||||
dbTx: true, description: "pending payment success after restart", exec: async tx => {
|
||||
if (routingFeeLimit - actualFee > 0) {
|
||||
this.log("refund pending payment routing fee", routingFeeLimit, actualFee, "sats")
|
||||
await this.storage.userStorage.IncrementUserBalance(p.user.user_id, routingFeeLimit - actualFee, "routing_fee_refund:" + p.invoice)
|
||||
}
|
||||
await this.storage.paymentStorage.UpdateExternalPayment(p.serial_id, actualFee, p.service_fees, true)
|
||||
}
|
||||
})
|
||||
if (p.linkedApplication && p.user.user_id !== p.linkedApplication.owner.user_id && serviceFee > 0) {
|
||||
await this.storage.userStorage.IncrementUserBalance(p.linkedApplication.owner.user_id, serviceFee, "fees")
|
||||
}
|
||||
const user = await this.storage.userStorage.GetUser(p.user.user_id)
|
||||
this.storage.eventsLog.LogEvent({ type: 'invoice_payment', userId: p.user.user_id, appId: p.linkedApplication?.app_id || "", appUserId: "", balance: user.balance_sats, data: p.invoice, amount: p.paid_amount })
|
||||
return
|
||||
case Payment_PaymentStatus.FAILED:
|
||||
const fullAmount = p.paid_amount + p.service_fees + p.routing_fees
|
||||
log("found a failed pending payment, refunding", fullAmount, "sats to user", p.user.user_id)
|
||||
await this.storage.txQueue.PushToQueue({
|
||||
dbTx: true, description: "refund failed pending payment", exec: async tx => {
|
||||
await this.storage.userStorage.IncrementUserBalance(p.user.user_id, fullAmount, "payment_refund:" + p.invoice, tx)
|
||||
await this.storage.paymentStorage.UpdateExternalPayment(p.serial_id, 0, 0, false)
|
||||
}
|
||||
})
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
getServiceFee(action: Types.UserOperationType, amount: number, appUser: boolean): number {
|
||||
switch (action) {
|
||||
case Types.UserOperationType.INCOMING_TX:
|
||||
|
|
@ -214,25 +330,29 @@ export default class {
|
|||
const { amountForLnd, payAmount, serviceFee } = amounts
|
||||
const totalAmountToDecrement = payAmount + serviceFee
|
||||
const routingFeeLimit = this.lnd.GetFeeLimitAmount(payAmount)
|
||||
await this.storage.userStorage.DecrementUserBalance(userId, totalAmountToDecrement + routingFeeLimit, invoice)
|
||||
let pendingPayment: UserInvoicePayment | null = null
|
||||
const use = await this.liquidityManager.beforeOutInvoicePayment(payAmount)
|
||||
const provider = use === 'provider' ? this.lnd.liquidProvider.GetProviderDestination() : undefined
|
||||
const pendingPayment = await this.storage.txQueue.PushToQueue({
|
||||
dbTx: true, description: "payment started", exec: async tx => {
|
||||
await this.storage.userStorage.DecrementUserBalance(userId, totalAmountToDecrement + routingFeeLimit, invoice, tx)
|
||||
return await this.storage.paymentStorage.AddPendingExternalPayment(userId, invoice, { payAmount, serviceFee, networkFee: routingFeeLimit }, linkedApplication, provider)
|
||||
}
|
||||
})
|
||||
try {
|
||||
pendingPayment = await this.storage.paymentStorage.AddPendingExternalPayment(userId, invoice, payAmount, linkedApplication)
|
||||
const use = await this.liquidityManager.beforeOutInvoicePayment(payAmount)
|
||||
const payment = await this.lnd.PayInvoice(invoice, amountForLnd, routingFeeLimit, payAmount, { useProvider: use === 'provider', from: 'user' })
|
||||
const payment = await this.lnd.PayInvoice(invoice, amountForLnd, routingFeeLimit, payAmount, { useProvider: use === 'provider', from: 'user' }, index => {
|
||||
this.storage.paymentStorage.SetExternalPaymentIndex(pendingPayment.serial_id, index)
|
||||
})
|
||||
if (routingFeeLimit - payment.feeSat > 0) {
|
||||
this.log("refund routing fee", routingFeeLimit, payment.feeSat, "sats")
|
||||
await this.storage.userStorage.IncrementUserBalance(userId, routingFeeLimit - payment.feeSat, "routing_fee_refund:" + invoice)
|
||||
}
|
||||
await this.storage.paymentStorage.UpdateExternalPayment(pendingPayment.serial_id, payment.feeSat, serviceFee, true, payment.providerDst)
|
||||
|
||||
await this.storage.paymentStorage.UpdateExternalPayment(pendingPayment.serial_id, payment.feeSat, serviceFee, true, payment.providerDst)
|
||||
return { preimage: payment.paymentPreimage, amtPaid: payment.valueSat, networkFee: payment.feeSat, serialId: pendingPayment.serial_id }
|
||||
|
||||
} catch (err) {
|
||||
await this.storage.userStorage.IncrementUserBalance(userId, totalAmountToDecrement + routingFeeLimit, "payment_refund:" + invoice)
|
||||
if (pendingPayment) {
|
||||
await this.storage.paymentStorage.UpdateExternalPayment(pendingPayment.serial_id, 0, 0, false)
|
||||
}
|
||||
await this.storage.paymentStorage.UpdateExternalPayment(pendingPayment.serial_id, 0, 0, false)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
|
@ -557,6 +677,23 @@ export default class {
|
|||
}
|
||||
}
|
||||
|
||||
async GetPaymentState(userId: string, req: Types.GetPaymentStateRequest): Promise<Types.PaymentState> {
|
||||
const user = await this.storage.userStorage.GetUser(userId)
|
||||
if (user.locked) {
|
||||
throw new Error("user is banned, cannot retrieve payment state")
|
||||
}
|
||||
const invoice = await this.storage.paymentStorage.GetPaymentOwner(req.invoice)
|
||||
if (!invoice || invoice.user.user_id !== userId) {
|
||||
throw new Error("invoice not found")
|
||||
}
|
||||
return {
|
||||
paid_at_unix: invoice.paid_at_unix,
|
||||
amount: invoice.paid_amount,
|
||||
network_fee: invoice.routing_fees,
|
||||
service_fee: invoice.service_fees,
|
||||
}
|
||||
}
|
||||
|
||||
async GetUserOperations(userId: string, req: Types.GetUserOperationsRequest): Promise<Types.GetUserOperationsResponse> {
|
||||
const user = await this.storage.userStorage.GetUser(userId)
|
||||
if (user.locked) {
|
||||
|
|
|
|||
|
|
@ -21,8 +21,9 @@ export class Watchdog {
|
|||
initialLndBalance: number;
|
||||
initialUsersBalance: number;
|
||||
startedAtUnix: number;
|
||||
latestIndexOffset: number;
|
||||
latestHtlcIndexOffset: number;
|
||||
accumulatedHtlcFees: number;
|
||||
latestPaymentIndexOffset: number;
|
||||
lnd: LND;
|
||||
liquidProvider: LiquidityProvider;
|
||||
liquidityManager: LiquidityManager;
|
||||
|
|
@ -71,10 +72,13 @@ export class Watchdog {
|
|||
this.initialLndBalance = totalExternal
|
||||
this.initialUsersBalance = totalUsersBalance
|
||||
const fwEvents = await this.lnd.GetForwardingHistory(0, this.startedAtUnix)
|
||||
this.latestIndexOffset = fwEvents.lastOffsetIndex
|
||||
this.latestHtlcIndexOffset = fwEvents.lastOffsetIndex
|
||||
this.accumulatedHtlcFees = 0
|
||||
const paymentFound = await this.storage.paymentStorage.GetMaxPaymentIndex()
|
||||
const knownMaxIndex = paymentFound.length > 0 ? paymentFound[0].paymentIndex : 0
|
||||
this.latestPaymentIndexOffset = await this.lnd.GetLatestPaymentIndex(knownMaxIndex)
|
||||
const other = { ilnd: this.initialLndBalance, hf: this.accumulatedHtlcFees, iu: this.initialUsersBalance, tu: totalUsersBalance, oext: otherExternal }
|
||||
getLogger({ component: 'watchdog_debug2' })(JSON.stringify({ deltaLnd: 0, deltaUsers: 0, totalExternal, other }))
|
||||
getLogger({ component: 'watchdog_debug2' })(JSON.stringify({ deltaLnd: 0, deltaUsers: 0, totalExternal, latestIndex: this.latestPaymentIndexOffset, other }))
|
||||
this.interval = setInterval(() => {
|
||||
if (this.latestCheckStart + (1000 * 58) < Date.now()) {
|
||||
this.PaymentRequested()
|
||||
|
|
@ -85,8 +89,8 @@ export class Watchdog {
|
|||
}
|
||||
|
||||
updateAccumulatedHtlcFees = async () => {
|
||||
const fwEvents = await this.lnd.GetForwardingHistory(this.latestIndexOffset, this.startedAtUnix)
|
||||
this.latestIndexOffset = fwEvents.lastOffsetIndex
|
||||
const fwEvents = await this.lnd.GetForwardingHistory(this.latestHtlcIndexOffset, this.startedAtUnix)
|
||||
this.latestHtlcIndexOffset = fwEvents.lastOffsetIndex
|
||||
fwEvents.forwardingEvents.forEach((event) => {
|
||||
this.accumulatedHtlcFees += Number(event.fee)
|
||||
})
|
||||
|
|
@ -115,6 +119,7 @@ export class Watchdog {
|
|||
return true
|
||||
}
|
||||
} else {
|
||||
this.log("WARNING! LND balance increased more than users balance with a difference of", result.absoluteDiff, "sats")
|
||||
this.updateDisruption(false, result.absoluteDiff)
|
||||
return false
|
||||
}
|
||||
|
|
@ -129,6 +134,7 @@ export class Watchdog {
|
|||
await this.updateDisruption(false, 0)
|
||||
return false
|
||||
} else {
|
||||
this.log("WARNING! LND balance decreased less than users balance with a difference of", result.absoluteDiff, "sats")
|
||||
await this.updateDisruption(false, result.absoluteDiff)
|
||||
return false
|
||||
}
|
||||
|
|
@ -179,14 +185,22 @@ export class Watchdog {
|
|||
this.utils.stateBundler.AddBalancePoint('accumulatedHtlcFees', this.accumulatedHtlcFees)
|
||||
const deltaLnd = totalExternal - (this.initialLndBalance + this.accumulatedHtlcFees)
|
||||
const deltaUsers = totalUsersBalance - this.initialUsersBalance
|
||||
const other = { ilnd: this.initialLndBalance, hf: this.accumulatedHtlcFees, iu: this.initialUsersBalance, tu: totalUsersBalance, oext: otherExternal }
|
||||
const paymentFound = await this.storage.paymentStorage.GetMaxPaymentIndex()
|
||||
const maxFromDb = paymentFound.length > 0 ? paymentFound[0].paymentIndex : 0
|
||||
const knownMaxIndex = Math.max(maxFromDb, this.latestPaymentIndexOffset)
|
||||
const newLatest = await this.lnd.GetLatestPaymentIndex(knownMaxIndex)
|
||||
const historyMismatch = newLatest > knownMaxIndex
|
||||
const other = { ilnd: this.initialLndBalance, hf: this.accumulatedHtlcFees, iu: this.initialUsersBalance, tu: totalUsersBalance, km: knownMaxIndex, nl: newLatest, oext: otherExternal }
|
||||
getLogger({ component: 'watchdog_debug2' })(JSON.stringify({ deltaLnd, deltaUsers, totalExternal, other }))
|
||||
const deny = await this.checkBalanceUpdate(deltaLnd, deltaUsers)
|
||||
if (deny) {
|
||||
this.log("Balance mismatch detected in absolute update, locking outgoing operations")
|
||||
if (historyMismatch) {
|
||||
this.log("History mismatch detected in absolute update, locking outgoing operations")
|
||||
this.lnd.LockOutgoingOperations()
|
||||
return
|
||||
}
|
||||
if (deny) {
|
||||
this.log("Balance mismatch detected in absolute update, but history is ok")
|
||||
}
|
||||
this.lnd.UnlockOutgoingOperations()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,6 +38,13 @@ export default (mainHandler: Main): Types.ServerMethods => {
|
|||
GetUserOperations: async ({ ctx, req }) => {
|
||||
return mainHandler.paymentManager.GetUserOperations(ctx.user_id, req)
|
||||
},
|
||||
GetPaymentState: async ({ ctx, req }) => {
|
||||
const err = Types.GetPaymentStateRequestValidate(req, {
|
||||
invoice_CustomCheck: invoice => invoice !== ""
|
||||
})
|
||||
if (err != null) throw new Error(err.message)
|
||||
return mainHandler.paymentManager.GetPaymentState(ctx.user_id, req)
|
||||
},
|
||||
OpenChannel: async ({ ctx, req }) => {
|
||||
const err = Types.OpenChannelRequestValidate(req, {
|
||||
fundingAmount_CustomCheck: amt => amt > 0,
|
||||
|
|
|
|||
|
|
@ -39,6 +39,11 @@ export class UserInvoicePayment {
|
|||
})
|
||||
liquidityProvider?: string
|
||||
|
||||
@Column({
|
||||
default: 0,
|
||||
})
|
||||
paymentIndex: number
|
||||
|
||||
@CreateDateColumn()
|
||||
created_at: Date
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class PaymentIndex1721760297610 implements MigrationInterface {
|
||||
name = 'PaymentIndex1721760297610'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP INDEX "IDX_a609a4d3d8d9b07b90692a3c45"`);
|
||||
await queryRunner.query(`CREATE TABLE "temporary_user_invoice_payment" ("serial_id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "invoice" varchar NOT NULL, "paid_amount" integer NOT NULL, "routing_fees" integer NOT NULL, "service_fees" integer NOT NULL, "paid_at_unix" integer NOT NULL, "internal" boolean NOT NULL DEFAULT (0), "created_at" datetime NOT NULL DEFAULT (datetime('now')), "updated_at" datetime NOT NULL DEFAULT (datetime('now')), "userSerialId" integer, "linkedApplicationSerialId" integer, "liquidityProvider" varchar, "paymentIndex" integer NOT NULL DEFAULT (-1), CONSTRAINT "FK_ef2aa6761ab681bbbd5f94e0fcb" FOREIGN KEY ("userSerialId") REFERENCES "user" ("serial_id") ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT "FK_6bcac90887eea1dc61d37db2994" FOREIGN KEY ("linkedApplicationSerialId") REFERENCES "application" ("serial_id") ON DELETE NO ACTION ON UPDATE NO ACTION)`);
|
||||
await queryRunner.query(`INSERT INTO "temporary_user_invoice_payment"("serial_id", "invoice", "paid_amount", "routing_fees", "service_fees", "paid_at_unix", "internal", "created_at", "updated_at", "userSerialId", "linkedApplicationSerialId", "liquidityProvider") SELECT "serial_id", "invoice", "paid_amount", "routing_fees", "service_fees", "paid_at_unix", "internal", "created_at", "updated_at", "userSerialId", "linkedApplicationSerialId", "liquidityProvider" FROM "user_invoice_payment"`);
|
||||
await queryRunner.query(`DROP TABLE "user_invoice_payment"`);
|
||||
await queryRunner.query(`ALTER TABLE "temporary_user_invoice_payment" RENAME TO "user_invoice_payment"`);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_a609a4d3d8d9b07b90692a3c45" ON "user_invoice_payment" ("invoice") `);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP INDEX "IDX_a609a4d3d8d9b07b90692a3c45"`);
|
||||
await queryRunner.query(`ALTER TABLE "user_invoice_payment" RENAME TO "temporary_user_invoice_payment"`);
|
||||
await queryRunner.query(`CREATE TABLE "user_invoice_payment" ("serial_id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "invoice" varchar NOT NULL, "paid_amount" integer NOT NULL, "routing_fees" integer NOT NULL, "service_fees" integer NOT NULL, "paid_at_unix" integer NOT NULL, "internal" boolean NOT NULL DEFAULT (0), "created_at" datetime NOT NULL DEFAULT (datetime('now')), "updated_at" datetime NOT NULL DEFAULT (datetime('now')), "userSerialId" integer, "linkedApplicationSerialId" integer, "liquidityProvider" varchar, CONSTRAINT "FK_ef2aa6761ab681bbbd5f94e0fcb" FOREIGN KEY ("userSerialId") REFERENCES "user" ("serial_id") ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT "FK_6bcac90887eea1dc61d37db2994" FOREIGN KEY ("linkedApplicationSerialId") REFERENCES "application" ("serial_id") ON DELETE NO ACTION ON UPDATE NO ACTION)`);
|
||||
await queryRunner.query(`INSERT INTO "user_invoice_payment"("serial_id", "invoice", "paid_amount", "routing_fees", "service_fees", "paid_at_unix", "internal", "created_at", "updated_at", "userSerialId", "linkedApplicationSerialId", "liquidityProvider") SELECT "serial_id", "invoice", "paid_amount", "routing_fees", "service_fees", "paid_at_unix", "internal", "created_at", "updated_at", "userSerialId", "linkedApplicationSerialId", "liquidityProvider" FROM "temporary_user_invoice_payment"`);
|
||||
await queryRunner.query(`DROP TABLE "temporary_user_invoice_payment"`);
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_a609a4d3d8d9b07b90692a3c45" ON "user_invoice_payment" ("invoice") `);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,8 @@ import { LiquidityProvider1719335699480 } from './1719335699480-liquidity_provid
|
|||
import { LndNodeInfo1720187506189 } from './1720187506189-lnd_node_info.js'
|
||||
import { TrackedProvider1720814323679 } from './1720814323679-tracked_provider.js'
|
||||
import { CreateInviteTokenTable1721751414878 } from "./1721751414878-create_invite_token_table.js"
|
||||
const allMigrations = [Initial1703170309875, LspOrder1718387847693, LiquidityProvider1719335699480, LndNodeInfo1720187506189, TrackedProvider1720814323679, CreateInviteTokenTable1721751414878]
|
||||
import { PaymentIndex1721760297610 } from './1721760297610-payment_index.js'
|
||||
const allMigrations = [Initial1703170309875, LspOrder1718387847693, LiquidityProvider1719335699480, LndNodeInfo1720187506189, TrackedProvider1720814323679, CreateInviteTokenTable1721751414878, PaymentIndex1721760297610]
|
||||
const allMetricsMigrations = [LndMetrics1703170330183, ChannelRouting1709316653538]
|
||||
export const TypeOrmMigrationRunner = async (log: PubLogger, storageManager: Storage, settings: DbSettings, arg: string | undefined): Promise<boolean> => {
|
||||
if (arg === 'fake_initial_migration') {
|
||||
|
|
|
|||
|
|
@ -154,20 +154,28 @@ export default class {
|
|||
})
|
||||
}
|
||||
|
||||
async AddPendingExternalPayment(userId: string, invoice: string, amount: number, linkedApplication: Application): Promise<UserInvoicePayment> {
|
||||
async AddPendingExternalPayment(userId: string, invoice: string, amounts: { payAmount: number, serviceFee: number, networkFee: number }, linkedApplication: Application, liquidityProvider: string | undefined): Promise<UserInvoicePayment> {
|
||||
const newPayment = this.DB.getRepository(UserInvoicePayment).create({
|
||||
user: await this.userStorage.GetUser(userId),
|
||||
paid_amount: amount,
|
||||
paid_amount: amounts.payAmount,
|
||||
invoice,
|
||||
routing_fees: 0,
|
||||
service_fees: 0,
|
||||
routing_fees: amounts.networkFee,
|
||||
service_fees: amounts.serviceFee,
|
||||
paid_at_unix: 0,
|
||||
internal: false,
|
||||
linkedApplication
|
||||
linkedApplication,
|
||||
liquidityProvider
|
||||
})
|
||||
return this.txQueue.PushToQueue<UserInvoicePayment>({ exec: async db => db.getRepository(UserInvoicePayment).save(newPayment), dbTx: false, description: `add pending invoice payment for ${userId} linked to ${linkedApplication.app_id}: ${invoice}, amt: ${amount} ` })
|
||||
return this.txQueue.PushToQueue<UserInvoicePayment>({ exec: async db => db.getRepository(UserInvoicePayment).save(newPayment), dbTx: false, description: `add pending invoice payment for ${userId} linked to ${linkedApplication.app_id}: ${invoice}, amt: ${amounts.payAmount} ` })
|
||||
}
|
||||
|
||||
async GetMaxPaymentIndex(entityManager = this.DB) {
|
||||
return entityManager.getRepository(UserInvoicePayment).find({ order: { paymentIndex: 'DESC' }, take: 1 })
|
||||
}
|
||||
|
||||
async SetExternalPaymentIndex(invoicePaymentSerialId: number, index: number, entityManager = this.DB) {
|
||||
return entityManager.getRepository(UserInvoicePayment).update(invoicePaymentSerialId, { paymentIndex: index })
|
||||
}
|
||||
async UpdateExternalPayment(invoicePaymentSerialId: number, routingFees: number, serviceFees: number, success: boolean, providerDestination?: string) {
|
||||
return this.DB.getRepository(UserInvoicePayment).update(invoicePaymentSerialId, {
|
||||
routing_fees: routingFees,
|
||||
|
|
@ -416,4 +424,8 @@ export default class {
|
|||
const total = await entityManager.getRepository(User).sum("balance_sats")
|
||||
return total || 0
|
||||
}
|
||||
|
||||
async GetPendingPayments(entityManager = this.DB) {
|
||||
return entityManager.getRepository(UserInvoicePayment).find({ where: { paid_at_unix: 0 } })
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue