Merge branch 'master' into tests-ci
This commit is contained in:
commit
263dd49137
15 changed files with 4401 additions and 3938 deletions
|
|
@ -13,6 +13,11 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
## NOSTR Methods
|
## NOSTR Methods
|
||||||
### These are the nostr methods the client implements to communicate with the API via nostr
|
### These are the nostr methods the client implements to communicate with the API via nostr
|
||||||
|
|
||||||
|
- LinkNPubThroughToken
|
||||||
|
- auth type: __User__
|
||||||
|
- input: [LinkNPubThroughTokenRequest](#LinkNPubThroughTokenRequest)
|
||||||
|
- This methods has an __empty__ __response__ body
|
||||||
|
|
||||||
- UserHealth
|
- UserHealth
|
||||||
- auth type: __User__
|
- auth type: __User__
|
||||||
- This methods has an __empty__ __request__ body
|
- This methods has an __empty__ __request__ body
|
||||||
|
|
@ -110,9 +115,9 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
|
|
||||||
- __User__:
|
- __User__:
|
||||||
- expected context content
|
- expected context content
|
||||||
- __app_user_id__: _string_
|
|
||||||
- __user_id__: _string_
|
- __user_id__: _string_
|
||||||
- __app_id__: _string_
|
- __app_id__: _string_
|
||||||
|
- __app_user_id__: _string_
|
||||||
|
|
||||||
- __Admin__:
|
- __Admin__:
|
||||||
- expected context content
|
- expected context content
|
||||||
|
|
@ -160,21 +165,21 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
- GetUsageMetrics
|
- GetUsageMetrics
|
||||||
- auth type: __Metrics__
|
- auth type: __Metrics__
|
||||||
- http method: __post__
|
- http method: __post__
|
||||||
- http route: __/api/admin/metrics/usage__
|
- http route: __/api/reports/usage__
|
||||||
- This methods has an __empty__ __request__ body
|
- This methods has an __empty__ __request__ body
|
||||||
- output: [UsageMetrics](#UsageMetrics)
|
- output: [UsageMetrics](#UsageMetrics)
|
||||||
|
|
||||||
- GetAppsMetrics
|
- GetAppsMetrics
|
||||||
- auth type: __Metrics__
|
- auth type: __Metrics__
|
||||||
- http method: __post__
|
- http method: __post__
|
||||||
- http route: __/api/admin/metrics/apps__
|
- http route: __/api/reports/apps__
|
||||||
- input: [AppsMetricsRequest](#AppsMetricsRequest)
|
- input: [AppsMetricsRequest](#AppsMetricsRequest)
|
||||||
- output: [AppsMetrics](#AppsMetrics)
|
- output: [AppsMetrics](#AppsMetrics)
|
||||||
|
|
||||||
- GetLndMetrics
|
- GetLndMetrics
|
||||||
- auth type: __Metrics__
|
- auth type: __Metrics__
|
||||||
- http method: __post__
|
- http method: __post__
|
||||||
- http route: __/api/admin/metrics/lnd__
|
- http route: __/api/reports/lnd__
|
||||||
- input: [LndMetricsRequest](#LndMetricsRequest)
|
- input: [LndMetricsRequest](#LndMetricsRequest)
|
||||||
- output: [LndMetrics](#LndMetrics)
|
- output: [LndMetrics](#LndMetrics)
|
||||||
|
|
||||||
|
|
@ -248,6 +253,13 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
- This methods has an __empty__ __request__ body
|
- This methods has an __empty__ __request__ body
|
||||||
- output: [LnurlPayInfoResponse](#LnurlPayInfoResponse)
|
- output: [LnurlPayInfoResponse](#LnurlPayInfoResponse)
|
||||||
|
|
||||||
|
- LinkNPubThroughToken
|
||||||
|
- auth type: __User__
|
||||||
|
- http method: __post__
|
||||||
|
- http route: __/api/guest/npub/link__
|
||||||
|
- input: [LinkNPubThroughTokenRequest](#LinkNPubThroughTokenRequest)
|
||||||
|
- This methods has an __empty__ __response__ body
|
||||||
|
|
||||||
- GetApp
|
- GetApp
|
||||||
- auth type: __App__
|
- auth type: __App__
|
||||||
- http method: __post__
|
- http method: __post__
|
||||||
|
|
@ -325,6 +337,13 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
- input: [SetMockAppBalanceRequest](#SetMockAppBalanceRequest)
|
- input: [SetMockAppBalanceRequest](#SetMockAppBalanceRequest)
|
||||||
- This methods has an __empty__ __response__ body
|
- This methods has an __empty__ __response__ body
|
||||||
|
|
||||||
|
- RequestNPubLinkingToken
|
||||||
|
- auth type: __App__
|
||||||
|
- http method: __post__
|
||||||
|
- http route: __/api/app/user/npub/token__
|
||||||
|
- input: [RequestNPubLinkingTokenRequest](#RequestNPubLinkingTokenRequest)
|
||||||
|
- output: [RequestNPubLinkingTokenResponse](#RequestNPubLinkingTokenResponse)
|
||||||
|
|
||||||
- UserHealth
|
- UserHealth
|
||||||
- auth type: __User__
|
- auth type: __User__
|
||||||
- http method: __post__
|
- http method: __post__
|
||||||
|
|
@ -451,11 +470,13 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
## Messages
|
## Messages
|
||||||
### The content of requests and response from the methods
|
### The content of requests and response from the methods
|
||||||
|
|
||||||
### OpenChannelRequest
|
### AddAppInvoiceRequest
|
||||||
- __destination__: _string_
|
- __payer_identifier__: _string_
|
||||||
- __fundingAmount__: _number_
|
- __http_callback_url__: _string_
|
||||||
- __pushAmount__: _number_
|
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
|
||||||
- __closeAddress__: _string_
|
|
||||||
|
### GetAppUserRequest
|
||||||
|
- __user_identifier__: _string_
|
||||||
|
|
||||||
### LnurlPayInfoResponse
|
### LnurlPayInfoResponse
|
||||||
- __tag__: _string_
|
- __tag__: _string_
|
||||||
|
|
@ -466,81 +487,20 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
- __allowsNostr__: _boolean_
|
- __allowsNostr__: _boolean_
|
||||||
- __nostrPubkey__: _string_
|
- __nostrPubkey__: _string_
|
||||||
|
|
||||||
### UserOperations
|
### LinkNPubThroughTokenRequest
|
||||||
- __fromIndex__: _number_
|
- __token__: _string_
|
||||||
- __toIndex__: _number_
|
- __nostr_pub__: _string_
|
||||||
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
|
|
||||||
|
|
||||||
### MigrationUpdate
|
### NewInvoiceResponse
|
||||||
- __closure__: _[ClosureMigration](#ClosureMigration)_ *this field is optional
|
- __invoice__: _string_
|
||||||
- __relays__: _[RelaysMigration](#RelaysMigration)_ *this field is optional
|
|
||||||
|
|
||||||
### SendAppUserToAppPaymentRequest
|
### PayAddressRequest
|
||||||
- __from_user_identifier__: _string_
|
- __address__: _string_
|
||||||
- __amount__: _number_
|
- __amoutSats__: _number_
|
||||||
|
- __satsPerVByte__: _number_
|
||||||
|
|
||||||
### GetAppUserLNURLInfoRequest
|
### GetProductBuyLinkResponse
|
||||||
- __user_identifier__: _string_
|
- __link__: _string_
|
||||||
- __base_url_override__: _string_
|
|
||||||
|
|
||||||
### NewAddressRequest
|
|
||||||
- __addressType__: _[AddressType](#AddressType)_
|
|
||||||
|
|
||||||
### BanUserResponse
|
|
||||||
- __balance_sats__: _number_
|
|
||||||
- __banned_app_users__: ARRAY of: _[BannedAppUser](#BannedAppUser)_
|
|
||||||
|
|
||||||
### Product
|
|
||||||
- __id__: _string_
|
|
||||||
- __name__: _string_
|
|
||||||
- __price_sats__: _number_
|
|
||||||
|
|
||||||
### LiveUserOperation
|
|
||||||
- __operation__: _[UserOperation](#UserOperation)_
|
|
||||||
|
|
||||||
### UsageMetric
|
|
||||||
- __processed_at_ms__: _number_
|
|
||||||
- __parsed_in_nano__: _number_
|
|
||||||
- __auth_in_nano__: _number_
|
|
||||||
- __validate_in_nano__: _number_
|
|
||||||
- __handle_in_nano__: _number_
|
|
||||||
- __rpc_name__: _string_
|
|
||||||
- __batch__: _boolean_
|
|
||||||
- __nostr__: _boolean_
|
|
||||||
- __batch_size__: _number_
|
|
||||||
|
|
||||||
### ChannelBalanceEvent
|
|
||||||
- __block_height__: _number_
|
|
||||||
- __channel_id__: _string_
|
|
||||||
- __local_balance_sats__: _number_
|
|
||||||
- __remote_balance_sats__: _number_
|
|
||||||
|
|
||||||
### ChainBalanceEvent
|
|
||||||
- __block_height__: _number_
|
|
||||||
- __confirmed_balance__: _number_
|
|
||||||
- __unconfirmed_balance__: _number_
|
|
||||||
- __total_balance__: _number_
|
|
||||||
|
|
||||||
### GetUserOperationsResponse
|
|
||||||
- __latestOutgoingInvoiceOperations__: _[UserOperations](#UserOperations)_
|
|
||||||
- __latestIncomingInvoiceOperations__: _[UserOperations](#UserOperations)_
|
|
||||||
- __latestOutgoingTxOperations__: _[UserOperations](#UserOperations)_
|
|
||||||
- __latestIncomingTxOperations__: _[UserOperations](#UserOperations)_
|
|
||||||
- __latestOutgoingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
|
|
||||||
- __latestIncomingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
|
|
||||||
|
|
||||||
### AuthAppRequest
|
|
||||||
- __name__: _string_
|
|
||||||
- __allow_user_creation__: _boolean_ *this field is optional
|
|
||||||
|
|
||||||
### AuthApp
|
|
||||||
- __app__: _[Application](#Application)_
|
|
||||||
- __auth_token__: _string_
|
|
||||||
|
|
||||||
### AddAppUserRequest
|
|
||||||
- __identifier__: _string_
|
|
||||||
- __fail_if_exists__: _boolean_
|
|
||||||
- __balance__: _number_
|
|
||||||
|
|
||||||
### OpenChannel
|
### OpenChannel
|
||||||
- __channel_id__: _string_
|
- __channel_id__: _string_
|
||||||
|
|
@ -550,18 +510,23 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
- __local_balance__: _number_
|
- __local_balance__: _number_
|
||||||
- __remote_balance__: _number_
|
- __remote_balance__: _number_
|
||||||
|
|
||||||
### LndGetInfoRequest
|
### Application
|
||||||
- __nodeId__: _number_
|
- __name__: _string_
|
||||||
|
- __id__: _string_
|
||||||
|
- __balance__: _number_
|
||||||
|
- __npub__: _string_
|
||||||
|
|
||||||
### AddAppUserInvoiceRequest
|
### AuthApp
|
||||||
- __receiver_identifier__: _string_
|
- __app__: _[Application](#Application)_
|
||||||
- __payer_identifier__: _string_
|
- __auth_token__: _string_
|
||||||
- __http_callback_url__: _string_
|
|
||||||
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
|
|
||||||
|
|
||||||
### NewInvoiceRequest
|
### PayAppUserInvoiceRequest
|
||||||
- __amountSats__: _number_
|
- __user_identifier__: _string_
|
||||||
- __memo__: _string_
|
- __invoice__: _string_
|
||||||
|
- __amount__: _number_
|
||||||
|
|
||||||
|
### OpenChannelResponse
|
||||||
|
- __channelId__: _string_
|
||||||
|
|
||||||
### LnurlWithdrawInfoResponse
|
### LnurlWithdrawInfoResponse
|
||||||
- __tag__: _string_
|
- __tag__: _string_
|
||||||
|
|
@ -573,6 +538,36 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
- __balanceCheck__: _string_
|
- __balanceCheck__: _string_
|
||||||
- __payLink__: _string_
|
- __payLink__: _string_
|
||||||
|
|
||||||
|
### MigrationUpdate
|
||||||
|
- __closure__: _[ClosureMigration](#ClosureMigration)_ *this field is optional
|
||||||
|
- __relays__: _[RelaysMigration](#RelaysMigration)_ *this field is optional
|
||||||
|
|
||||||
|
### BannedAppUser
|
||||||
|
- __app_name__: _string_
|
||||||
|
- __app_id__: _string_
|
||||||
|
- __user_identifier__: _string_
|
||||||
|
- __nostr_pub__: _string_
|
||||||
|
|
||||||
|
### AuthAppRequest
|
||||||
|
- __name__: _string_
|
||||||
|
- __allow_user_creation__: _boolean_ *this field is optional
|
||||||
|
|
||||||
|
### SendAppUserToAppUserPaymentRequest
|
||||||
|
- __from_user_identifier__: _string_
|
||||||
|
- __to_user_identifier__: _string_
|
||||||
|
- __amount__: _number_
|
||||||
|
|
||||||
|
### NewAddressResponse
|
||||||
|
- __address__: _string_
|
||||||
|
|
||||||
|
### SetMockAppUserBalanceRequest
|
||||||
|
- __user_identifier__: _string_
|
||||||
|
- __amount__: _number_
|
||||||
|
|
||||||
|
### NewInvoiceRequest
|
||||||
|
- __amountSats__: _number_
|
||||||
|
- __memo__: _string_
|
||||||
|
|
||||||
### HandleLnurlPayResponse
|
### HandleLnurlPayResponse
|
||||||
- __pr__: _string_
|
- __pr__: _string_
|
||||||
- __routes__: ARRAY of: _[Empty](#Empty)_
|
- __routes__: ARRAY of: _[Empty](#Empty)_
|
||||||
|
|
@ -580,16 +575,7 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
### ClosureMigration
|
### ClosureMigration
|
||||||
- __closes_at_unix__: _number_
|
- __closes_at_unix__: _number_
|
||||||
|
|
||||||
### AppMetrics
|
### Empty
|
||||||
- __app__: _[Application](#Application)_
|
|
||||||
- __users__: _[UsersInfo](#UsersInfo)_
|
|
||||||
- __received__: _number_
|
|
||||||
- __spent__: _number_
|
|
||||||
- __available__: _number_
|
|
||||||
- __fees__: _number_
|
|
||||||
- __invoices__: _number_
|
|
||||||
- __total_fees__: _number_
|
|
||||||
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
|
|
||||||
|
|
||||||
### RoutingEvent
|
### RoutingEvent
|
||||||
- __incoming_channel_id__: _number_
|
- __incoming_channel_id__: _number_
|
||||||
|
|
@ -605,121 +591,6 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
- __offchain__: _boolean_
|
- __offchain__: _boolean_
|
||||||
- __forward_fail_event__: _boolean_
|
- __forward_fail_event__: _boolean_
|
||||||
|
|
||||||
### SetMockAppBalanceRequest
|
|
||||||
- __amount__: _number_
|
|
||||||
|
|
||||||
### NewAddressResponse
|
|
||||||
- __address__: _string_
|
|
||||||
|
|
||||||
### PayAddressRequest
|
|
||||||
- __address__: _string_
|
|
||||||
- __amoutSats__: _number_
|
|
||||||
- __satsPerVByte__: _number_
|
|
||||||
|
|
||||||
### LnurlLinkResponse
|
|
||||||
- __lnurl__: _string_
|
|
||||||
- __k1__: _string_
|
|
||||||
|
|
||||||
### SetMockInvoiceAsPaidRequest
|
|
||||||
- __invoice__: _string_
|
|
||||||
- __amount__: _number_
|
|
||||||
|
|
||||||
### BannedAppUser
|
|
||||||
- __app_name__: _string_
|
|
||||||
- __app_id__: _string_
|
|
||||||
- __user_identifier__: _string_
|
|
||||||
- __nostr_pub__: _string_
|
|
||||||
|
|
||||||
### Application
|
|
||||||
- __name__: _string_
|
|
||||||
- __id__: _string_
|
|
||||||
- __balance__: _number_
|
|
||||||
- __npub__: _string_
|
|
||||||
|
|
||||||
### AddAppInvoiceRequest
|
|
||||||
- __payer_identifier__: _string_
|
|
||||||
- __http_callback_url__: _string_
|
|
||||||
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
|
|
||||||
|
|
||||||
### AddProductRequest
|
|
||||||
- __name__: _string_
|
|
||||||
- __price_sats__: _number_
|
|
||||||
|
|
||||||
### RelaysMigration
|
|
||||||
- __relays__: ARRAY of: _string_
|
|
||||||
|
|
||||||
### GetProductBuyLinkResponse
|
|
||||||
- __link__: _string_
|
|
||||||
|
|
||||||
### AddAppRequest
|
|
||||||
- __name__: _string_
|
|
||||||
- __allow_user_creation__: _boolean_
|
|
||||||
|
|
||||||
### SetMockAppUserBalanceRequest
|
|
||||||
- __user_identifier__: _string_
|
|
||||||
- __amount__: _number_
|
|
||||||
|
|
||||||
### OpenChannelResponse
|
|
||||||
- __channelId__: _string_
|
|
||||||
|
|
||||||
### ClosedChannel
|
|
||||||
- __channel_id__: _string_
|
|
||||||
- __capacity__: _number_
|
|
||||||
- __closed_height__: _number_
|
|
||||||
|
|
||||||
### PayAppUserInvoiceRequest
|
|
||||||
- __user_identifier__: _string_
|
|
||||||
- __invoice__: _string_
|
|
||||||
- __amount__: _number_
|
|
||||||
|
|
||||||
### EncryptionExchangeRequest
|
|
||||||
- __publicKey__: _string_
|
|
||||||
- __deviceId__: _string_
|
|
||||||
|
|
||||||
### AppsMetricsRequest
|
|
||||||
- __from_unix__: _number_ *this field is optional
|
|
||||||
- __to_unix__: _number_ *this field is optional
|
|
||||||
- __include_operations__: _boolean_ *this field is optional
|
|
||||||
|
|
||||||
### UsersInfo
|
|
||||||
- __total__: _number_
|
|
||||||
- __no_balance__: _number_
|
|
||||||
- __negative_balance__: _number_
|
|
||||||
- __always_been_inactive__: _number_
|
|
||||||
- __balance_avg__: _number_
|
|
||||||
- __balance_median__: _number_
|
|
||||||
|
|
||||||
### SendAppUserToAppUserPaymentRequest
|
|
||||||
- __from_user_identifier__: _string_
|
|
||||||
- __to_user_identifier__: _string_
|
|
||||||
- __amount__: _number_
|
|
||||||
|
|
||||||
### NewInvoiceResponse
|
|
||||||
- __invoice__: _string_
|
|
||||||
|
|
||||||
### UserInfo
|
|
||||||
- __userId__: _string_
|
|
||||||
- __balance__: _number_
|
|
||||||
- __max_withdrawable__: _number_
|
|
||||||
- __user_identifier__: _string_
|
|
||||||
|
|
||||||
### GetUserOperationsRequest
|
|
||||||
- __latestIncomingInvoice__: _number_
|
|
||||||
- __latestOutgoingInvoice__: _number_
|
|
||||||
- __latestIncomingTx__: _number_
|
|
||||||
- __latestOutgoingTx__: _number_
|
|
||||||
- __latestIncomingUserToUserPayment__: _number_
|
|
||||||
- __latestOutgoingUserToUserPayment__: _number_
|
|
||||||
- __max_size__: _number_
|
|
||||||
|
|
||||||
### Empty
|
|
||||||
|
|
||||||
### BanUserRequest
|
|
||||||
- __user_id__: _string_
|
|
||||||
|
|
||||||
### GetAppUserRequest
|
|
||||||
- __user_identifier__: _string_
|
|
||||||
|
|
||||||
### ChannelRouting
|
### ChannelRouting
|
||||||
- __channel_id__: _string_
|
- __channel_id__: _string_
|
||||||
- __send_errors__: _number_
|
- __send_errors__: _number_
|
||||||
|
|
@ -732,15 +603,155 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
- __forward_fee_as_output__: _number_
|
- __forward_fee_as_output__: _number_
|
||||||
- __events_number__: _number_
|
- __events_number__: _number_
|
||||||
|
|
||||||
### PayInvoiceRequest
|
### BanUserResponse
|
||||||
- __invoice__: _string_
|
- __balance_sats__: _number_
|
||||||
|
- __banned_app_users__: ARRAY of: _[BannedAppUser](#BannedAppUser)_
|
||||||
|
|
||||||
|
### UsageMetric
|
||||||
|
- __processed_at_ms__: _number_
|
||||||
|
- __parsed_in_nano__: _number_
|
||||||
|
- __auth_in_nano__: _number_
|
||||||
|
- __validate_in_nano__: _number_
|
||||||
|
- __handle_in_nano__: _number_
|
||||||
|
- __rpc_name__: _string_
|
||||||
|
- __batch__: _boolean_
|
||||||
|
- __nostr__: _boolean_
|
||||||
|
- __batch_size__: _number_
|
||||||
|
|
||||||
|
### UsersInfo
|
||||||
|
- __total__: _number_
|
||||||
|
- __no_balance__: _number_
|
||||||
|
- __negative_balance__: _number_
|
||||||
|
- __always_been_inactive__: _number_
|
||||||
|
- __balance_avg__: _number_
|
||||||
|
- __balance_median__: _number_
|
||||||
|
|
||||||
|
### PayInvoiceResponse
|
||||||
|
- __preimage__: _string_
|
||||||
|
- __amount_paid__: _number_
|
||||||
|
- __operation_id__: _string_
|
||||||
|
- __service_fee__: _number_
|
||||||
|
- __network_fee__: _number_
|
||||||
|
|
||||||
|
### AddAppUserRequest
|
||||||
|
- __identifier__: _string_
|
||||||
|
- __fail_if_exists__: _boolean_
|
||||||
|
- __balance__: _number_
|
||||||
|
|
||||||
|
### GetAppUserLNURLInfoRequest
|
||||||
|
- __user_identifier__: _string_
|
||||||
|
- __base_url_override__: _string_
|
||||||
|
|
||||||
|
### UserInfo
|
||||||
|
- __userId__: _string_
|
||||||
|
- __balance__: _number_
|
||||||
|
- __max_withdrawable__: _number_
|
||||||
|
- __user_identifier__: _string_
|
||||||
|
|
||||||
|
### AppUser
|
||||||
|
- __identifier__: _string_
|
||||||
|
- __info__: _[UserInfo](#UserInfo)_
|
||||||
|
- __max_withdrawable__: _number_
|
||||||
|
|
||||||
|
### NewAddressRequest
|
||||||
|
- __addressType__: _[AddressType](#AddressType)_
|
||||||
|
|
||||||
|
### ChainBalanceEvent
|
||||||
|
- __block_height__: _number_
|
||||||
|
- __confirmed_balance__: _number_
|
||||||
|
- __unconfirmed_balance__: _number_
|
||||||
|
- __total_balance__: _number_
|
||||||
|
|
||||||
|
### SetMockAppBalanceRequest
|
||||||
- __amount__: _number_
|
- __amount__: _number_
|
||||||
|
|
||||||
|
### GetUserOperationsResponse
|
||||||
|
- __latestOutgoingInvoiceOperations__: _[UserOperations](#UserOperations)_
|
||||||
|
- __latestIncomingInvoiceOperations__: _[UserOperations](#UserOperations)_
|
||||||
|
- __latestOutgoingTxOperations__: _[UserOperations](#UserOperations)_
|
||||||
|
- __latestIncomingTxOperations__: _[UserOperations](#UserOperations)_
|
||||||
|
- __latestOutgoingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
|
||||||
|
- __latestIncomingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
|
||||||
|
|
||||||
|
### AddProductRequest
|
||||||
|
- __name__: _string_
|
||||||
|
- __price_sats__: _number_
|
||||||
|
|
||||||
|
### LndNodeMetrics
|
||||||
|
- __channels_balance_events__: ARRAY of: _[ChannelBalanceEvent](#ChannelBalanceEvent)_
|
||||||
|
- __chain_balance_events__: ARRAY of: _[ChainBalanceEvent](#ChainBalanceEvent)_
|
||||||
|
- __offline_channels__: _number_
|
||||||
|
- __online_channels__: _number_
|
||||||
|
- __pending_channels__: _number_
|
||||||
|
- __closing_channels__: _number_
|
||||||
|
- __open_channels__: ARRAY of: _[OpenChannel](#OpenChannel)_
|
||||||
|
- __closed_channels__: ARRAY of: _[ClosedChannel](#ClosedChannel)_
|
||||||
|
- __channel_routing__: ARRAY of: _[ChannelRouting](#ChannelRouting)_
|
||||||
|
|
||||||
|
### SendAppUserToAppPaymentRequest
|
||||||
|
- __from_user_identifier__: _string_
|
||||||
|
- __amount__: _number_
|
||||||
|
|
||||||
|
### DecodeInvoiceResponse
|
||||||
|
- __amount__: _number_
|
||||||
|
|
||||||
|
### OpenChannelRequest
|
||||||
|
- __destination__: _string_
|
||||||
|
- __fundingAmount__: _number_
|
||||||
|
- __pushAmount__: _number_
|
||||||
|
- __closeAddress__: _string_
|
||||||
|
|
||||||
|
### LndGetInfoResponse
|
||||||
|
- __alias__: _string_
|
||||||
|
|
||||||
|
### AddAppRequest
|
||||||
|
- __name__: _string_
|
||||||
|
- __allow_user_creation__: _boolean_
|
||||||
|
|
||||||
|
### AddAppUserInvoiceRequest
|
||||||
|
- __receiver_identifier__: _string_
|
||||||
|
- __payer_identifier__: _string_
|
||||||
|
- __http_callback_url__: _string_
|
||||||
|
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
|
||||||
|
|
||||||
|
### LndMetrics
|
||||||
|
- __nodes__: ARRAY of: _[LndNodeMetrics](#LndNodeMetrics)_
|
||||||
|
|
||||||
|
### LndGetInfoRequest
|
||||||
|
- __nodeId__: _number_
|
||||||
|
|
||||||
|
### DecodeInvoiceRequest
|
||||||
|
- __invoice__: _string_
|
||||||
|
|
||||||
|
### UserOperations
|
||||||
|
- __fromIndex__: _number_
|
||||||
|
- __toIndex__: _number_
|
||||||
|
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
|
||||||
|
|
||||||
|
### Product
|
||||||
|
- __id__: _string_
|
||||||
|
- __name__: _string_
|
||||||
|
- __price_sats__: _number_
|
||||||
|
|
||||||
|
### RelaysMigration
|
||||||
|
- __relays__: ARRAY of: _string_
|
||||||
|
|
||||||
|
### LiveUserOperation
|
||||||
|
- __operation__: _[UserOperation](#UserOperation)_
|
||||||
|
|
||||||
|
### RequestNPubLinkingTokenResponse
|
||||||
|
- __token__: _string_
|
||||||
|
|
||||||
|
### UsageMetrics
|
||||||
|
- __metrics__: ARRAY of: _[UsageMetric](#UsageMetric)_
|
||||||
|
|
||||||
### AppsMetrics
|
### AppsMetrics
|
||||||
- __apps__: ARRAY of: _[AppMetrics](#AppMetrics)_
|
- __apps__: ARRAY of: _[AppMetrics](#AppMetrics)_
|
||||||
|
|
||||||
### LndGetInfoResponse
|
### ClosedChannel
|
||||||
- __alias__: _string_
|
- __channel_id__: _string_
|
||||||
|
- __capacity__: _number_
|
||||||
|
- __closed_height__: _number_
|
||||||
|
|
||||||
### UserOperation
|
### UserOperation
|
||||||
- __paidAtUnix__: _number_
|
- __paidAtUnix__: _number_
|
||||||
|
|
@ -755,20 +766,12 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
- __tx_hash__: _string_
|
- __tx_hash__: _string_
|
||||||
- __internal__: _boolean_
|
- __internal__: _boolean_
|
||||||
|
|
||||||
### UsageMetrics
|
### SetMockInvoiceAsPaidRequest
|
||||||
- __metrics__: ARRAY of: _[UsageMetric](#UsageMetric)_
|
- __invoice__: _string_
|
||||||
|
- __amount__: _number_
|
||||||
|
|
||||||
### AppUser
|
### BanUserRequest
|
||||||
- __identifier__: _string_
|
- __user_id__: _string_
|
||||||
- __info__: _[UserInfo](#UserInfo)_
|
|
||||||
- __max_withdrawable__: _number_
|
|
||||||
|
|
||||||
### PayInvoiceResponse
|
|
||||||
- __preimage__: _string_
|
|
||||||
- __amount_paid__: _number_
|
|
||||||
- __operation_id__: _string_
|
|
||||||
- __service_fee__: _number_
|
|
||||||
- __network_fee__: _number_
|
|
||||||
|
|
||||||
### PayAddressResponse
|
### PayAddressResponse
|
||||||
- __txId__: _string_
|
- __txId__: _string_
|
||||||
|
|
@ -776,29 +779,55 @@ The nostr server will send back a message response, and inside the body there wi
|
||||||
- __service_fee__: _number_
|
- __service_fee__: _number_
|
||||||
- __network_fee__: _number_
|
- __network_fee__: _number_
|
||||||
|
|
||||||
### DecodeInvoiceRequest
|
### GetUserOperationsRequest
|
||||||
- __invoice__: _string_
|
- __latestIncomingInvoice__: _number_
|
||||||
|
- __latestOutgoingInvoice__: _number_
|
||||||
|
- __latestIncomingTx__: _number_
|
||||||
|
- __latestOutgoingTx__: _number_
|
||||||
|
- __latestIncomingUserToUserPayment__: _number_
|
||||||
|
- __latestOutgoingUserToUserPayment__: _number_
|
||||||
|
- __max_size__: _number_
|
||||||
|
|
||||||
### DecodeInvoiceResponse
|
### EncryptionExchangeRequest
|
||||||
- __amount__: _number_
|
- __publicKey__: _string_
|
||||||
|
- __deviceId__: _string_
|
||||||
|
|
||||||
|
### AppsMetricsRequest
|
||||||
|
- __from_unix__: _number_ *this field is optional
|
||||||
|
- __to_unix__: _number_ *this field is optional
|
||||||
|
- __include_operations__: _boolean_ *this field is optional
|
||||||
|
|
||||||
|
### AppMetrics
|
||||||
|
- __app__: _[Application](#Application)_
|
||||||
|
- __users__: _[UsersInfo](#UsersInfo)_
|
||||||
|
- __received__: _number_
|
||||||
|
- __spent__: _number_
|
||||||
|
- __available__: _number_
|
||||||
|
- __fees__: _number_
|
||||||
|
- __invoices__: _number_
|
||||||
|
- __total_fees__: _number_
|
||||||
|
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
|
||||||
|
|
||||||
|
### ChannelBalanceEvent
|
||||||
|
- __block_height__: _number_
|
||||||
|
- __channel_id__: _string_
|
||||||
|
- __local_balance_sats__: _number_
|
||||||
|
- __remote_balance_sats__: _number_
|
||||||
|
|
||||||
|
### RequestNPubLinkingTokenRequest
|
||||||
|
- __user_identifier__: _string_
|
||||||
|
|
||||||
### LndMetricsRequest
|
### LndMetricsRequest
|
||||||
- __from_unix__: _number_ *this field is optional
|
- __from_unix__: _number_ *this field is optional
|
||||||
- __to_unix__: _number_ *this field is optional
|
- __to_unix__: _number_ *this field is optional
|
||||||
|
|
||||||
### LndNodeMetrics
|
### PayInvoiceRequest
|
||||||
- __channels_balance_events__: ARRAY of: _[ChannelBalanceEvent](#ChannelBalanceEvent)_
|
- __invoice__: _string_
|
||||||
- __chain_balance_events__: ARRAY of: _[ChainBalanceEvent](#ChainBalanceEvent)_
|
- __amount__: _number_
|
||||||
- __offline_channels__: _number_
|
|
||||||
- __online_channels__: _number_
|
|
||||||
- __pending_channels__: _number_
|
|
||||||
- __closing_channels__: _number_
|
|
||||||
- __open_channels__: ARRAY of: _[OpenChannel](#OpenChannel)_
|
|
||||||
- __closed_channels__: ARRAY of: _[ClosedChannel](#ClosedChannel)_
|
|
||||||
- __channel_routing__: ARRAY of: _[ChannelRouting](#ChannelRouting)_
|
|
||||||
|
|
||||||
### LndMetrics
|
### LnurlLinkResponse
|
||||||
- __nodes__: ARRAY of: _[LndNodeMetrics](#LndNodeMetrics)_
|
- __lnurl__: _string_
|
||||||
|
- __k1__: _string_
|
||||||
## Enums
|
## Enums
|
||||||
### The enumerators used in the messages
|
### The enumerators used in the messages
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -122,7 +122,7 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
||||||
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
} 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.GetUsageMetrics) throw new Error('method: GetUsageMetrics is not implemented')
|
if (!opts.allowNotImplementedMethods && !methods.GetUsageMetrics) throw new Error('method: GetUsageMetrics is not implemented')
|
||||||
app.post('/api/admin/metrics/usage', async (req, res) => {
|
app.post('/api/reports/usage', async (req, res) => {
|
||||||
const info: Types.RequestInfo = { rpcName: 'GetUsageMetrics', batch: false, nostr: false, batchSize: 0}
|
const info: Types.RequestInfo = { rpcName: 'GetUsageMetrics', 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 }
|
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 = {}
|
let authCtx: Types.AuthContext = {}
|
||||||
|
|
@ -141,7 +141,7 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
||||||
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
} 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.GetAppsMetrics) throw new Error('method: GetAppsMetrics is not implemented')
|
if (!opts.allowNotImplementedMethods && !methods.GetAppsMetrics) throw new Error('method: GetAppsMetrics is not implemented')
|
||||||
app.post('/api/admin/metrics/apps', async (req, res) => {
|
app.post('/api/reports/apps', async (req, res) => {
|
||||||
const info: Types.RequestInfo = { rpcName: 'GetAppsMetrics', batch: false, nostr: false, batchSize: 0}
|
const info: Types.RequestInfo = { rpcName: 'GetAppsMetrics', 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 }
|
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 = {}
|
let authCtx: Types.AuthContext = {}
|
||||||
|
|
@ -163,7 +163,7 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
||||||
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
} 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.GetLndMetrics) throw new Error('method: GetLndMetrics is not implemented')
|
if (!opts.allowNotImplementedMethods && !methods.GetLndMetrics) throw new Error('method: GetLndMetrics is not implemented')
|
||||||
app.post('/api/admin/metrics/lnd', async (req, res) => {
|
app.post('/api/reports/lnd', async (req, res) => {
|
||||||
const info: Types.RequestInfo = { rpcName: 'GetLndMetrics', batch: false, nostr: false, batchSize: 0}
|
const info: Types.RequestInfo = { rpcName: 'GetLndMetrics', 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 }
|
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 = {}
|
let authCtx: Types.AuthContext = {}
|
||||||
|
|
@ -342,6 +342,28 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
||||||
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
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 }
|
} 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.LinkNPubThroughToken) throw new Error('method: LinkNPubThroughToken is not implemented')
|
||||||
|
app.post('/api/guest/npub/link', async (req, res) => {
|
||||||
|
const info: Types.RequestInfo = { rpcName: 'LinkNPubThroughToken', 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.LinkNPubThroughToken) throw new Error('method: LinkNPubThroughToken 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.LinkNPubThroughTokenRequestValidate(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
|
||||||
|
await methods.LinkNPubThroughToken({rpcName:'LinkNPubThroughToken', ctx:authContext , req: request})
|
||||||
|
stats.handle = process.hrtime.bigint()
|
||||||
|
res.json({status: 'OK'})
|
||||||
|
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.GetApp) throw new Error('method: GetApp is not implemented')
|
if (!opts.allowNotImplementedMethods && !methods.GetApp) throw new Error('method: GetApp is not implemented')
|
||||||
app.post('/api/app/get', async (req, res) => {
|
app.post('/api/app/get', async (req, res) => {
|
||||||
const info: Types.RequestInfo = { rpcName: 'GetApp', batch: false, nostr: false, batchSize: 0}
|
const info: Types.RequestInfo = { rpcName: 'GetApp', batch: false, nostr: false, batchSize: 0}
|
||||||
|
|
@ -581,6 +603,28 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
||||||
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
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 }
|
} 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.RequestNPubLinkingToken) throw new Error('method: RequestNPubLinkingToken is not implemented')
|
||||||
|
app.post('/api/app/user/npub/token', async (req, res) => {
|
||||||
|
const info: Types.RequestInfo = { rpcName: 'RequestNPubLinkingToken', 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.RequestNPubLinkingToken) throw new Error('method: RequestNPubLinkingToken is not implemented')
|
||||||
|
const authContext = await opts.AppAuthGuard(req.headers['authorization'])
|
||||||
|
authCtx = authContext
|
||||||
|
stats.guard = process.hrtime.bigint()
|
||||||
|
const request = req.body
|
||||||
|
const error = Types.RequestNPubLinkingTokenRequestValidate(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.RequestNPubLinkingToken({rpcName:'RequestNPubLinkingToken', 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.UserHealth) throw new Error('method: UserHealth is not implemented')
|
if (!opts.allowNotImplementedMethods && !methods.UserHealth) throw new Error('method: UserHealth is not implemented')
|
||||||
app.post('/api/user/health', async (req, res) => {
|
app.post('/api/user/health', async (req, res) => {
|
||||||
const info: Types.RequestInfo = { rpcName: 'UserHealth', batch: false, nostr: false, batchSize: 0}
|
const info: Types.RequestInfo = { rpcName: 'UserHealth', batch: false, nostr: false, batchSize: 0}
|
||||||
|
|
@ -892,6 +936,18 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
||||||
const opStats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: stats.parse, guard: stats.guard, validate: 0n, handle: 0n }
|
const opStats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: stats.parse, guard: stats.guard, validate: 0n, handle: 0n }
|
||||||
try {
|
try {
|
||||||
switch(operation.rpcName) {
|
switch(operation.rpcName) {
|
||||||
|
case 'LinkNPubThroughToken':
|
||||||
|
if (!methods.LinkNPubThroughToken) {
|
||||||
|
throw new Error('method LinkNPubThroughToken not found' )
|
||||||
|
} else {
|
||||||
|
const error = Types.LinkNPubThroughTokenRequestValidate(operation.req)
|
||||||
|
opStats.validate = process.hrtime.bigint()
|
||||||
|
if (error !== null) throw error
|
||||||
|
await methods.LinkNPubThroughToken({...operation, ctx}); responses.push({ status: 'OK' })
|
||||||
|
opStats.handle = process.hrtime.bigint()
|
||||||
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
||||||
|
}
|
||||||
|
break
|
||||||
case 'UserHealth':
|
case 'UserHealth':
|
||||||
if (!methods.UserHealth) {
|
if (!methods.UserHealth) {
|
||||||
throw new Error('method UserHealth not found' )
|
throw new Error('method UserHealth not found' )
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ export default (params: ClientParams) => ({
|
||||||
GetUsageMetrics: async (): Promise<ResultError | ({ status: 'OK' }& Types.UsageMetrics)> => {
|
GetUsageMetrics: async (): Promise<ResultError | ({ status: 'OK' }& Types.UsageMetrics)> => {
|
||||||
const auth = await params.retrieveMetricsAuth()
|
const auth = await params.retrieveMetricsAuth()
|
||||||
if (auth === null) throw new Error('retrieveMetricsAuth() returned null')
|
if (auth === null) throw new Error('retrieveMetricsAuth() returned null')
|
||||||
let finalRoute = '/api/admin/metrics/usage'
|
let finalRoute = '/api/reports/usage'
|
||||||
const { data } = await axios.post(params.baseUrl + finalRoute, {}, { headers: { 'authorization': auth } })
|
const { data } = await axios.post(params.baseUrl + finalRoute, {}, { headers: { 'authorization': auth } })
|
||||||
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||||
if (data.status === 'OK') {
|
if (data.status === 'OK') {
|
||||||
|
|
@ -89,7 +89,7 @@ export default (params: ClientParams) => ({
|
||||||
GetAppsMetrics: async (request: Types.AppsMetricsRequest): Promise<ResultError | ({ status: 'OK' }& Types.AppsMetrics)> => {
|
GetAppsMetrics: async (request: Types.AppsMetricsRequest): Promise<ResultError | ({ status: 'OK' }& Types.AppsMetrics)> => {
|
||||||
const auth = await params.retrieveMetricsAuth()
|
const auth = await params.retrieveMetricsAuth()
|
||||||
if (auth === null) throw new Error('retrieveMetricsAuth() returned null')
|
if (auth === null) throw new Error('retrieveMetricsAuth() returned null')
|
||||||
let finalRoute = '/api/admin/metrics/apps'
|
let finalRoute = '/api/reports/apps'
|
||||||
const { data } = await axios.post(params.baseUrl + finalRoute, request, { headers: { 'authorization': auth } })
|
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 === 'ERROR' && typeof data.reason === 'string') return data
|
||||||
if (data.status === 'OK') {
|
if (data.status === 'OK') {
|
||||||
|
|
@ -103,7 +103,7 @@ export default (params: ClientParams) => ({
|
||||||
GetLndMetrics: async (request: Types.LndMetricsRequest): Promise<ResultError | ({ status: 'OK' }& Types.LndMetrics)> => {
|
GetLndMetrics: async (request: Types.LndMetricsRequest): Promise<ResultError | ({ status: 'OK' }& Types.LndMetrics)> => {
|
||||||
const auth = await params.retrieveMetricsAuth()
|
const auth = await params.retrieveMetricsAuth()
|
||||||
if (auth === null) throw new Error('retrieveMetricsAuth() returned null')
|
if (auth === null) throw new Error('retrieveMetricsAuth() returned null')
|
||||||
let finalRoute = '/api/admin/metrics/lnd'
|
let finalRoute = '/api/reports/lnd'
|
||||||
const { data } = await axios.post(params.baseUrl + finalRoute, request, { headers: { 'authorization': auth } })
|
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 === 'ERROR' && typeof data.reason === 'string') return data
|
||||||
if (data.status === 'OK') {
|
if (data.status === 'OK') {
|
||||||
|
|
@ -223,6 +223,17 @@ export default (params: ClientParams) => ({
|
||||||
}
|
}
|
||||||
return { status: 'ERROR', reason: 'invalid response' }
|
return { status: 'ERROR', reason: 'invalid response' }
|
||||||
},
|
},
|
||||||
|
LinkNPubThroughToken: async (request: Types.LinkNPubThroughTokenRequest): Promise<ResultError | ({ status: 'OK' })> => {
|
||||||
|
const auth = await params.retrieveUserAuth()
|
||||||
|
if (auth === null) throw new Error('retrieveUserAuth() returned null')
|
||||||
|
let finalRoute = '/api/guest/npub/link'
|
||||||
|
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') {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
return { status: 'ERROR', reason: 'invalid response' }
|
||||||
|
},
|
||||||
GetApp: async (): Promise<ResultError | ({ status: 'OK' }& Types.Application)> => {
|
GetApp: async (): Promise<ResultError | ({ status: 'OK' }& Types.Application)> => {
|
||||||
const auth = await params.retrieveAppAuth()
|
const auth = await params.retrieveAppAuth()
|
||||||
if (auth === null) throw new Error('retrieveAppAuth() returned null')
|
if (auth === null) throw new Error('retrieveAppAuth() returned null')
|
||||||
|
|
@ -365,6 +376,20 @@ export default (params: ClientParams) => ({
|
||||||
}
|
}
|
||||||
return { status: 'ERROR', reason: 'invalid response' }
|
return { status: 'ERROR', reason: 'invalid response' }
|
||||||
},
|
},
|
||||||
|
RequestNPubLinkingToken: async (request: Types.RequestNPubLinkingTokenRequest): Promise<ResultError | ({ status: 'OK' }& Types.RequestNPubLinkingTokenResponse)> => {
|
||||||
|
const auth = await params.retrieveAppAuth()
|
||||||
|
if (auth === null) throw new Error('retrieveAppAuth() returned null')
|
||||||
|
let finalRoute = '/api/app/user/npub/token'
|
||||||
|
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.RequestNPubLinkingTokenResponseValidate(result)
|
||||||
|
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
|
||||||
|
}
|
||||||
|
return { status: 'ERROR', reason: 'invalid response' }
|
||||||
|
},
|
||||||
UserHealth: async (): Promise<ResultError | ({ status: 'OK' })> => {
|
UserHealth: async (): Promise<ResultError | ({ status: 'OK' })> => {
|
||||||
const auth = await params.retrieveUserAuth()
|
const auth = await params.retrieveUserAuth()
|
||||||
if (auth === null) throw new Error('retrieveUserAuth() returned null')
|
if (auth === null) throw new Error('retrieveUserAuth() returned null')
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,18 @@ export type NostrClientParams = {
|
||||||
checkResult?: true
|
checkResult?: true
|
||||||
}
|
}
|
||||||
export default (params: NostrClientParams, send: (to:string, message: NostrRequest) => Promise<any>, subscribe: (to:string, message: NostrRequest, cb:(res:any)=> void) => void) => ({
|
export default (params: NostrClientParams, send: (to:string, message: NostrRequest) => Promise<any>, subscribe: (to:string, message: NostrRequest, cb:(res:any)=> void) => void) => ({
|
||||||
|
LinkNPubThroughToken: async (request: Types.LinkNPubThroughTokenRequest): Promise<ResultError | ({ status: 'OK' })> => {
|
||||||
|
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:'LinkNPubThroughToken',authIdentifier:auth, ...nostrRequest })
|
||||||
|
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||||
|
if (data.status === 'OK') {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
return { status: 'ERROR', reason: 'invalid response' }
|
||||||
|
},
|
||||||
UserHealth: async (): Promise<ResultError | ({ status: 'OK' })> => {
|
UserHealth: async (): Promise<ResultError | ({ status: 'OK' })> => {
|
||||||
const auth = await params.retrieveNostrUserAuth()
|
const auth = await params.retrieveNostrUserAuth()
|
||||||
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
|
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,22 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
const stats: Types.RequestStats = { startMs, start: startTime, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
const stats: Types.RequestStats = { startMs, start: startTime, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
||||||
let authCtx: Types.AuthContext = {}
|
let authCtx: Types.AuthContext = {}
|
||||||
switch (req.rpcName) {
|
switch (req.rpcName) {
|
||||||
|
case 'LinkNPubThroughToken':
|
||||||
|
try {
|
||||||
|
if (!methods.LinkNPubThroughToken) throw new Error('method: LinkNPubThroughToken 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.LinkNPubThroughTokenRequestValidate(request)
|
||||||
|
stats.validate = process.hrtime.bigint()
|
||||||
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback)
|
||||||
|
await methods.LinkNPubThroughToken({rpcName:'LinkNPubThroughToken', ctx:authContext , req: request})
|
||||||
|
stats.handle = process.hrtime.bigint()
|
||||||
|
res({status: 'OK'})
|
||||||
|
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 'UserHealth':
|
case 'UserHealth':
|
||||||
try {
|
try {
|
||||||
if (!methods.UserHealth) throw new Error('method: UserHealth is not implemented')
|
if (!methods.UserHealth) throw new Error('method: UserHealth is not implemented')
|
||||||
|
|
@ -280,6 +296,18 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
const opStats: Types.RequestStats = { startMs, start: startTime, parse: stats.parse, guard: stats.guard, validate: 0n, handle: 0n }
|
const opStats: Types.RequestStats = { startMs, start: startTime, parse: stats.parse, guard: stats.guard, validate: 0n, handle: 0n }
|
||||||
try {
|
try {
|
||||||
switch(operation.rpcName) {
|
switch(operation.rpcName) {
|
||||||
|
case 'LinkNPubThroughToken':
|
||||||
|
if (!methods.LinkNPubThroughToken) {
|
||||||
|
throw new Error('method not defined: LinkNPubThroughToken')
|
||||||
|
} else {
|
||||||
|
const error = Types.LinkNPubThroughTokenRequestValidate(operation.req)
|
||||||
|
opStats.validate = process.hrtime.bigint()
|
||||||
|
if (error !== null) throw error
|
||||||
|
await methods.LinkNPubThroughToken({...operation, ctx}); responses.push({ status: 'OK' })
|
||||||
|
opStats.handle = process.hrtime.bigint()
|
||||||
|
callsMetrics.push({ ...opInfo, ...opStats, ...ctx })
|
||||||
|
}
|
||||||
|
break
|
||||||
case 'UserHealth':
|
case 'UserHealth':
|
||||||
if (!methods.UserHealth) {
|
if (!methods.UserHealth) {
|
||||||
throw new Error('method not defined: UserHealth')
|
throw new Error('method not defined: UserHealth')
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -115,19 +115,19 @@ service LightningPub {
|
||||||
rpc GetUsageMetrics(structs.Empty) returns (structs.UsageMetrics) {
|
rpc GetUsageMetrics(structs.Empty) returns (structs.UsageMetrics) {
|
||||||
option (auth_type) = "Metrics";
|
option (auth_type) = "Metrics";
|
||||||
option (http_method) = "post";
|
option (http_method) = "post";
|
||||||
option (http_route) = "/api/admin/metrics/usage";
|
option (http_route) = "/api/reports/usage";
|
||||||
}
|
}
|
||||||
|
|
||||||
rpc GetAppsMetrics(structs.AppsMetricsRequest) returns (structs.AppsMetrics) {
|
rpc GetAppsMetrics(structs.AppsMetricsRequest) returns (structs.AppsMetrics) {
|
||||||
option (auth_type) = "Metrics";
|
option (auth_type) = "Metrics";
|
||||||
option (http_method) = "post";
|
option (http_method) = "post";
|
||||||
option (http_route) = "/api/admin/metrics/apps";
|
option (http_route) = "/api/reports/apps";
|
||||||
}
|
}
|
||||||
|
|
||||||
rpc GetLndMetrics(structs.LndMetricsRequest) returns (structs.LndMetrics) {
|
rpc GetLndMetrics(structs.LndMetricsRequest) returns (structs.LndMetrics) {
|
||||||
option (auth_type) = "Metrics";
|
option (auth_type) = "Metrics";
|
||||||
option (http_method) = "post";
|
option (http_method) = "post";
|
||||||
option (http_route) = "/api/admin/metrics/lnd";
|
option (http_route) = "/api/reports/lnd";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -179,6 +179,13 @@ service LightningPub {
|
||||||
option (http_method) = "get";
|
option (http_method) = "get";
|
||||||
option (http_route) = "/.well-known/lnurlp/:address_name";
|
option (http_route) = "/.well-known/lnurlp/:address_name";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpc LinkNPubThroughToken(structs.LinkNPubThroughTokenRequest) returns (structs.Empty) {
|
||||||
|
option (auth_type) = "User";
|
||||||
|
option(http_method) = "post";
|
||||||
|
option (http_route) = "/api/guest/npub/link";
|
||||||
|
option (nostr) = true;
|
||||||
|
}
|
||||||
//</Guest>
|
//</Guest>
|
||||||
|
|
||||||
// <App>
|
// <App>
|
||||||
|
|
@ -245,6 +252,11 @@ service LightningPub {
|
||||||
option (http_method) = "post";
|
option (http_method) = "post";
|
||||||
option (http_route) = "/api/app/mock/blance/set";
|
option (http_route) = "/api/app/mock/blance/set";
|
||||||
}
|
}
|
||||||
|
rpc RequestNPubLinkingToken(structs.RequestNPubLinkingTokenRequest) returns (structs.RequestNPubLinkingTokenResponse) {
|
||||||
|
option (auth_type) = "App";
|
||||||
|
option(http_method) = "post";
|
||||||
|
option (http_route) = "/api/app/user/npub/token";
|
||||||
|
}
|
||||||
// </App>
|
// </App>
|
||||||
|
|
||||||
// <User>
|
// <User>
|
||||||
|
|
|
||||||
|
|
@ -425,4 +425,21 @@ message ClosureMigration {
|
||||||
|
|
||||||
message RelaysMigration {
|
message RelaysMigration {
|
||||||
repeated string relays = 1;
|
repeated string relays = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
message RequestNPubLinkingTokenRequest {
|
||||||
|
string user_identifier = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message RequestNPubLinkingTokenResponse {
|
||||||
|
string token = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
message LinkNPubThroughTokenRequest {
|
||||||
|
string token = 1;
|
||||||
|
string nostr_pub = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -327,7 +327,7 @@ export default class {
|
||||||
channelId: c.chanId,
|
channelId: c.chanId,
|
||||||
localBalanceSats: Number(c.localBalance),
|
localBalanceSats: Number(c.localBalance),
|
||||||
remoteBalanceSats: Number(c.remoteBalance),
|
remoteBalanceSats: Number(c.remoteBalance),
|
||||||
htlcs: c.pendingHtlcs.map(htlc => ({ incoming: htlc.incoming, amount: Number(htlc.amount) }))
|
htlcs: c.pendingHtlcs.map(htlc => ({ incoming: htlc.incoming, amount: Number(htlc.amount), index: Number(htlc.htlcIndex), fwIndex: Number(htlc.forwardingHtlcIndex) }))
|
||||||
}))
|
}))
|
||||||
return { confirmedBalance: Number(confirmedBalance), unconfirmedBalance: Number(unconfirmedBalance), totalBalance: Number(totalBalance), channelsBalance }
|
return { confirmedBalance: Number(confirmedBalance), unconfirmedBalance: Number(unconfirmedBalance), totalBalance: Number(totalBalance), channelsBalance }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,34 @@ import PaymentManager from './paymentManager.js'
|
||||||
import { InboundOptionals, defaultInvoiceExpiry } from '../storage/paymentStorage.js'
|
import { InboundOptionals, defaultInvoiceExpiry } from '../storage/paymentStorage.js'
|
||||||
import { ApplicationUser } from '../storage/entity/ApplicationUser.js'
|
import { ApplicationUser } from '../storage/entity/ApplicationUser.js'
|
||||||
import { getLogger } from '../helpers/logger.js'
|
import { getLogger } from '../helpers/logger.js'
|
||||||
|
import crypto from 'crypto'
|
||||||
|
|
||||||
|
const TOKEN_EXPIRY_TIME = 2 * 60 * 1000 // 2 minutes, in milliseconds
|
||||||
|
|
||||||
|
type NsecLinkingData = {
|
||||||
|
serialId: number,
|
||||||
|
expiry: number
|
||||||
|
}
|
||||||
export default class {
|
export default class {
|
||||||
storage: Storage
|
storage: Storage
|
||||||
settings: MainSettings
|
settings: MainSettings
|
||||||
paymentManager: PaymentManager
|
paymentManager: PaymentManager
|
||||||
|
nPubLinkingTokens = new Map<string, NsecLinkingData>();
|
||||||
constructor(storage: Storage, settings: MainSettings, paymentManager: PaymentManager) {
|
constructor(storage: Storage, settings: MainSettings, paymentManager: PaymentManager) {
|
||||||
this.storage = storage
|
this.storage = storage
|
||||||
this.settings = settings
|
this.settings = settings
|
||||||
this.paymentManager = paymentManager
|
this.paymentManager = paymentManager
|
||||||
|
setInterval(() => {
|
||||||
|
const now = Date.now();
|
||||||
|
for (let [token, data] of this.nPubLinkingTokens) {
|
||||||
|
if (data.expiry <= now) {
|
||||||
|
const copy = { ...data }
|
||||||
|
if (this.nPubLinkingTokens.delete(token)) {
|
||||||
|
console.log("Expired an npub linking token for user serial id: ", copy.serialId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 60 * 1000); // 1 minute
|
||||||
}
|
}
|
||||||
SignAppToken(appId: string): string {
|
SignAppToken(appId: string): string {
|
||||||
return jwt.sign({ appId }, this.settings.jwtSecret);
|
return jwt.sign({ appId }, this.settings.jwtSecret);
|
||||||
|
|
@ -172,4 +192,43 @@ export default class {
|
||||||
const user = await this.storage.applicationStorage.GetApplicationUser(app, req.user_identifier)
|
const user = await this.storage.applicationStorage.GetApplicationUser(app, req.user_identifier)
|
||||||
return this.paymentManager.GetLnurlPayInfoFromUser(user.user.user_id, app, req.base_url_override)
|
return this.paymentManager.GetLnurlPayInfoFromUser(user.user.user_id, app, req.base_url_override)
|
||||||
}
|
}
|
||||||
|
async RequestNPubLinkingToken(appId: string, req: Types.RequestNPubLinkingTokenRequest): Promise<Types.RequestNPubLinkingTokenResponse> {
|
||||||
|
const app = await this.storage.applicationStorage.GetApplication(appId);
|
||||||
|
const user = await this.storage.applicationStorage.GetApplicationUser(app, req.user_identifier);
|
||||||
|
if (Array.from(this.nPubLinkingTokens.values()).find(t => t.serialId === user.serial_id)) {
|
||||||
|
throw new Error("App user already waiting on linking");
|
||||||
|
}
|
||||||
|
if (user.nostr_public_key) {
|
||||||
|
throw new Error("User already has an npub");
|
||||||
|
}
|
||||||
|
const token = crypto.randomBytes(32).toString("hex");
|
||||||
|
this.nPubLinkingTokens.set(token, { serialId: user.serial_id, expiry: Date.now() + TOKEN_EXPIRY_TIME })
|
||||||
|
return { token };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async LinkNpubThroughToken(ctx: Types.UserContext, req: Types.LinkNPubThroughTokenRequest): Promise<void> {
|
||||||
|
const { app_id: appId, app_user_id: appUserId } = ctx
|
||||||
|
const app = await this.storage.applicationStorage.GetApplication(appId)
|
||||||
|
const appUser = await this.storage.applicationStorage.GetApplicationUser(app, appUserId)
|
||||||
|
await this.storage.txQueue.PushToQueue({
|
||||||
|
dbTx: true,
|
||||||
|
exec: async tx => {
|
||||||
|
await this.storage.applicationStorage.RemoveApplicationUserAndBaseUser(appUser, tx);
|
||||||
|
const entry = this.nPubLinkingTokens.get(req.token)
|
||||||
|
if (entry && entry.expiry > Date.now()) {
|
||||||
|
const copy = { ...entry }
|
||||||
|
const deleted = this.nPubLinkingTokens.delete(req.token)
|
||||||
|
if (deleted) {
|
||||||
|
await this.storage.applicationStorage.AddNPubToApplicationUser(copy.serialId, req.nostr_pub, tx)
|
||||||
|
} else {
|
||||||
|
throw new Error("An uknown error occured")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error("Token invalid or expired")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -36,7 +36,7 @@ export class Watchdog {
|
||||||
|
|
||||||
Start = async () => {
|
Start = async () => {
|
||||||
const totalUsersBalance = await this.storage.paymentStorage.GetTotalUsersBalance()
|
const totalUsersBalance = await this.storage.paymentStorage.GetTotalUsersBalance()
|
||||||
this.initialLndBalance = await this.getTotalLndBalance()
|
this.initialLndBalance = await this.getTotalLndBalance(totalUsersBalance)
|
||||||
this.initialUsersBalance = totalUsersBalance
|
this.initialUsersBalance = totalUsersBalance
|
||||||
this.enabled = true
|
this.enabled = true
|
||||||
|
|
||||||
|
|
@ -48,14 +48,24 @@ export class Watchdog {
|
||||||
}, 1000 * 60)
|
}, 1000 * 60)
|
||||||
}
|
}
|
||||||
|
|
||||||
getTotalLndBalance = async () => {
|
getTotalLndBalance = async (usersTotal: number) => {
|
||||||
const localLog = getLogger({ appName: "debugLndBalance" })
|
const localLog = getLogger({ appName: "debugLndBalancev2" })
|
||||||
const { confirmedBalance, channelsBalance } = await this.lnd.GetBalance()
|
const { confirmedBalance, channelsBalance } = await this.lnd.GetBalance()
|
||||||
this.log(confirmedBalance, "sats in chain wallet")
|
this.log(confirmedBalance, "sats in chain wallet")
|
||||||
localLog(channelsBalance)
|
localLog({ c: channelsBalance, u: usersTotal })
|
||||||
return channelsBalance.reduce((acc, c) => {
|
let totalBalance = confirmedBalance
|
||||||
return acc + c.localBalanceSats + c.htlcs.reduce((acc2, htlc) => acc2 + (htlc.incoming ? htlc.amount : -htlc.amount), 0)
|
channelsBalance.forEach(c => {
|
||||||
}, 0)
|
let totalBalanceInHtlcs = 0
|
||||||
|
c.htlcs.forEach(htlc => {
|
||||||
|
if (htlc.incoming) {
|
||||||
|
totalBalanceInHtlcs += htlc.amount
|
||||||
|
} else {
|
||||||
|
//totalBalanceInHtlcs -= htlc.amount
|
||||||
|
}
|
||||||
|
})
|
||||||
|
totalBalance += c.localBalanceSats + totalBalanceInHtlcs
|
||||||
|
})
|
||||||
|
return totalBalance
|
||||||
}
|
}
|
||||||
|
|
||||||
checkBalanceUpdate = (deltaLnd: number, deltaUsers: number) => {
|
checkBalanceUpdate = (deltaLnd: number, deltaUsers: number) => {
|
||||||
|
|
@ -117,7 +127,7 @@ export class Watchdog {
|
||||||
}
|
}
|
||||||
this.latestCheckStart = Date.now()
|
this.latestCheckStart = Date.now()
|
||||||
const totalUsersBalance = await this.storage.paymentStorage.GetTotalUsersBalance()
|
const totalUsersBalance = await this.storage.paymentStorage.GetTotalUsersBalance()
|
||||||
const totalLndBalance = await this.getTotalLndBalance()
|
const totalLndBalance = await this.getTotalLndBalance(totalUsersBalance)
|
||||||
const deltaLnd = totalLndBalance - this.initialLndBalance
|
const deltaLnd = totalLndBalance - this.initialLndBalance
|
||||||
const deltaUsers = totalUsersBalance - this.initialUsersBalance
|
const deltaUsers = totalUsersBalance - this.initialUsersBalance
|
||||||
const deny = this.checkBalanceUpdate(deltaLnd, deltaUsers)
|
const deny = this.checkBalanceUpdate(deltaLnd, deltaUsers)
|
||||||
|
|
@ -126,6 +136,7 @@ export class Watchdog {
|
||||||
this.lnd.LockOutgoingOperations()
|
this.lnd.LockOutgoingOperations()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
this.lnd.UnlockOutgoingOperations()
|
||||||
}
|
}
|
||||||
|
|
||||||
checkDeltas = (deltaLnd: number, deltaUsers: number): DeltaCheckResult => {
|
checkDeltas = (deltaLnd: number, deltaUsers: number): DeltaCheckResult => {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ export default class HtlcTracker {
|
||||||
}
|
}
|
||||||
log = getLogger({ appName: 'htlcTracker' })
|
log = getLogger({ appName: 'htlcTracker' })
|
||||||
onHtlcEvent = async (htlc: HtlcEvent) => {
|
onHtlcEvent = async (htlc: HtlcEvent) => {
|
||||||
|
getLogger({ appName: 'debugHtlcs' })(htlc)
|
||||||
const htlcEvent = htlc.event
|
const htlcEvent = htlc.event
|
||||||
if (htlcEvent.oneofKind === 'subscribedEvent') {
|
if (htlcEvent.oneofKind === 'subscribedEvent') {
|
||||||
this.log("htlc subscribed")
|
this.log("htlc subscribed")
|
||||||
|
|
|
||||||
|
|
@ -199,6 +199,21 @@ export default (mainHandler: Main): Types.ServerMethods => {
|
||||||
GetLiveUserOperations: async ({ ctx, cb }) => {
|
GetLiveUserOperations: async ({ ctx, cb }) => {
|
||||||
},
|
},
|
||||||
GetMigrationUpdate: async ({ ctx, cb }) => {
|
GetMigrationUpdate: async ({ ctx, cb }) => {
|
||||||
|
},
|
||||||
|
RequestNPubLinkingToken: async ({ ctx, req }) => {
|
||||||
|
const err = Types.RequestNPubLinkingTokenRequestValidate(req, {
|
||||||
|
user_identifier_CustomCheck: userIdentifier => userIdentifier !== '',
|
||||||
|
})
|
||||||
|
if (err != null) throw new Error(err.message)
|
||||||
|
return mainHandler.applicationManager.RequestNPubLinkingToken(ctx.app_id, req)
|
||||||
|
},
|
||||||
|
LinkNPubThroughToken: async ({ ctx, req }) => {
|
||||||
|
const err = Types.LinkNPubThroughTokenRequestValidate(req, {
|
||||||
|
nostr_pub_CustomCheck: nostrPub => nostrPub !== '',
|
||||||
|
token_CustomCheck: token => token !== ''
|
||||||
|
})
|
||||||
|
if (err != null) throw new Error(err.message)
|
||||||
|
return mainHandler.applicationManager.LinkNpubThroughToken(ctx, req)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,6 +6,7 @@ import UserStorage from './userStorage.js';
|
||||||
import { ApplicationUser } from './entity/ApplicationUser.js';
|
import { ApplicationUser } from './entity/ApplicationUser.js';
|
||||||
import { getLogger } from '../helpers/logger.js';
|
import { getLogger } from '../helpers/logger.js';
|
||||||
import TransactionsQueue, { TX } from "./transactionsQueue.js";
|
import TransactionsQueue, { TX } from "./transactionsQueue.js";
|
||||||
|
import { User } from './entity/User.js';
|
||||||
export default class {
|
export default class {
|
||||||
DB: DataSource | EntityManager
|
DB: DataSource | EntityManager
|
||||||
userStorage: UserStorage
|
userStorage: UserStorage
|
||||||
|
|
@ -95,6 +96,9 @@ export default class {
|
||||||
}
|
}
|
||||||
const user = await entityManager.getRepository(ApplicationUser).findOne({ where: { nostr_public_key: nostrPub } })
|
const user = await entityManager.getRepository(ApplicationUser).findOne({ where: { nostr_public_key: nostrPub } })
|
||||||
if (user) {
|
if (user) {
|
||||||
|
//if (user.application.app_id !== application.app_id) {
|
||||||
|
// throw new Error("tried to access a user of application:" + user.application.app_id + "from application:" + application.app_id)
|
||||||
|
//}
|
||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
if (!application.allow_user_creation) {
|
if (!application.allow_user_creation) {
|
||||||
|
|
@ -152,4 +156,17 @@ export default class {
|
||||||
async IsApplicationOwner(userId: string, entityManager = this.DB) {
|
async IsApplicationOwner(userId: string, entityManager = this.DB) {
|
||||||
return entityManager.getRepository(Application).findOne({ where: { owner: { user_id: userId } } })
|
return entityManager.getRepository(Application).findOne({ where: { owner: { user_id: userId } } })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async AddNPubToApplicationUser(serialId: number, nPub: string, entityManager = this.DB) {
|
||||||
|
return entityManager.getRepository(ApplicationUser).update(serialId, { nostr_public_key: nPub })
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async RemoveApplicationUserAndBaseUser(appUser: ApplicationUser, entityManager = this.DB) {
|
||||||
|
const baseUser = appUser.user;
|
||||||
|
await entityManager.getRepository(ApplicationUser).remove(appUser);
|
||||||
|
await entityManager.getRepository(User).remove(baseUser);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue