locking bugs
This commit is contained in:
parent
494277a2d5
commit
102b2f70b8
2 changed files with 25 additions and 4 deletions
|
|
@ -15,6 +15,15 @@ const start = async () => {
|
||||||
const nostrSettings = LoadNosrtSettingsFromEnv()
|
const nostrSettings = LoadNosrtSettingsFromEnv()
|
||||||
nostrMiddleware(serverMethods, mainHandler, nostrSettings)
|
nostrMiddleware(serverMethods, mainHandler, nostrSettings)
|
||||||
const Server = NewServer(serverMethods, serverOptions(mainHandler))
|
const Server = NewServer(serverMethods, serverOptions(mainHandler))
|
||||||
|
if (process.argv[2] === 'unlock') {
|
||||||
|
const u = process.argv[3]
|
||||||
|
if (u) {
|
||||||
|
console.log("unlocking user", u)
|
||||||
|
await mainHandler.storage.userStorage.UnlockUser(u)
|
||||||
|
} else {
|
||||||
|
console.log("no user id found to unlock")
|
||||||
|
}
|
||||||
|
}
|
||||||
Server.Listen(mainSettings.servicePort)
|
Server.Listen(mainSettings.servicePort)
|
||||||
}
|
}
|
||||||
start()
|
start()
|
||||||
|
|
|
||||||
|
|
@ -128,12 +128,18 @@ export default class {
|
||||||
|
|
||||||
const routingFeeLimit = this.lnd.GetFeeLimitAmount(payAmount)
|
const routingFeeLimit = this.lnd.GetFeeLimitAmount(payAmount)
|
||||||
await this.lockUserWithMinBalance(userId, totalAmountToDecrement + routingFeeLimit)
|
await this.lockUserWithMinBalance(userId, totalAmountToDecrement + routingFeeLimit)
|
||||||
const payment = await this.lnd.PayInvoice(req.invoice, req.amount, routingFeeLimit)
|
let payment
|
||||||
|
try {
|
||||||
|
payment = await this.lnd.PayInvoice(req.invoice, req.amount, routingFeeLimit)
|
||||||
|
await this.storage.userStorage.UnlockUser(userId)
|
||||||
|
} catch (err) {
|
||||||
|
await this.storage.userStorage.UnlockUser(userId)
|
||||||
|
throw err
|
||||||
|
}
|
||||||
await this.storage.userStorage.DecrementUserBalance(userId, totalAmountToDecrement + Number(payment.feeSat))
|
await this.storage.userStorage.DecrementUserBalance(userId, totalAmountToDecrement + Number(payment.feeSat))
|
||||||
if (isAppUserPayment && serviceFee > 0) {
|
if (isAppUserPayment && serviceFee > 0) {
|
||||||
await this.storage.userStorage.IncrementUserBalance(linkedApplication.owner.user_id, serviceFee)
|
await this.storage.userStorage.IncrementUserBalance(linkedApplication.owner.user_id, serviceFee)
|
||||||
}
|
}
|
||||||
await this.storage.userStorage.UnlockUser(userId)
|
|
||||||
await this.storage.paymentStorage.AddUserInvoicePayment(userId, req.invoice, payAmount, Number(payment.feeSat), serviceFee)
|
await this.storage.paymentStorage.AddUserInvoicePayment(userId, req.invoice, payAmount, Number(payment.feeSat), serviceFee)
|
||||||
return {
|
return {
|
||||||
preimage: payment.paymentPreimage,
|
preimage: payment.paymentPreimage,
|
||||||
|
|
@ -154,9 +160,15 @@ export default class {
|
||||||
}
|
}
|
||||||
const serviceFee = this.getServiceFee(Types.UserOperationType.OUTGOING_INVOICE, req.amoutSats, false)
|
const serviceFee = this.getServiceFee(Types.UserOperationType.OUTGOING_INVOICE, req.amoutSats, false)
|
||||||
await this.lockUserWithMinBalance(userId, total + serviceFee)
|
await this.lockUserWithMinBalance(userId, total + serviceFee)
|
||||||
const payment = await this.lnd.PayAddress(req.address, req.amoutSats, satPerVByte)
|
let payment
|
||||||
await this.storage.userStorage.DecrementUserBalance(userId, total + serviceFee)
|
try {
|
||||||
|
payment = await this.lnd.PayAddress(req.address, req.amoutSats, satPerVByte)
|
||||||
await this.storage.userStorage.UnlockUser(userId)
|
await this.storage.userStorage.UnlockUser(userId)
|
||||||
|
} catch (err) {
|
||||||
|
await this.storage.userStorage.UnlockUser(userId)
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
await this.storage.userStorage.DecrementUserBalance(userId, total + serviceFee)
|
||||||
await this.storage.paymentStorage.AddUserTransactionPayment(userId, req.address, payment.txid, 0, req.amoutSats, chainFees, serviceFee)
|
await this.storage.paymentStorage.AddUserTransactionPayment(userId, req.address, payment.txid, 0, req.amoutSats, chainFees, serviceFee)
|
||||||
return {
|
return {
|
||||||
txId: payment.txid
|
txId: payment.txid
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue