lnurl pay info
This commit is contained in:
parent
6382cce337
commit
c5ea8c899d
9 changed files with 2043 additions and 1919 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -191,6 +191,20 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
|||
res.json({status: 'OK'})
|
||||
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
|
||||
})
|
||||
if (!opts.allowNotImplementedMethods && !methods.GetAppUserLNURLInfo) throw new Error('method: GetAppUserLNURLInfo is not implemented')
|
||||
app.post('/api/app/user/lnurl/pay/info', async (req, res) => {
|
||||
try {
|
||||
if (!methods.GetAppUserLNURLInfo) throw new Error('method: GetAppUserLNURLInfo is not implemented')
|
||||
const authContext = await opts.AppAuthGuard(req.headers['authorization'])
|
||||
const request = req.body
|
||||
const error = Types.GetAppUserLNURLInfoRequestValidate(request)
|
||||
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
|
||||
const query = req.query
|
||||
const params = req.params
|
||||
const response = await methods.GetAppUserLNURLInfo({ ...authContext, ...query, ...params }, request)
|
||||
res.json({status: 'OK', ...response})
|
||||
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
|
||||
})
|
||||
if (!opts.allowNotImplementedMethods && !methods.AddUser) throw new Error('method: AddUser is not implemented')
|
||||
app.post('/api/user/add', async (req, res) => {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -168,6 +168,20 @@ export default (params: ClientParams) => ({
|
|||
}
|
||||
return { status: 'ERROR', reason: 'invalid response' }
|
||||
},
|
||||
GetAppUserLNURLInfo: async (request: Types.GetAppUserLNURLInfoRequest): Promise<ResultError | ({ status: 'OK' }& Types.LnurlPayInfoResponse)> => {
|
||||
const auth = await params.retrieveAppAuth()
|
||||
if (auth === null) throw new Error('retrieveAppAuth() returned null')
|
||||
let finalRoute = '/api/app/user/lnurl/pay/info'
|
||||
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.LnurlPayInfoResponseValidate(result)
|
||||
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
|
||||
}
|
||||
return { status: 'ERROR', reason: 'invalid response' }
|
||||
},
|
||||
AddUser: async (request: Types.AddUserRequest): Promise<ResultError | ({ status: 'OK' }& Types.AddUserResponse)> => {
|
||||
const auth = await params.retrieveGuestAuth()
|
||||
if (auth === null) throw new Error('retrieveGuestAuth() returned null')
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -144,6 +144,12 @@ service LightningPub {
|
|||
option (http_route) = "/api/app/internal/pay";
|
||||
}
|
||||
|
||||
rpc GetAppUserLNURLInfo(structs.GetAppUserLNURLInfoRequest) returns (structs.LnurlPayInfoResponse) {
|
||||
option (auth_type) = "App";
|
||||
option (http_method) = "post";
|
||||
option (http_route) = "/api/app/user/lnurl/pay/info";
|
||||
}
|
||||
|
||||
// </App>
|
||||
|
||||
rpc AddUser(structs.AddUserRequest)returns (structs.AddUserResponse){
|
||||
|
|
|
|||
|
|
@ -87,6 +87,10 @@ message SendAppUserToAppPaymentRequest {
|
|||
int64 amount = 2;
|
||||
}
|
||||
|
||||
message GetAppUserLNURLInfoRequest {
|
||||
string user_identifier = 1;
|
||||
}
|
||||
|
||||
enum AddressType {
|
||||
WITNESS_PUBKEY_HASH = 0;
|
||||
NESTED_PUBKEY_HASH = 1;
|
||||
|
|
|
|||
|
|
@ -100,4 +100,8 @@ export default class {
|
|||
const app = await this.storage.applicationStorage.GetApplication(appId)
|
||||
await this.paymentManager.SendUserToUserPayment(fromUser.user.user_id, app.owner.user_id, req.amount)
|
||||
}
|
||||
async GetAppUserLNURLInfo(appId: string, req: Types.GetAppUserLNURLInfoRequest): Promise<Types.LnurlPayInfoResponse> {
|
||||
const user = await this.storage.applicationStorage.GetApplicationUser(appId, req.user_identifier)
|
||||
return this.paymentManager.GetLnurlPayInfoFromUser(user.user.user_id)
|
||||
}
|
||||
}
|
||||
|
|
@ -161,7 +161,18 @@ export default class {
|
|||
})
|
||||
}
|
||||
|
||||
async GetLnurlPayInfo(payInfoK1: string): Promise<Types.LnurlPayInfoResponse> {
|
||||
async GetLnurlPayInfoFromUser(userId: string): Promise<Types.LnurlPayInfoResponse> {
|
||||
const payK1 = await this.storage.paymentStorage.AddUserEphemeralKey(userId, 'pay')
|
||||
return {
|
||||
tag: 'payRequest',
|
||||
callback: `${this.settings.serviceUrl}/api/guest/lnurl_pay/handle?k1=${payK1.key}`,
|
||||
maxSendable: 10000000,
|
||||
minSendable: 0,
|
||||
metadata: defaultLnurlPayMetadata
|
||||
}
|
||||
}
|
||||
|
||||
async GetLnurlPayInfoFromK1(payInfoK1: string): Promise<Types.LnurlPayInfoResponse> {
|
||||
const key = await this.storage.paymentStorage.UseUserEphemeralKey(payInfoK1, 'payInfo')
|
||||
const payK1 = await this.storage.paymentStorage.AddUserEphemeralKey(key.user.user_id, 'pay')
|
||||
return {
|
||||
|
|
@ -189,10 +200,8 @@ export default class {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
async OpenChannel(userId: string, req: Types.OpenChannelRequest): Promise<Types.OpenChannelResponse> { throw new Error("WIP") }
|
||||
|
||||
|
||||
mapOperations(operations: UserOperationInfo[], type: Types.UserOperationType, inbound: boolean): Types.UserOperations {
|
||||
if (operations.length === 0) {
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ export default (mainHandler: Main): Types.ServerMethods => {
|
|||
if (!ctx.k1) {
|
||||
throw new Error("invalid lnurl pay to get info")
|
||||
}
|
||||
return mainHandler.paymentManager.GetLnurlPayInfo(ctx.k1)
|
||||
return mainHandler.paymentManager.GetLnurlPayInfoFromK1(ctx.k1)
|
||||
},
|
||||
HandleLnurlPay: async (ctx) => {
|
||||
if (!ctx.k1 || !ctx.amount) {
|
||||
|
|
@ -169,6 +169,13 @@ export default (mainHandler: Main): Types.ServerMethods => {
|
|||
})
|
||||
if (err != null) throw new Error(err.message)
|
||||
await mainHandler.applicationManager.SendAppUserToAppPayment(ctx.app_id, req)
|
||||
},
|
||||
GetAppUserLNURLInfo: async (ctx, req) => {
|
||||
const err = Types.GetAppUserLNURLInfoRequestValidate(req, {
|
||||
user_identifier_CustomCheck: id => id !== ''
|
||||
})
|
||||
if (err != null) throw new Error(err.message)
|
||||
return mainHandler.applicationManager.GetAppUserLNURLInfo(ctx.app_id, req)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue