diff --git a/proto/autogenerated/client.md b/proto/autogenerated/client.md index 8784a3e8..62dfc3cf 100644 --- a/proto/autogenerated/client.md +++ b/proto/autogenerated/client.md @@ -292,7 +292,7 @@ The nostr server will send back a message response, and inside the body there wi - PayAdminTransactionSwap - auth type: __Admin__ - - input: [TransactionSwapQuoteRequest](#TransactionSwapQuoteRequest) + - input: [PayAdminTransactionSwapRequest](#PayAdminTransactionSwapRequest) - output: [AdminSwapResponse](#AdminSwapResponse) - PayInvoice @@ -903,7 +903,7 @@ The nostr server will send back a message response, and inside the body there wi - auth type: __Admin__ - http method: __post__ - http route: __/api/admin/swap/transaction/pay__ - - input: [TransactionSwapQuoteRequest](#TransactionSwapQuoteRequest) + - input: [PayAdminTransactionSwapRequest](#PayAdminTransactionSwapRequest) - output: [AdminSwapResponse](#AdminSwapResponse) - PayAppUserInvoice @@ -1534,6 +1534,10 @@ The nostr server will send back a message response, and inside the body there wi - __service_fee__: _number_ - __txId__: _string_ +### PayAdminTransactionSwapRequest + - __address__: _string_ + - __swap_operation_id__: _string_ + ### PayAppUserInvoiceRequest - __amount__: _number_ - __debit_npub__: _string_ *this field is optional @@ -1564,7 +1568,6 @@ The nostr server will send back a message response, and inside the body there wi - __network_fee__: _number_ - __operation_id__: _string_ - __paid_at_unix__: _number_ - - __preimage__: _string_ *this field is optional - __service_fee__: _number_ ### Product @@ -1655,10 +1658,6 @@ 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_ diff --git a/proto/autogenerated/go/http_client.go b/proto/autogenerated/go/http_client.go index 38990c80..4975bf90 100644 --- a/proto/autogenerated/go/http_client.go +++ b/proto/autogenerated/go/http_client.go @@ -123,7 +123,7 @@ type Client struct { 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) + PayAdminTransactionSwap func(req PayAdminTransactionSwapRequest) (*AdminSwapResponse, error) PayAppUserInvoice func(req PayAppUserInvoiceRequest) (*PayInvoiceResponse, error) PayInvoice func(req PayInvoiceRequest) (*PayInvoiceResponse, error) PingSubProcesses func() error @@ -1892,7 +1892,7 @@ func NewClient(params ClientParams) *Client { } return &res, nil }, - PayAdminTransactionSwap: func(req TransactionSwapQuoteRequest) (*AdminSwapResponse, error) { + PayAdminTransactionSwap: func(req PayAdminTransactionSwapRequest) (*AdminSwapResponse, error) { auth, err := params.RetrieveAdminAuth() if err != nil { return nil, err diff --git a/proto/autogenerated/go/types.go b/proto/autogenerated/go/types.go index 48673865..f2530527 100644 --- a/proto/autogenerated/go/types.go +++ b/proto/autogenerated/go/types.go @@ -559,6 +559,10 @@ type PayAddressResponse struct { Service_fee int64 `json:"service_fee"` Txid string `json:"txId"` } +type PayAdminTransactionSwapRequest struct { + Address string `json:"address"` + Swap_operation_id string `json:"swap_operation_id"` +} type PayAppUserInvoiceRequest struct { Amount int64 `json:"amount"` Debit_npub string `json:"debit_npub"` @@ -589,7 +593,6 @@ type PaymentState struct { Network_fee int64 `json:"network_fee"` Operation_id string `json:"operation_id"` Paid_at_unix int64 `json:"paid_at_unix"` - Preimage string `json:"preimage"` Service_fee int64 `json:"service_fee"` } type Product struct { @@ -680,10 +683,6 @@ 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"` } diff --git a/proto/autogenerated/ts/express_server.ts b/proto/autogenerated/ts/express_server.ts index c06a392e..6f4b142d 100644 --- a/proto/autogenerated/ts/express_server.ts +++ b/proto/autogenerated/ts/express_server.ts @@ -1804,7 +1804,7 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => { authCtx = authContext stats.guard = process.hrtime.bigint() const request = req.body - const error = Types.TransactionSwapQuoteRequestValidate(request) + const error = Types.PayAdminTransactionSwapRequestValidate(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 diff --git a/proto/autogenerated/ts/http_client.ts b/proto/autogenerated/ts/http_client.ts index 92cc43cb..b7b3b961 100644 --- a/proto/autogenerated/ts/http_client.ts +++ b/proto/autogenerated/ts/http_client.ts @@ -909,7 +909,7 @@ export default (params: ClientParams) => ({ } return { status: 'ERROR', reason: 'invalid response' } }, - PayAdminTransactionSwap: async (request: Types.TransactionSwapQuoteRequest): Promise => { + PayAdminTransactionSwap: async (request: Types.PayAdminTransactionSwapRequest): Promise => { const auth = await params.retrieveAdminAuth() if (auth === null) throw new Error('retrieveAdminAuth() returned null') let finalRoute = '/api/admin/swap/transaction/pay' diff --git a/proto/autogenerated/ts/nostr_client.ts b/proto/autogenerated/ts/nostr_client.ts index c9851138..cc2641eb 100644 --- a/proto/autogenerated/ts/nostr_client.ts +++ b/proto/autogenerated/ts/nostr_client.ts @@ -798,7 +798,7 @@ export default (params: NostrClientParams, send: (to:string, message: NostrRequ } return { status: 'ERROR', reason: 'invalid response' } }, - PayAdminTransactionSwap: async (request: Types.TransactionSwapQuoteRequest): Promise => { + PayAdminTransactionSwap: async (request: Types.PayAdminTransactionSwapRequest): Promise => { const auth = await params.retrieveNostrAdminAuth() if (auth === null) throw new Error('retrieveNostrAdminAuth() returned null') const nostrRequest: NostrRequest = {} diff --git a/proto/autogenerated/ts/nostr_transport.ts b/proto/autogenerated/ts/nostr_transport.ts index 6c9cf582..cc01068d 100644 --- a/proto/autogenerated/ts/nostr_transport.ts +++ b/proto/autogenerated/ts/nostr_transport.ts @@ -1261,7 +1261,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { stats.guard = process.hrtime.bigint() authCtx = authContext const request = req.body - const error = Types.TransactionSwapQuoteRequestValidate(request) + const error = Types.PayAdminTransactionSwapRequestValidate(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}) diff --git a/proto/autogenerated/ts/types.ts b/proto/autogenerated/ts/types.ts index 6cf518e2..4f299055 100644 --- a/proto/autogenerated/ts/types.ts +++ b/proto/autogenerated/ts/types.ts @@ -268,7 +268,7 @@ 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_Input = {rpcName:'PayAdminTransactionSwap', req: PayAdminTransactionSwapRequest} export type PayAdminTransactionSwap_Output = ResultError | ({ status: 'OK' } & AdminSwapResponse) export type PayAppUserInvoice_Input = {rpcName:'PayAppUserInvoice', req: PayAppUserInvoiceRequest} @@ -3308,6 +3308,29 @@ export const PayAddressResponseValidate = (o?: PayAddressResponse, opts: PayAddr return null } +export type PayAdminTransactionSwapRequest = { + address: string + swap_operation_id: string +} +export const PayAdminTransactionSwapRequestOptionalFields: [] = [] +export type PayAdminTransactionSwapRequestOptions = OptionsBaseMessage & { + checkOptionalsAreSet?: [] + address_CustomCheck?: (v: string) => boolean + swap_operation_id_CustomCheck?: (v: string) => boolean +} +export const PayAdminTransactionSwapRequestValidate = (o?: PayAdminTransactionSwapRequest, opts: PayAdminTransactionSwapRequestOptions = {}, path: string = 'PayAdminTransactionSwapRequest::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 PayAppUserInvoiceRequest = { amount: number debit_npub?: string @@ -3456,19 +3479,16 @@ export type PaymentState = { network_fee: number operation_id: string paid_at_unix: number - preimage?: string service_fee: number } -export type PaymentStateOptionalField = 'preimage' -export const PaymentStateOptionalFields: PaymentStateOptionalField[] = ['preimage'] +export const PaymentStateOptionalFields: [] = [] export type PaymentStateOptions = OptionsBaseMessage & { - checkOptionalsAreSet?: PaymentStateOptionalField[] + checkOptionalsAreSet?: [] amount_CustomCheck?: (v: number) => boolean internal_CustomCheck?: (v: boolean) => boolean network_fee_CustomCheck?: (v: number) => boolean operation_id_CustomCheck?: (v: string) => boolean paid_at_unix_CustomCheck?: (v: number) => boolean - preimage_CustomCheck?: (v?: string) => boolean service_fee_CustomCheck?: (v: number) => boolean } export const PaymentStateValidate = (o?: PaymentState, opts: PaymentStateOptions = {}, path: string = 'PaymentState::root.'): Error | null => { @@ -3490,9 +3510,6 @@ export const PaymentStateValidate = (o?: PaymentState, opts: PaymentStateOptions if (typeof o.paid_at_unix !== 'number') return new Error(`${path}.paid_at_unix: is not a number`) if (opts.paid_at_unix_CustomCheck && !opts.paid_at_unix_CustomCheck(o.paid_at_unix)) return new Error(`${path}.paid_at_unix: custom check failed`) - if ((o.preimage || opts.allOptionalsAreSet || opts.checkOptionalsAreSet?.includes('preimage')) && typeof o.preimage !== 'string') return new Error(`${path}.preimage: is not a string`) - if (opts.preimage_CustomCheck && !opts.preimage_CustomCheck(o.preimage)) return new Error(`${path}.preimage: custom check failed`) - if (typeof o.service_fee !== 'number') return new Error(`${path}.service_fee: is not a number`) if (opts.service_fee_CustomCheck && !opts.service_fee_CustomCheck(o.service_fee)) return new Error(`${path}.service_fee: custom check failed`) @@ -4013,29 +4030,6 @@ 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 } diff --git a/proto/service/methods.proto b/proto/service/methods.proto index 3ec7c912..a85beba4 100644 --- a/proto/service/methods.proto +++ b/proto/service/methods.proto @@ -182,7 +182,7 @@ service LightningPub { option (nostr) = true; } - rpc PayAdminTransactionSwap(structs.TransactionSwapQuoteRequest) returns (structs.AdminSwapResponse) { + rpc PayAdminTransactionSwap(structs.PayAdminTransactionSwapRequest) returns (structs.AdminSwapResponse) { option (auth_type) = "Admin"; option (http_method) = "post"; option (http_route) = "/api/admin/swap/transaction/pay"; diff --git a/proto/service/structs.proto b/proto/service/structs.proto index 21d5b855..2681d18a 100644 --- a/proto/service/structs.proto +++ b/proto/service/structs.proto @@ -837,7 +837,7 @@ message TransactionSwapRequest { int64 transaction_amount_sats = 2; } -message TransactionSwapQuoteRequest { +message PayAdminTransactionSwapRequest { string address = 1; string swap_operation_id = 2; } diff --git a/src/services/main/adminManager.ts b/src/services/main/adminManager.ts index 62d1699e..1d125086 100644 --- a/src/services/main/adminManager.ts +++ b/src/services/main/adminManager.ts @@ -267,11 +267,10 @@ export class AdminManager { async GetAdminTransactionSwapQuote(req: Types.TransactionSwapRequest): Promise { return this.swaps.GetTxSwapQuote("admin", req.transaction_amount_sats, () => 0) } - async PayAdminTransactionSwap(req: Types.TransactionSwapQuoteRequest): Promise { + async PayAdminTransactionSwap(req: Types.PayAdminTransactionSwapRequest): Promise { const routingFloor = this.settings.getSettings().lndSettings.routingFeeFloor const routingLimit = this.settings.getSettings().lndSettings.routingFeeLimitBps / 10000 - const swap = await this.swaps.PayAddrWithSwap("admin", req.swap_operation_id, req.address, async (invoice, amt) => { const r = Math.max(Math.ceil(routingLimit * amt), routingFloor) const payment = await this.lnd.PayInvoice(invoice, 0, { routingFeeLimit: r, serviceFee: 0 }, amt, { useProvider: false, from: 'system' }) diff --git a/src/services/serverMethods/index.ts b/src/services/serverMethods/index.ts index 85fb7cf9..f7cb7e1a 100644 --- a/src/services/serverMethods/index.ts +++ b/src/services/serverMethods/index.ts @@ -99,7 +99,7 @@ export default (mainHandler: Main): Types.ServerMethods => { return mainHandler.adminManager.GetAdminTransactionSwapQuote(req) }, PayAdminTransactionSwap: async ({ ctx, req }) => { - const err = Types.TransactionSwapQuoteRequestValidate(req, { + const err = Types.PayAdminTransactionSwapRequestValidate(req, { address_CustomCheck: addr => addr !== '', swap_operation_id_CustomCheck: id => id !== '', })