admin swaps
This commit is contained in:
parent
e9a8865192
commit
0a385188ae
17 changed files with 560 additions and 188 deletions
|
|
@ -93,6 +93,11 @@ The nostr server will send back a message response, and inside the body there wi
|
|||
- input: [MessagingToken](#MessagingToken)
|
||||
- This methods has an __empty__ __response__ body
|
||||
|
||||
- GetAdminTransactionSwapQuote
|
||||
- auth type: __Admin__
|
||||
- input: [TransactionSwapRequest](#TransactionSwapRequest)
|
||||
- output: [TransactionSwapQuote](#TransactionSwapQuote)
|
||||
|
||||
- GetAppsMetrics
|
||||
- auth type: __Metrics__
|
||||
- input: [AppsMetricsRequest](#AppsMetricsRequest)
|
||||
|
|
@ -280,6 +285,11 @@ The nostr server will send back a message response, and inside the body there wi
|
|||
- input: [PayAddressRequest](#PayAddressRequest)
|
||||
- output: [PayAddressResponse](#PayAddressResponse)
|
||||
|
||||
- PayAdminTransactionSwap
|
||||
- auth type: __Admin__
|
||||
- input: [TransactionSwapQuoteRequest](#TransactionSwapQuoteRequest)
|
||||
- output: [AdminSwapResponse](#AdminSwapResponse)
|
||||
|
||||
- PayInvoice
|
||||
- auth type: __User__
|
||||
- input: [PayInvoiceRequest](#PayInvoiceRequest)
|
||||
|
|
@ -525,6 +535,13 @@ The nostr server will send back a message response, and inside the body there wi
|
|||
- input: [MessagingToken](#MessagingToken)
|
||||
- This methods has an __empty__ __response__ body
|
||||
|
||||
- GetAdminTransactionSwapQuote
|
||||
- auth type: __Admin__
|
||||
- http method: __post__
|
||||
- http route: __/api/admin/swap/transaction/quote__
|
||||
- input: [TransactionSwapRequest](#TransactionSwapRequest)
|
||||
- output: [TransactionSwapQuote](#TransactionSwapQuote)
|
||||
|
||||
- GetApp
|
||||
- auth type: __App__
|
||||
- http method: __post__
|
||||
|
|
@ -870,6 +887,13 @@ The nostr server will send back a message response, and inside the body there wi
|
|||
- input: [PayAddressRequest](#PayAddressRequest)
|
||||
- output: [PayAddressResponse](#PayAddressResponse)
|
||||
|
||||
- PayAdminTransactionSwap
|
||||
- auth type: __Admin__
|
||||
- http method: __post__
|
||||
- http route: __/api/admin/swap/transaction/pay__
|
||||
- input: [TransactionSwapQuoteRequest](#TransactionSwapQuoteRequest)
|
||||
- output: [AdminSwapResponse](#AdminSwapResponse)
|
||||
|
||||
- PayAppUserInvoice
|
||||
- auth type: __App__
|
||||
- http method: __post__
|
||||
|
|
@ -1062,6 +1086,10 @@ The nostr server will send back a message response, and inside the body there wi
|
|||
- __name__: _string_
|
||||
- __price_sats__: _number_
|
||||
|
||||
### AdminSwapResponse
|
||||
- __network_fee__: _number_
|
||||
- __tx_id__: _string_
|
||||
|
||||
### AppMetrics
|
||||
- __app__: _[Application](#Application)_
|
||||
- __available__: _number_
|
||||
|
|
@ -1612,6 +1640,10 @@ The nostr server will send back a message response, and inside the body there wi
|
|||
- __swap_operation_id__: _string_
|
||||
- __transaction_amount_sats__: _number_
|
||||
|
||||
### TransactionSwapQuoteRequest
|
||||
- __address__: _string_
|
||||
- __swap_operation_id__: _string_
|
||||
|
||||
### TransactionSwapRequest
|
||||
- __transaction_amount_sats__: _number_
|
||||
|
||||
|
|
|
|||
|
|
@ -66,83 +66,85 @@ type Client struct {
|
|||
BanDebit func(req DebitOperation) error
|
||||
BanUser func(req BanUserRequest) (*BanUserResponse, error)
|
||||
// batching method: BatchUser not implemented
|
||||
CloseChannel func(req CloseChannelRequest) (*CloseChannelResponse, error)
|
||||
CreateOneTimeInviteLink func(req CreateOneTimeInviteLinkRequest) (*CreateOneTimeInviteLinkResponse, error)
|
||||
DecodeInvoice func(req DecodeInvoiceRequest) (*DecodeInvoiceResponse, error)
|
||||
DeleteUserOffer func(req OfferId) error
|
||||
EditDebit func(req DebitAuthorizationRequest) error
|
||||
EncryptionExchange func(req EncryptionExchangeRequest) error
|
||||
EnrollAdminToken func(req EnrollAdminTokenRequest) error
|
||||
EnrollMessagingToken func(req MessagingToken) error
|
||||
GetApp func() (*Application, error)
|
||||
GetAppUser func(req GetAppUserRequest) (*AppUser, error)
|
||||
GetAppUserLNURLInfo func(req GetAppUserLNURLInfoRequest) (*LnurlPayInfoResponse, error)
|
||||
GetAppsMetrics func(req AppsMetricsRequest) (*AppsMetrics, error)
|
||||
GetBundleMetrics func(req LatestBundleMetricReq) (*BundleMetrics, error)
|
||||
GetDebitAuthorizations func() (*DebitAuthorizations, error)
|
||||
GetErrorStats func() (*ErrorStats, error)
|
||||
GetHttpCreds func() (*HttpCreds, error)
|
||||
GetInviteLinkState func(req GetInviteTokenStateRequest) (*GetInviteTokenStateResponse, error)
|
||||
GetLNURLChannelLink func() (*LnurlLinkResponse, error)
|
||||
GetLiveDebitRequests func() (*LiveDebitRequest, error)
|
||||
GetLiveManageRequests func() (*LiveManageRequest, error)
|
||||
GetLiveUserOperations func() (*LiveUserOperation, error)
|
||||
GetLndForwardingMetrics func(req LndMetricsRequest) (*LndForwardingMetrics, error)
|
||||
GetLndMetrics func(req LndMetricsRequest) (*LndMetrics, error)
|
||||
GetLnurlPayInfo func(query GetLnurlPayInfo_Query) (*LnurlPayInfoResponse, error)
|
||||
GetLnurlPayLink func() (*LnurlLinkResponse, error)
|
||||
GetLnurlWithdrawInfo func(query GetLnurlWithdrawInfo_Query) (*LnurlWithdrawInfoResponse, error)
|
||||
GetLnurlWithdrawLink func() (*LnurlLinkResponse, error)
|
||||
GetManageAuthorizations func() (*ManageAuthorizations, error)
|
||||
GetMigrationUpdate func() (*MigrationUpdate, error)
|
||||
GetNPubLinkingState func(req GetNPubLinking) (*NPubLinking, error)
|
||||
GetPaymentState func(req GetPaymentStateRequest) (*PaymentState, error)
|
||||
GetProvidersDisruption func() (*ProvidersDisruption, error)
|
||||
GetSeed func() (*LndSeed, error)
|
||||
GetSingleBundleMetrics func(req SingleMetricReq) (*BundleData, error)
|
||||
GetSingleUsageMetrics func(req SingleMetricReq) (*UsageMetricTlv, error)
|
||||
GetTransactionSwapQuote func(req TransactionSwapRequest) (*TransactionSwapQuote, error)
|
||||
GetUsageMetrics func(req LatestUsageMetricReq) (*UsageMetrics, error)
|
||||
GetUserInfo func() (*UserInfo, error)
|
||||
GetUserOffer func(req OfferId) (*OfferConfig, error)
|
||||
GetUserOfferInvoices func(req GetUserOfferInvoicesReq) (*OfferInvoices, error)
|
||||
GetUserOffers func() (*UserOffers, error)
|
||||
GetUserOperations func(req GetUserOperationsRequest) (*GetUserOperationsResponse, error)
|
||||
HandleLnurlAddress func(routeParams HandleLnurlAddress_RouteParams) (*LnurlPayInfoResponse, error)
|
||||
HandleLnurlPay func(query HandleLnurlPay_Query) (*HandleLnurlPayResponse, error)
|
||||
HandleLnurlWithdraw func(query HandleLnurlWithdraw_Query) error
|
||||
Health func() error
|
||||
LinkNPubThroughToken func(req LinkNPubThroughTokenRequest) error
|
||||
ListChannels func() (*LndChannels, error)
|
||||
ListSwaps func() (*SwapsList, error)
|
||||
LndGetInfo func(req LndGetInfoRequest) (*LndGetInfoResponse, error)
|
||||
NewAddress func(req NewAddressRequest) (*NewAddressResponse, error)
|
||||
NewInvoice func(req NewInvoiceRequest) (*NewInvoiceResponse, error)
|
||||
NewProductInvoice func(query NewProductInvoice_Query) (*NewInvoiceResponse, error)
|
||||
OpenChannel func(req OpenChannelRequest) (*OpenChannelResponse, error)
|
||||
PayAddress func(req PayAddressRequest) (*PayAddressResponse, error)
|
||||
PayAppUserInvoice func(req PayAppUserInvoiceRequest) (*PayInvoiceResponse, error)
|
||||
PayInvoice func(req PayInvoiceRequest) (*PayInvoiceResponse, error)
|
||||
PingSubProcesses func() error
|
||||
RequestNPubLinkingToken func(req RequestNPubLinkingTokenRequest) (*RequestNPubLinkingTokenResponse, error)
|
||||
ResetDebit func(req DebitOperation) error
|
||||
ResetManage func(req ManageOperation) error
|
||||
ResetMetricsStorages func() error
|
||||
ResetNPubLinkingToken func(req RequestNPubLinkingTokenRequest) (*RequestNPubLinkingTokenResponse, error)
|
||||
RespondToDebit func(req DebitResponse) error
|
||||
SendAppUserToAppPayment func(req SendAppUserToAppPaymentRequest) error
|
||||
SendAppUserToAppUserPayment func(req SendAppUserToAppUserPaymentRequest) error
|
||||
SetMockAppBalance func(req SetMockAppBalanceRequest) error
|
||||
SetMockAppUserBalance func(req SetMockAppUserBalanceRequest) error
|
||||
SetMockInvoiceAsPaid func(req SetMockInvoiceAsPaidRequest) error
|
||||
SubToWebRtcCandidates func() (*WebRtcCandidate, error)
|
||||
SubmitWebRtcMessage func(req WebRtcMessage) (*WebRtcAnswer, error)
|
||||
UpdateCallbackUrl func(req CallbackUrl) (*CallbackUrl, error)
|
||||
UpdateChannelPolicy func(req UpdateChannelPolicyRequest) error
|
||||
UpdateUserOffer func(req OfferConfig) error
|
||||
UseInviteLink func(req UseInviteLinkRequest) error
|
||||
UserHealth func() (*UserHealthState, error)
|
||||
ZipMetricsStorages func() (*ZippedMetrics, error)
|
||||
CloseChannel func(req CloseChannelRequest) (*CloseChannelResponse, error)
|
||||
CreateOneTimeInviteLink func(req CreateOneTimeInviteLinkRequest) (*CreateOneTimeInviteLinkResponse, error)
|
||||
DecodeInvoice func(req DecodeInvoiceRequest) (*DecodeInvoiceResponse, error)
|
||||
DeleteUserOffer func(req OfferId) error
|
||||
EditDebit func(req DebitAuthorizationRequest) error
|
||||
EncryptionExchange func(req EncryptionExchangeRequest) error
|
||||
EnrollAdminToken func(req EnrollAdminTokenRequest) error
|
||||
EnrollMessagingToken func(req MessagingToken) error
|
||||
GetAdminTransactionSwapQuote func(req TransactionSwapRequest) (*TransactionSwapQuote, error)
|
||||
GetApp func() (*Application, error)
|
||||
GetAppUser func(req GetAppUserRequest) (*AppUser, error)
|
||||
GetAppUserLNURLInfo func(req GetAppUserLNURLInfoRequest) (*LnurlPayInfoResponse, error)
|
||||
GetAppsMetrics func(req AppsMetricsRequest) (*AppsMetrics, error)
|
||||
GetBundleMetrics func(req LatestBundleMetricReq) (*BundleMetrics, error)
|
||||
GetDebitAuthorizations func() (*DebitAuthorizations, error)
|
||||
GetErrorStats func() (*ErrorStats, error)
|
||||
GetHttpCreds func() (*HttpCreds, error)
|
||||
GetInviteLinkState func(req GetInviteTokenStateRequest) (*GetInviteTokenStateResponse, error)
|
||||
GetLNURLChannelLink func() (*LnurlLinkResponse, error)
|
||||
GetLiveDebitRequests func() (*LiveDebitRequest, error)
|
||||
GetLiveManageRequests func() (*LiveManageRequest, error)
|
||||
GetLiveUserOperations func() (*LiveUserOperation, error)
|
||||
GetLndForwardingMetrics func(req LndMetricsRequest) (*LndForwardingMetrics, error)
|
||||
GetLndMetrics func(req LndMetricsRequest) (*LndMetrics, error)
|
||||
GetLnurlPayInfo func(query GetLnurlPayInfo_Query) (*LnurlPayInfoResponse, error)
|
||||
GetLnurlPayLink func() (*LnurlLinkResponse, error)
|
||||
GetLnurlWithdrawInfo func(query GetLnurlWithdrawInfo_Query) (*LnurlWithdrawInfoResponse, error)
|
||||
GetLnurlWithdrawLink func() (*LnurlLinkResponse, error)
|
||||
GetManageAuthorizations func() (*ManageAuthorizations, error)
|
||||
GetMigrationUpdate func() (*MigrationUpdate, error)
|
||||
GetNPubLinkingState func(req GetNPubLinking) (*NPubLinking, error)
|
||||
GetPaymentState func(req GetPaymentStateRequest) (*PaymentState, error)
|
||||
GetProvidersDisruption func() (*ProvidersDisruption, error)
|
||||
GetSeed func() (*LndSeed, error)
|
||||
GetSingleBundleMetrics func(req SingleMetricReq) (*BundleData, error)
|
||||
GetSingleUsageMetrics func(req SingleMetricReq) (*UsageMetricTlv, error)
|
||||
GetTransactionSwapQuote func(req TransactionSwapRequest) (*TransactionSwapQuote, error)
|
||||
GetUsageMetrics func(req LatestUsageMetricReq) (*UsageMetrics, error)
|
||||
GetUserInfo func() (*UserInfo, error)
|
||||
GetUserOffer func(req OfferId) (*OfferConfig, error)
|
||||
GetUserOfferInvoices func(req GetUserOfferInvoicesReq) (*OfferInvoices, error)
|
||||
GetUserOffers func() (*UserOffers, error)
|
||||
GetUserOperations func(req GetUserOperationsRequest) (*GetUserOperationsResponse, error)
|
||||
HandleLnurlAddress func(routeParams HandleLnurlAddress_RouteParams) (*LnurlPayInfoResponse, error)
|
||||
HandleLnurlPay func(query HandleLnurlPay_Query) (*HandleLnurlPayResponse, error)
|
||||
HandleLnurlWithdraw func(query HandleLnurlWithdraw_Query) error
|
||||
Health func() error
|
||||
LinkNPubThroughToken func(req LinkNPubThroughTokenRequest) error
|
||||
ListChannels func() (*LndChannels, error)
|
||||
ListSwaps func() (*SwapsList, error)
|
||||
LndGetInfo func(req LndGetInfoRequest) (*LndGetInfoResponse, error)
|
||||
NewAddress func(req NewAddressRequest) (*NewAddressResponse, error)
|
||||
NewInvoice func(req NewInvoiceRequest) (*NewInvoiceResponse, error)
|
||||
NewProductInvoice func(query NewProductInvoice_Query) (*NewInvoiceResponse, error)
|
||||
OpenChannel func(req OpenChannelRequest) (*OpenChannelResponse, error)
|
||||
PayAddress func(req PayAddressRequest) (*PayAddressResponse, error)
|
||||
PayAdminTransactionSwap func(req TransactionSwapQuoteRequest) (*AdminSwapResponse, error)
|
||||
PayAppUserInvoice func(req PayAppUserInvoiceRequest) (*PayInvoiceResponse, error)
|
||||
PayInvoice func(req PayInvoiceRequest) (*PayInvoiceResponse, error)
|
||||
PingSubProcesses func() error
|
||||
RequestNPubLinkingToken func(req RequestNPubLinkingTokenRequest) (*RequestNPubLinkingTokenResponse, error)
|
||||
ResetDebit func(req DebitOperation) error
|
||||
ResetManage func(req ManageOperation) error
|
||||
ResetMetricsStorages func() error
|
||||
ResetNPubLinkingToken func(req RequestNPubLinkingTokenRequest) (*RequestNPubLinkingTokenResponse, error)
|
||||
RespondToDebit func(req DebitResponse) error
|
||||
SendAppUserToAppPayment func(req SendAppUserToAppPaymentRequest) error
|
||||
SendAppUserToAppUserPayment func(req SendAppUserToAppUserPaymentRequest) error
|
||||
SetMockAppBalance func(req SetMockAppBalanceRequest) error
|
||||
SetMockAppUserBalance func(req SetMockAppUserBalanceRequest) error
|
||||
SetMockInvoiceAsPaid func(req SetMockInvoiceAsPaidRequest) error
|
||||
SubToWebRtcCandidates func() (*WebRtcCandidate, error)
|
||||
SubmitWebRtcMessage func(req WebRtcMessage) (*WebRtcAnswer, error)
|
||||
UpdateCallbackUrl func(req CallbackUrl) (*CallbackUrl, error)
|
||||
UpdateChannelPolicy func(req UpdateChannelPolicyRequest) error
|
||||
UpdateUserOffer func(req OfferConfig) error
|
||||
UseInviteLink func(req UseInviteLinkRequest) error
|
||||
UserHealth func() (*UserHealthState, error)
|
||||
ZipMetricsStorages func() (*ZippedMetrics, error)
|
||||
}
|
||||
|
||||
func NewClient(params ClientParams) *Client {
|
||||
|
|
@ -664,6 +666,35 @@ func NewClient(params ClientParams) *Client {
|
|||
}
|
||||
return nil
|
||||
},
|
||||
GetAdminTransactionSwapQuote: func(req TransactionSwapRequest) (*TransactionSwapQuote, error) {
|
||||
auth, err := params.RetrieveAdminAuth()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
finalRoute := "/api/admin/swap/transaction/quote"
|
||||
body, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resBody, err := doPostRequest(params.BaseURL+finalRoute, body, auth)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := ResultError{}
|
||||
err = json.Unmarshal(resBody, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if result.Status == "ERROR" {
|
||||
return nil, fmt.Errorf(result.Reason)
|
||||
}
|
||||
res := TransactionSwapQuote{}
|
||||
err = json.Unmarshal(resBody, &res)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
},
|
||||
GetApp: func() (*Application, error) {
|
||||
auth, err := params.RetrieveAppAuth()
|
||||
if err != nil {
|
||||
|
|
@ -1834,6 +1865,35 @@ func NewClient(params ClientParams) *Client {
|
|||
}
|
||||
return &res, nil
|
||||
},
|
||||
PayAdminTransactionSwap: func(req TransactionSwapQuoteRequest) (*AdminSwapResponse, error) {
|
||||
auth, err := params.RetrieveAdminAuth()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
finalRoute := "/api/admin/swap/transaction/pay"
|
||||
body, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resBody, err := doPostRequest(params.BaseURL+finalRoute, body, auth)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := ResultError{}
|
||||
err = json.Unmarshal(resBody, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if result.Status == "ERROR" {
|
||||
return nil, fmt.Errorf(result.Reason)
|
||||
}
|
||||
res := AdminSwapResponse{}
|
||||
err = json.Unmarshal(resBody, &res)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &res, nil
|
||||
},
|
||||
PayAppUserInvoice: func(req PayAppUserInvoiceRequest) (*PayInvoiceResponse, error) {
|
||||
auth, err := params.RetrieveAppAuth()
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -123,6 +123,10 @@ type AddProductRequest struct {
|
|||
Name string `json:"name"`
|
||||
Price_sats int64 `json:"price_sats"`
|
||||
}
|
||||
type AdminSwapResponse struct {
|
||||
Network_fee int64 `json:"network_fee"`
|
||||
Tx_id string `json:"tx_id"`
|
||||
}
|
||||
type AppMetrics struct {
|
||||
App *Application `json:"app"`
|
||||
Available int64 `json:"available"`
|
||||
|
|
@ -673,6 +677,10 @@ type TransactionSwapQuote struct {
|
|||
Swap_operation_id string `json:"swap_operation_id"`
|
||||
Transaction_amount_sats int64 `json:"transaction_amount_sats"`
|
||||
}
|
||||
type TransactionSwapQuoteRequest struct {
|
||||
Address string `json:"address"`
|
||||
Swap_operation_id string `json:"swap_operation_id"`
|
||||
}
|
||||
type TransactionSwapRequest struct {
|
||||
Transaction_amount_sats int64 `json:"transaction_amount_sats"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -869,6 +869,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.GetAdminTransactionSwapQuote) throw new Error('method: GetAdminTransactionSwapQuote is not implemented')
|
||||
app.post('/api/admin/swap/transaction/quote', async (req, res) => {
|
||||
const info: Types.RequestInfo = { rpcName: 'GetAdminTransactionSwapQuote', 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.GetAdminTransactionSwapQuote) throw new Error('method: GetAdminTransactionSwapQuote is not implemented')
|
||||
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
||||
authCtx = authContext
|
||||
stats.guard = process.hrtime.bigint()
|
||||
const request = req.body
|
||||
const error = Types.TransactionSwapRequestValidate(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.GetAdminTransactionSwapQuote({rpcName:'GetAdminTransactionSwapQuote', 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.GetApp) throw new Error('method: GetApp is not implemented')
|
||||
app.post('/api/app/get', async (req, res) => {
|
||||
const info: Types.RequestInfo = { rpcName: 'GetApp', batch: false, nostr: false, batchSize: 0}
|
||||
|
|
@ -1752,6 +1774,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.PayAdminTransactionSwap) throw new Error('method: PayAdminTransactionSwap is not implemented')
|
||||
app.post('/api/admin/swap/transaction/pay', async (req, res) => {
|
||||
const info: Types.RequestInfo = { rpcName: 'PayAdminTransactionSwap', 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.PayAdminTransactionSwap) throw new Error('method: PayAdminTransactionSwap is not implemented')
|
||||
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
||||
authCtx = authContext
|
||||
stats.guard = process.hrtime.bigint()
|
||||
const request = req.body
|
||||
const error = Types.TransactionSwapQuoteRequestValidate(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.PayAdminTransactionSwap({rpcName:'PayAdminTransactionSwap', 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.PayAppUserInvoice) throw new Error('method: PayAppUserInvoice is not implemented')
|
||||
app.post('/api/app/invoice/pay', async (req, res) => {
|
||||
const info: Types.RequestInfo = { rpcName: 'PayAppUserInvoice', batch: false, nostr: false, batchSize: 0}
|
||||
|
|
|
|||
|
|
@ -273,6 +273,20 @@ export default (params: ClientParams) => ({
|
|||
}
|
||||
return { status: 'ERROR', reason: 'invalid response' }
|
||||
},
|
||||
GetAdminTransactionSwapQuote: async (request: Types.TransactionSwapRequest): Promise<ResultError | ({ status: 'OK' }& Types.TransactionSwapQuote)> => {
|
||||
const auth = await params.retrieveAdminAuth()
|
||||
if (auth === null) throw new Error('retrieveAdminAuth() returned null')
|
||||
let finalRoute = '/api/admin/swap/transaction/quote'
|
||||
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.TransactionSwapQuoteValidate(result)
|
||||
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
|
||||
}
|
||||
return { status: 'ERROR', reason: 'invalid response' }
|
||||
},
|
||||
GetApp: async (): Promise<ResultError | ({ status: 'OK' }& Types.Application)> => {
|
||||
const auth = await params.retrieveAppAuth()
|
||||
if (auth === null) throw new Error('retrieveAppAuth() returned null')
|
||||
|
|
@ -881,6 +895,20 @@ export default (params: ClientParams) => ({
|
|||
}
|
||||
return { status: 'ERROR', reason: 'invalid response' }
|
||||
},
|
||||
PayAdminTransactionSwap: async (request: Types.TransactionSwapQuoteRequest): Promise<ResultError | ({ status: 'OK' }& Types.AdminSwapResponse)> => {
|
||||
const auth = await params.retrieveAdminAuth()
|
||||
if (auth === null) throw new Error('retrieveAdminAuth() returned null')
|
||||
let finalRoute = '/api/admin/swap/transaction/pay'
|
||||
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.AdminSwapResponseValidate(result)
|
||||
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
|
||||
}
|
||||
return { status: 'ERROR', reason: 'invalid response' }
|
||||
},
|
||||
PayAppUserInvoice: async (request: Types.PayAppUserInvoiceRequest): Promise<ResultError | ({ status: 'OK' }& Types.PayInvoiceResponse)> => {
|
||||
const auth = await params.retrieveAppAuth()
|
||||
if (auth === null) throw new Error('retrieveAppAuth() returned null')
|
||||
|
|
|
|||
|
|
@ -230,6 +230,21 @@ export default (params: NostrClientParams, send: (to:string, message: NostrRequ
|
|||
}
|
||||
return { status: 'ERROR', reason: 'invalid response' }
|
||||
},
|
||||
GetAdminTransactionSwapQuote: async (request: Types.TransactionSwapRequest): Promise<ResultError | ({ status: 'OK' }& Types.TransactionSwapQuote)> => {
|
||||
const auth = await params.retrieveNostrAdminAuth()
|
||||
if (auth === null) throw new Error('retrieveNostrAdminAuth() returned null')
|
||||
const nostrRequest: NostrRequest = {}
|
||||
nostrRequest.body = request
|
||||
const data = await send(params.pubDestination, {rpcName:'GetAdminTransactionSwapQuote',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.TransactionSwapQuoteValidate(result)
|
||||
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
|
||||
}
|
||||
return { status: 'ERROR', reason: 'invalid response' }
|
||||
},
|
||||
GetAppsMetrics: async (request: Types.AppsMetricsRequest): Promise<ResultError | ({ status: 'OK' }& Types.AppsMetrics)> => {
|
||||
const auth = await params.retrieveNostrMetricsAuth()
|
||||
if (auth === null) throw new Error('retrieveNostrMetricsAuth() returned null')
|
||||
|
|
@ -769,6 +784,21 @@ export default (params: NostrClientParams, send: (to:string, message: NostrRequ
|
|||
}
|
||||
return { status: 'ERROR', reason: 'invalid response' }
|
||||
},
|
||||
PayAdminTransactionSwap: async (request: Types.TransactionSwapQuoteRequest): Promise<ResultError | ({ status: 'OK' }& Types.AdminSwapResponse)> => {
|
||||
const auth = await params.retrieveNostrAdminAuth()
|
||||
if (auth === null) throw new Error('retrieveNostrAdminAuth() returned null')
|
||||
const nostrRequest: NostrRequest = {}
|
||||
nostrRequest.body = request
|
||||
const data = await send(params.pubDestination, {rpcName:'PayAdminTransactionSwap',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.AdminSwapResponseValidate(result)
|
||||
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
|
||||
}
|
||||
return { status: 'ERROR', reason: 'invalid response' }
|
||||
},
|
||||
PayInvoice: async (request: Types.PayInvoiceRequest): Promise<ResultError | ({ status: 'OK' }& Types.PayInvoiceResponse)> => {
|
||||
const auth = await params.retrieveNostrUserAuth()
|
||||
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
|
||||
|
|
|
|||
|
|
@ -687,6 +687,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 'GetAdminTransactionSwapQuote':
|
||||
try {
|
||||
if (!methods.GetAdminTransactionSwapQuote) throw new Error('method: GetAdminTransactionSwapQuote is not implemented')
|
||||
const authContext = await opts.NostrAdminAuthGuard(req.appId, req.authIdentifier)
|
||||
stats.guard = process.hrtime.bigint()
|
||||
authCtx = authContext
|
||||
const request = req.body
|
||||
const error = Types.TransactionSwapRequestValidate(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.GetAdminTransactionSwapQuote({rpcName:'GetAdminTransactionSwapQuote', 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 'GetAppsMetrics':
|
||||
try {
|
||||
if (!methods.GetAppsMetrics) throw new Error('method: GetAppsMetrics is not implemented')
|
||||
|
|
@ -1225,6 +1241,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 'PayAdminTransactionSwap':
|
||||
try {
|
||||
if (!methods.PayAdminTransactionSwap) throw new Error('method: PayAdminTransactionSwap is not implemented')
|
||||
const authContext = await opts.NostrAdminAuthGuard(req.appId, req.authIdentifier)
|
||||
stats.guard = process.hrtime.bigint()
|
||||
authCtx = authContext
|
||||
const request = req.body
|
||||
const error = Types.TransactionSwapQuoteRequestValidate(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.PayAdminTransactionSwap({rpcName:'PayAdminTransactionSwap', 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 'PayInvoice':
|
||||
try {
|
||||
if (!methods.PayInvoice) throw new Error('method: PayInvoice is not implemented')
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ export type RequestMetric = AuthContext & RequestInfo & RequestStats & { error?:
|
|||
export type AdminContext = {
|
||||
admin_id: string
|
||||
}
|
||||
export type AdminMethodInputs = AddApp_Input | AddPeer_Input | AuthApp_Input | BanUser_Input | CloseChannel_Input | CreateOneTimeInviteLink_Input | GetInviteLinkState_Input | GetSeed_Input | ListChannels_Input | LndGetInfo_Input | OpenChannel_Input | UpdateChannelPolicy_Input
|
||||
export type AdminMethodOutputs = AddApp_Output | AddPeer_Output | AuthApp_Output | BanUser_Output | CloseChannel_Output | CreateOneTimeInviteLink_Output | GetInviteLinkState_Output | GetSeed_Output | ListChannels_Output | LndGetInfo_Output | OpenChannel_Output | UpdateChannelPolicy_Output
|
||||
export type AdminMethodInputs = AddApp_Input | AddPeer_Input | AuthApp_Input | BanUser_Input | CloseChannel_Input | CreateOneTimeInviteLink_Input | GetAdminTransactionSwapQuote_Input | GetInviteLinkState_Input | GetSeed_Input | ListChannels_Input | LndGetInfo_Input | OpenChannel_Input | PayAdminTransactionSwap_Input | UpdateChannelPolicy_Input
|
||||
export type AdminMethodOutputs = AddApp_Output | AddPeer_Output | AuthApp_Output | BanUser_Output | CloseChannel_Output | CreateOneTimeInviteLink_Output | GetAdminTransactionSwapQuote_Output | GetInviteLinkState_Output | GetSeed_Output | ListChannels_Output | LndGetInfo_Output | OpenChannel_Output | PayAdminTransactionSwap_Output | UpdateChannelPolicy_Output
|
||||
export type AppContext = {
|
||||
app_id: string
|
||||
}
|
||||
|
|
@ -99,6 +99,9 @@ export type EnrollAdminToken_Output = ResultError | { status: 'OK' }
|
|||
export type EnrollMessagingToken_Input = {rpcName:'EnrollMessagingToken', req: MessagingToken}
|
||||
export type EnrollMessagingToken_Output = ResultError | { status: 'OK' }
|
||||
|
||||
export type GetAdminTransactionSwapQuote_Input = {rpcName:'GetAdminTransactionSwapQuote', req: TransactionSwapRequest}
|
||||
export type GetAdminTransactionSwapQuote_Output = ResultError | ({ status: 'OK' } & TransactionSwapQuote)
|
||||
|
||||
export type GetApp_Input = {rpcName:'GetApp'}
|
||||
export type GetApp_Output = ResultError | ({ status: 'OK' } & Application)
|
||||
|
||||
|
|
@ -262,6 +265,9 @@ export type OpenChannel_Output = ResultError | ({ status: 'OK' } & OpenChannelRe
|
|||
export type PayAddress_Input = {rpcName:'PayAddress', req: PayAddressRequest}
|
||||
export type PayAddress_Output = ResultError | ({ status: 'OK' } & PayAddressResponse)
|
||||
|
||||
export type PayAdminTransactionSwap_Input = {rpcName:'PayAdminTransactionSwap', req: TransactionSwapQuoteRequest}
|
||||
export type PayAdminTransactionSwap_Output = ResultError | ({ status: 'OK' } & AdminSwapResponse)
|
||||
|
||||
export type PayAppUserInvoice_Input = {rpcName:'PayAppUserInvoice', req: PayAppUserInvoiceRequest}
|
||||
export type PayAppUserInvoice_Output = ResultError | ({ status: 'OK' } & PayInvoiceResponse)
|
||||
|
||||
|
|
@ -348,6 +354,7 @@ export type ServerMethods = {
|
|||
EncryptionExchange?: (req: EncryptionExchange_Input & {ctx: GuestContext }) => Promise<void>
|
||||
EnrollAdminToken?: (req: EnrollAdminToken_Input & {ctx: UserContext }) => Promise<void>
|
||||
EnrollMessagingToken?: (req: EnrollMessagingToken_Input & {ctx: UserContext }) => Promise<void>
|
||||
GetAdminTransactionSwapQuote?: (req: GetAdminTransactionSwapQuote_Input & {ctx: AdminContext }) => Promise<TransactionSwapQuote>
|
||||
GetApp?: (req: GetApp_Input & {ctx: AppContext }) => Promise<Application>
|
||||
GetAppUser?: (req: GetAppUser_Input & {ctx: AppContext }) => Promise<AppUser>
|
||||
GetAppUserLNURLInfo?: (req: GetAppUserLNURLInfo_Input & {ctx: AppContext }) => Promise<LnurlPayInfoResponse>
|
||||
|
|
@ -395,6 +402,7 @@ export type ServerMethods = {
|
|||
NewProductInvoice?: (req: NewProductInvoice_Input & {ctx: UserContext }) => Promise<NewInvoiceResponse>
|
||||
OpenChannel?: (req: OpenChannel_Input & {ctx: AdminContext }) => Promise<OpenChannelResponse>
|
||||
PayAddress?: (req: PayAddress_Input & {ctx: UserContext }) => Promise<PayAddressResponse>
|
||||
PayAdminTransactionSwap?: (req: PayAdminTransactionSwap_Input & {ctx: AdminContext }) => Promise<AdminSwapResponse>
|
||||
PayAppUserInvoice?: (req: PayAppUserInvoice_Input & {ctx: AppContext }) => Promise<PayInvoiceResponse>
|
||||
PayInvoice?: (req: PayInvoice_Input & {ctx: UserContext }) => Promise<PayInvoiceResponse>
|
||||
PingSubProcesses?: (req: PingSubProcesses_Input & {ctx: MetricsContext }) => Promise<void>
|
||||
|
|
@ -659,6 +667,29 @@ export const AddProductRequestValidate = (o?: AddProductRequest, opts: AddProduc
|
|||
return null
|
||||
}
|
||||
|
||||
export type AdminSwapResponse = {
|
||||
network_fee: number
|
||||
tx_id: string
|
||||
}
|
||||
export const AdminSwapResponseOptionalFields: [] = []
|
||||
export type AdminSwapResponseOptions = OptionsBaseMessage & {
|
||||
checkOptionalsAreSet?: []
|
||||
network_fee_CustomCheck?: (v: number) => boolean
|
||||
tx_id_CustomCheck?: (v: string) => boolean
|
||||
}
|
||||
export const AdminSwapResponseValidate = (o?: AdminSwapResponse, opts: AdminSwapResponseOptions = {}, path: string = 'AdminSwapResponse::root.'): Error | null => {
|
||||
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
|
||||
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
|
||||
|
||||
if (typeof o.network_fee !== 'number') return new Error(`${path}.network_fee: is not a number`)
|
||||
if (opts.network_fee_CustomCheck && !opts.network_fee_CustomCheck(o.network_fee)) return new Error(`${path}.network_fee: custom check failed`)
|
||||
|
||||
if (typeof o.tx_id !== 'string') return new Error(`${path}.tx_id: is not a string`)
|
||||
if (opts.tx_id_CustomCheck && !opts.tx_id_CustomCheck(o.tx_id)) return new Error(`${path}.tx_id: custom check failed`)
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export type AppMetrics = {
|
||||
app: Application
|
||||
available: number
|
||||
|
|
@ -3962,6 +3993,29 @@ export const TransactionSwapQuoteValidate = (o?: TransactionSwapQuote, opts: Tra
|
|||
return null
|
||||
}
|
||||
|
||||
export type TransactionSwapQuoteRequest = {
|
||||
address: string
|
||||
swap_operation_id: string
|
||||
}
|
||||
export const TransactionSwapQuoteRequestOptionalFields: [] = []
|
||||
export type TransactionSwapQuoteRequestOptions = OptionsBaseMessage & {
|
||||
checkOptionalsAreSet?: []
|
||||
address_CustomCheck?: (v: string) => boolean
|
||||
swap_operation_id_CustomCheck?: (v: string) => boolean
|
||||
}
|
||||
export const TransactionSwapQuoteRequestValidate = (o?: TransactionSwapQuoteRequest, opts: TransactionSwapQuoteRequestOptions = {}, path: string = 'TransactionSwapQuoteRequest::root.'): Error | null => {
|
||||
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
|
||||
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
|
||||
|
||||
if (typeof o.address !== 'string') return new Error(`${path}.address: is not a string`)
|
||||
if (opts.address_CustomCheck && !opts.address_CustomCheck(o.address)) return new Error(`${path}.address: custom check failed`)
|
||||
|
||||
if (typeof o.swap_operation_id !== 'string') return new Error(`${path}.swap_operation_id: is not a string`)
|
||||
if (opts.swap_operation_id_CustomCheck && !opts.swap_operation_id_CustomCheck(o.swap_operation_id)) return new Error(`${path}.swap_operation_id: custom check failed`)
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export type TransactionSwapRequest = {
|
||||
transaction_amount_sats: number
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue