fixies
This commit is contained in:
parent
5969e8fecf
commit
703379c938
12 changed files with 2070 additions and 2043 deletions
|
|
@ -95,9 +95,9 @@ The nostr server will send back a message response, and inside the body there wi
|
|||
|
||||
- __User__:
|
||||
- expected context content
|
||||
- __user_id__: _string_
|
||||
- __app_id__: _string_
|
||||
- __app_user_id__: _string_
|
||||
- __user_id__: _string_
|
||||
|
||||
- __Admin__:
|
||||
- expected context content
|
||||
|
|
@ -372,48 +372,93 @@ The nostr server will send back a message response, and inside the body there wi
|
|||
## Messages
|
||||
### The content of requests and response from the methods
|
||||
|
||||
### Application
|
||||
- __name__: _string_
|
||||
- __id__: _string_
|
||||
- __balance__: _number_
|
||||
- __npub__: _string_
|
||||
### GetProductBuyLinkResponse
|
||||
- __link__: _string_
|
||||
|
||||
### GetAppUserRequest
|
||||
- __user_identifier__: _string_
|
||||
### AddAppUserRequest
|
||||
- __identifier__: _string_
|
||||
- __fail_if_exists__: _boolean_
|
||||
- __balance__: _number_
|
||||
|
||||
### AppUser
|
||||
- __identifier__: _string_
|
||||
- __info__: _[UserInfo](#UserInfo)_
|
||||
- __max_withdrawable__: _number_
|
||||
|
||||
### PayAppUserInvoiceRequest
|
||||
- __user_identifier__: _string_
|
||||
- __invoice__: _string_
|
||||
- __amount__: _number_
|
||||
|
||||
### OpenChannelResponse
|
||||
- __channelId__: _string_
|
||||
### UserOperation
|
||||
- __paidAtUnix__: _number_
|
||||
- __type__: _[UserOperationType](#UserOperationType)_
|
||||
- __inbound__: _boolean_
|
||||
- __amount__: _number_
|
||||
- __identifier__: _string_
|
||||
- __operationId__: _string_
|
||||
|
||||
### AddProductRequest
|
||||
- __name__: _string_
|
||||
- __price_sats__: _number_
|
||||
|
||||
### LnurlLinkResponse
|
||||
- __lnurl__: _string_
|
||||
- __k1__: _string_
|
||||
|
||||
### UserInfo
|
||||
- __userId__: _string_
|
||||
- __balance__: _number_
|
||||
- __max_withdrawable__: _number_
|
||||
|
||||
### GetUserOperationsRequest
|
||||
- __latestIncomingInvoice__: _number_
|
||||
- __latestOutgoingInvoice__: _number_
|
||||
- __latestIncomingTx__: _number_
|
||||
- __latestOutgoingTx__: _number_
|
||||
- __latestIncomingUserToUserPayment__: _number_
|
||||
- __latestOutgoingUserToUserPayment__: _number_
|
||||
|
||||
### LiveUserOperation
|
||||
- __id__: _string_
|
||||
- __operation__: _[UserOperation](#UserOperation)_
|
||||
|
||||
### SetMockInvoiceAsPaidRequest
|
||||
### EncryptionExchangeRequest
|
||||
- __publicKey__: _string_
|
||||
- __deviceId__: _string_
|
||||
|
||||
### AddAppInvoiceRequest
|
||||
- __payer_identifier__: _string_
|
||||
- __http_callback_url__: _string_
|
||||
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
|
||||
|
||||
### PayAddressRequest
|
||||
- __address__: _string_
|
||||
- __amoutSats__: _number_
|
||||
- __satsPerVByte__: _number_
|
||||
|
||||
### DecodeInvoiceRequest
|
||||
- __invoice__: _string_
|
||||
|
||||
### DecodeInvoiceResponse
|
||||
- __amount__: _number_
|
||||
|
||||
### PayInvoiceRequest
|
||||
- __invoice__: _string_
|
||||
- __amount__: _number_
|
||||
|
||||
### PayInvoiceResponse
|
||||
- __preimage__: _string_
|
||||
- __amount_paid__: _number_
|
||||
|
||||
### UserOperations
|
||||
- __fromIndex__: _number_
|
||||
- __toIndex__: _number_
|
||||
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
|
||||
|
||||
### Application
|
||||
- __name__: _string_
|
||||
- __id__: _string_
|
||||
- __balance__: _number_
|
||||
- __npub__: _string_
|
||||
|
||||
### AuthApp
|
||||
- __app__: _[Application](#Application)_
|
||||
- __auth_token__: _string_
|
||||
|
||||
### AddAppUserInvoiceRequest
|
||||
- __receiver_identifier__: _string_
|
||||
- __payer_identifier__: _string_
|
||||
- __http_callback_url__: _string_
|
||||
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
|
||||
|
||||
### SetMockAppUserBalanceRequest
|
||||
- __user_identifier__: _string_
|
||||
- __amount__: _number_
|
||||
|
|
@ -421,6 +466,9 @@ The nostr server will send back a message response, and inside the body there wi
|
|||
### NewInvoiceResponse
|
||||
- __invoice__: _string_
|
||||
|
||||
### LndGetInfoRequest
|
||||
- __nodeId__: _number_
|
||||
|
||||
### LnurlWithdrawInfoResponse
|
||||
- __tag__: _string_
|
||||
- __callback__: _string_
|
||||
|
|
@ -431,54 +479,6 @@ The nostr server will send back a message response, and inside the body there wi
|
|||
- __balanceCheck__: _string_
|
||||
- __payLink__: _string_
|
||||
|
||||
### GetProductBuyLinkResponse
|
||||
- __link__: _string_
|
||||
|
||||
### AddAppUserRequest
|
||||
- __identifier__: _string_
|
||||
- __fail_if_exists__: _boolean_
|
||||
- __balance__: _number_
|
||||
|
||||
### NewAddressRequest
|
||||
- __addressType__: _[AddressType](#AddressType)_
|
||||
|
||||
### PayInvoiceRequest
|
||||
- __invoice__: _string_
|
||||
- __amount__: _number_
|
||||
|
||||
### UserOperation
|
||||
- __paidAtUnix__: _number_
|
||||
- __type__: _[UserOperationType](#UserOperationType)_
|
||||
- __inbound__: _boolean_
|
||||
- __amount__: _number_
|
||||
- __identifier__: _string_
|
||||
|
||||
### PayAddressRequest
|
||||
- __address__: _string_
|
||||
- __amoutSats__: _number_
|
||||
- __satsPerVByte__: _number_
|
||||
|
||||
### OpenChannelRequest
|
||||
- __destination__: _string_
|
||||
- __fundingAmount__: _number_
|
||||
- __pushAmount__: _number_
|
||||
- __closeAddress__: _string_
|
||||
|
||||
### HandleLnurlPayResponse
|
||||
- __pr__: _string_
|
||||
- __routes__: ARRAY of: _[Empty](#Empty)_
|
||||
|
||||
### GetAppUserLNURLInfoRequest
|
||||
- __user_identifier__: _string_
|
||||
- __base_url_override__: _string_
|
||||
|
||||
### SetMockAppBalanceRequest
|
||||
- __amount__: _number_
|
||||
|
||||
### PayInvoiceResponse
|
||||
- __preimage__: _string_
|
||||
- __amount_paid__: _number_
|
||||
|
||||
### LnurlPayInfoResponse
|
||||
- __tag__: _string_
|
||||
- __callback__: _string_
|
||||
|
|
@ -494,56 +494,54 @@ The nostr server will send back a message response, and inside the body there wi
|
|||
- __latestOutgoingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
|
||||
- __latestIncomingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
|
||||
|
||||
### Empty
|
||||
### Product
|
||||
- __id__: _string_
|
||||
- __name__: _string_
|
||||
- __price_sats__: _number_
|
||||
|
||||
### AuthApp
|
||||
- __app__: _[Application](#Application)_
|
||||
- __auth_token__: _string_
|
||||
### AuthAppRequest
|
||||
- __name__: _string_
|
||||
- __allow_user_creation__: _boolean_ *this field is optional
|
||||
|
||||
### SendAppUserToAppUserPaymentRequest
|
||||
- __from_user_identifier__: _string_
|
||||
- __to_user_identifier__: _string_
|
||||
- __amount__: _number_
|
||||
|
||||
### AddProductRequest
|
||||
### GetAppUserLNURLInfoRequest
|
||||
- __user_identifier__: _string_
|
||||
- __base_url_override__: _string_
|
||||
|
||||
### OpenChannelRequest
|
||||
- __destination__: _string_
|
||||
- __fundingAmount__: _number_
|
||||
- __pushAmount__: _number_
|
||||
- __closeAddress__: _string_
|
||||
|
||||
### GetUserOperationsRequest
|
||||
- __latestIncomingInvoice__: _number_
|
||||
- __latestOutgoingInvoice__: _number_
|
||||
- __latestIncomingTx__: _number_
|
||||
- __latestOutgoingTx__: _number_
|
||||
- __latestIncomingUserToUserPayment__: _number_
|
||||
- __latestOutgoingUserToUserPayment__: _number_
|
||||
|
||||
### LndGetInfoResponse
|
||||
- __alias__: _string_
|
||||
|
||||
### AddAppRequest
|
||||
- __name__: _string_
|
||||
- __price_sats__: _number_
|
||||
- __allow_user_creation__: _boolean_
|
||||
|
||||
### UserOperations
|
||||
- __fromIndex__: _number_
|
||||
- __toIndex__: _number_
|
||||
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
|
||||
### GetAppUserRequest
|
||||
- __user_identifier__: _string_
|
||||
|
||||
### Product
|
||||
- __id__: _string_
|
||||
- __name__: _string_
|
||||
- __price_sats__: _number_
|
||||
### OpenChannelResponse
|
||||
- __channelId__: _string_
|
||||
|
||||
### EncryptionExchangeRequest
|
||||
- __publicKey__: _string_
|
||||
- __deviceId__: _string_
|
||||
|
||||
### AppUser
|
||||
- __identifier__: _string_
|
||||
- __info__: _[UserInfo](#UserInfo)_
|
||||
- __max_withdrawable__: _number_
|
||||
|
||||
### NewAddressResponse
|
||||
- __address__: _string_
|
||||
|
||||
### AddAppUserInvoiceRequest
|
||||
- __receiver_identifier__: _string_
|
||||
- __payer_identifier__: _string_
|
||||
- __http_callback_url__: _string_
|
||||
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
|
||||
|
||||
### PayAppUserInvoiceResponse
|
||||
- __preimage__: _string_
|
||||
- __amount_paid__: _number_
|
||||
|
||||
### SendAppUserToAppPaymentRequest
|
||||
- __from_user_identifier__: _string_
|
||||
- __amount__: _number_
|
||||
### HandleLnurlPayResponse
|
||||
- __pr__: _string_
|
||||
- __routes__: ARRAY of: _[Empty](#Empty)_
|
||||
|
||||
### PayAddressResponse
|
||||
- __txId__: _string_
|
||||
|
|
@ -552,30 +550,33 @@ The nostr server will send back a message response, and inside the body there wi
|
|||
- __amountSats__: _number_
|
||||
- __memo__: _string_
|
||||
|
||||
### LndGetInfoRequest
|
||||
- __nodeId__: _number_
|
||||
### UserInfo
|
||||
- __userId__: _string_
|
||||
- __balance__: _number_
|
||||
- __max_withdrawable__: _number_
|
||||
|
||||
### AddAppRequest
|
||||
- __name__: _string_
|
||||
- __allow_user_creation__: _boolean_
|
||||
### Empty
|
||||
|
||||
### AuthAppRequest
|
||||
- __name__: _string_
|
||||
- __allow_user_creation__: _boolean_ *this field is optional
|
||||
|
||||
### DecodeInvoiceRequest
|
||||
### SetMockInvoiceAsPaidRequest
|
||||
- __invoice__: _string_
|
||||
|
||||
### DecodeInvoiceResponse
|
||||
- __amount__: _number_
|
||||
|
||||
### LndGetInfoResponse
|
||||
- __alias__: _string_
|
||||
### PayAppUserInvoiceResponse
|
||||
- __preimage__: _string_
|
||||
- __amount_paid__: _number_
|
||||
|
||||
### AddAppInvoiceRequest
|
||||
- __payer_identifier__: _string_
|
||||
- __http_callback_url__: _string_
|
||||
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
|
||||
### SetMockAppBalanceRequest
|
||||
- __amount__: _number_
|
||||
|
||||
### NewAddressResponse
|
||||
- __address__: _string_
|
||||
|
||||
### SendAppUserToAppPaymentRequest
|
||||
- __from_user_identifier__: _string_
|
||||
- __amount__: _number_
|
||||
|
||||
### NewAddressRequest
|
||||
- __addressType__: _[AddressType](#AddressType)_
|
||||
## Enums
|
||||
### The enumerators used in the messages
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -226,6 +226,7 @@ message UserOperation {
|
|||
bool inbound =3;
|
||||
int64 amount = 4;
|
||||
string identifier = 5;
|
||||
string operationId = 6;
|
||||
}
|
||||
message UserOperations {
|
||||
int64 fromIndex=1;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ export default class {
|
|||
if (decoded.numSatoshis && amount) {
|
||||
throw new Error("non zero amount provided to pay invoice but invoice has value already")
|
||||
}
|
||||
this.invoicePaidCb(invoice, decoded.numSatoshis || amount)
|
||||
this.invoicePaidCb(invoice, decoded.numSatoshis || amount, false)
|
||||
delete this.invoicesAwaiting[invoice]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,4 +55,11 @@ export default class {
|
|||
user_identifier: ctx.app_user_id
|
||||
})
|
||||
}
|
||||
async PayAddress(ctx: Types.UserContext, req: Types.PayInvoiceRequest): Promise<Types.PayInvoiceResponse> {
|
||||
return this.applicationManager.PayAppUserInvoice(ctx.app_id, {
|
||||
amount: req.amount,
|
||||
invoice: req.invoice,
|
||||
user_identifier: ctx.app_user_id
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -77,7 +77,8 @@ export default class {
|
|||
// This call will fail if the transaction is already registered
|
||||
const addedTx = await this.storage.paymentStorage.AddAddressReceivingTransaction(userAddress, txOutput.hash, txOutput.index, amount, fee, internal, tx)
|
||||
await this.storage.userStorage.IncrementUserBalance(userAddress.user.user_id, addedTx.paid_amount - fee, tx)
|
||||
this.triggerSubs(userAddress.user.user_id, { amount, paidAtUnix: Date.now() / 1000, inbound: true, type: Types.UserOperationType.INCOMING_TX, identifier: userAddress.address })
|
||||
const operationId = `${+Types.UserOperationType.INCOMING_TX}-${userAddress.serial_id}`
|
||||
this.triggerSubs(userAddress.user.user_id, { amount, paidAtUnix: Date.now() / 1000, inbound: true, type: Types.UserOperationType.INCOMING_TX, identifier: userAddress.address, operationId })
|
||||
} catch {
|
||||
|
||||
}
|
||||
|
|
@ -109,7 +110,8 @@ export default class {
|
|||
}
|
||||
|
||||
await this.triggerPaidCallback(log, userInvoice.callbackUrl)
|
||||
this.triggerSubs(userInvoice.user.user_id, { amount, paidAtUnix: Date.now() / 1000, inbound: true, type: Types.UserOperationType.INCOMING_INVOICE, identifier: userInvoice.invoice })
|
||||
const operationId = `${+Types.UserOperationType.INCOMING_INVOICE}-${userInvoice.serial_id}`
|
||||
this.triggerSubs(userInvoice.user.user_id, { amount, paidAtUnix: Date.now() / 1000, inbound: true, type: Types.UserOperationType.INCOMING_INVOICE, identifier: userInvoice.invoice, operationId })
|
||||
log("paid invoice processed successfully")
|
||||
} catch (err: any) {
|
||||
log("ERROR", "cannot process paid invoice", err.message || "")
|
||||
|
|
|
|||
|
|
@ -170,9 +170,10 @@ export default class {
|
|||
}
|
||||
|
||||
|
||||
async PayAddress(userId: string, req: Types.PayAddressRequest, linkedApplication: Application): Promise<Types.PayAddressResponse> {
|
||||
async PayAddress(ctx: Types.UserContext, req: Types.PayAddressRequest): Promise<Types.PayAddressResponse> {
|
||||
const app = await this.storage.applicationStorage.GetApplication(ctx.app_id)
|
||||
const serviceFee = this.getServiceFee(Types.UserOperationType.OUTGOING_TX, req.amoutSats, false)
|
||||
const isAppUserPayment = userId !== linkedApplication.owner.user_id
|
||||
const isAppUserPayment = ctx.user_id !== app.owner.user_id
|
||||
const internalAddress = await this.storage.paymentStorage.GetAddressOwner(req.address)
|
||||
let txId = ""
|
||||
let chainFees = 0
|
||||
|
|
@ -181,25 +182,25 @@ export default class {
|
|||
const vBytes = Math.ceil(Number(estimate.feeSat / estimate.satPerVbyte))
|
||||
chainFees = vBytes * req.satsPerVByte
|
||||
const total = req.amoutSats + chainFees
|
||||
await this.lockUserWithMinBalance(userId, total + serviceFee)
|
||||
await this.lockUserWithMinBalance(ctx.user_id, total + serviceFee)
|
||||
try {
|
||||
const payment = await this.lnd.PayAddress(req.address, req.amoutSats, req.satsPerVByte)
|
||||
txId = payment.txid
|
||||
await this.storage.userStorage.DecrementUserBalance(userId, total + serviceFee)
|
||||
await this.storage.userStorage.UnlockUser(userId)
|
||||
await this.storage.userStorage.DecrementUserBalance(ctx.user_id, total + serviceFee)
|
||||
await this.storage.userStorage.UnlockUser(ctx.user_id)
|
||||
} catch (err) {
|
||||
await this.storage.userStorage.UnlockUser(userId)
|
||||
await this.storage.userStorage.UnlockUser(ctx.user_id)
|
||||
throw err
|
||||
}
|
||||
} else {
|
||||
await this.storage.userStorage.DecrementUserBalance(userId, req.amoutSats + serviceFee)
|
||||
await this.storage.userStorage.DecrementUserBalance(ctx.user_id, req.amoutSats + serviceFee)
|
||||
this.addressPaidCb({ hash: crypto.randomBytes(32).toString("hex"), index: 0 }, req.address, req.amoutSats, true)
|
||||
}
|
||||
|
||||
if (isAppUserPayment && serviceFee > 0) {
|
||||
await this.storage.userStorage.IncrementUserBalance(linkedApplication.owner.user_id, serviceFee)
|
||||
await this.storage.userStorage.IncrementUserBalance(app.owner.user_id, serviceFee)
|
||||
}
|
||||
await this.storage.paymentStorage.AddUserTransactionPayment(userId, req.address, txId, 0, req.amoutSats, chainFees, serviceFee, !!internalAddress)
|
||||
await this.storage.paymentStorage.AddUserTransactionPayment(ctx.user_id, req.address, txId, 0, req.amoutSats, chainFees, serviceFee, !!internalAddress)
|
||||
return {
|
||||
txId: txId
|
||||
}
|
||||
|
|
@ -336,7 +337,8 @@ export default class {
|
|||
type,
|
||||
amount: o.paid_amount,
|
||||
paidAtUnix: o.paid_at_unix,
|
||||
identifier
|
||||
identifier,
|
||||
operationId: `${+type}-${o.serial_id}`
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ export class AddressReceivingTransaction {
|
|||
@Column()
|
||||
paid_at_unix: number
|
||||
|
||||
@Column()
|
||||
@Column({ default: false })
|
||||
internal: boolean
|
||||
|
||||
@CreateDateColumn()
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ export class UserInvoicePayment {
|
|||
@Column()
|
||||
paid_at_unix: number
|
||||
|
||||
@Column()
|
||||
@Column({ default: false })
|
||||
internal: boolean
|
||||
|
||||
@CreateDateColumn()
|
||||
|
|
|
|||
|
|
@ -23,10 +23,10 @@ export class UserReceivingInvoice {
|
|||
@Column({ default: 0 })
|
||||
paid_at_unix: number
|
||||
|
||||
@Column()
|
||||
@Column({ default: false })
|
||||
internal: boolean
|
||||
|
||||
@Column()
|
||||
@Column({ default: false })
|
||||
paidByLnd: boolean
|
||||
|
||||
@Column({ default: "" })
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ export class UserTransactionPayment {
|
|||
@Column()
|
||||
paid_at_unix: number
|
||||
|
||||
@Column()
|
||||
@Column({ default: false })
|
||||
internal: boolean
|
||||
|
||||
@CreateDateColumn()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue