fix typo and early return

This commit is contained in:
boufni95 2026-01-14 20:17:49 +00:00
parent f6e425aed5
commit b356d804a2
8 changed files with 16 additions and 15 deletions

View file

@ -1524,7 +1524,7 @@ The nostr server will send back a message response, and inside the body there wi
### PayAddressRequest ### PayAddressRequest
- __address__: _string_ - __address__: _string_
- __amoutSats__: _number_ - __amountSats__: _number_
- __satsPerVByte__: _number_ - __satsPerVByte__: _number_
- __swap_operation_id__: _string_ *this field is optional - __swap_operation_id__: _string_ *this field is optional

View file

@ -549,7 +549,7 @@ type OperationsCursor struct {
} }
type PayAddressRequest struct { type PayAddressRequest struct {
Address string `json:"address"` Address string `json:"address"`
Amoutsats int64 `json:"amoutSats"` Amountsats int64 `json:"amountSats"`
Satspervbyte int64 `json:"satsPerVByte"` Satspervbyte int64 `json:"satsPerVByte"`
Swap_operation_id string `json:"swap_operation_id"` Swap_operation_id string `json:"swap_operation_id"`
} }

View file

@ -3243,7 +3243,7 @@ export const OperationsCursorValidate = (o?: OperationsCursor, opts: OperationsC
export type PayAddressRequest = { export type PayAddressRequest = {
address: string address: string
amoutSats: number amountSats: number
satsPerVByte: number satsPerVByte: number
swap_operation_id?: string swap_operation_id?: string
} }
@ -3252,7 +3252,7 @@ export const PayAddressRequestOptionalFields: PayAddressRequestOptionalField[] =
export type PayAddressRequestOptions = OptionsBaseMessage & { export type PayAddressRequestOptions = OptionsBaseMessage & {
checkOptionalsAreSet?: PayAddressRequestOptionalField[] checkOptionalsAreSet?: PayAddressRequestOptionalField[]
address_CustomCheck?: (v: string) => boolean address_CustomCheck?: (v: string) => boolean
amoutSats_CustomCheck?: (v: number) => boolean amountSats_CustomCheck?: (v: number) => boolean
satsPerVByte_CustomCheck?: (v: number) => boolean satsPerVByte_CustomCheck?: (v: number) => boolean
swap_operation_id_CustomCheck?: (v?: string) => boolean swap_operation_id_CustomCheck?: (v?: string) => boolean
} }
@ -3263,8 +3263,8 @@ export const PayAddressRequestValidate = (o?: PayAddressRequest, opts: PayAddres
if (typeof o.address !== 'string') return new Error(`${path}.address: is not a string`) 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 (opts.address_CustomCheck && !opts.address_CustomCheck(o.address)) return new Error(`${path}.address: custom check failed`)
if (typeof o.amoutSats !== 'number') return new Error(`${path}.amoutSats: is not a number`) if (typeof o.amountSats !== 'number') return new Error(`${path}.amountSats: is not a number`)
if (opts.amoutSats_CustomCheck && !opts.amoutSats_CustomCheck(o.amoutSats)) return new Error(`${path}.amoutSats: custom check failed`) if (opts.amountSats_CustomCheck && !opts.amountSats_CustomCheck(o.amountSats)) return new Error(`${path}.amountSats: custom check failed`)
if (typeof o.satsPerVByte !== 'number') return new Error(`${path}.satsPerVByte: is not a number`) if (typeof o.satsPerVByte !== 'number') return new Error(`${path}.satsPerVByte: is not a number`)
if (opts.satsPerVByte_CustomCheck && !opts.satsPerVByte_CustomCheck(o.satsPerVByte)) return new Error(`${path}.satsPerVByte: custom check failed`) if (opts.satsPerVByte_CustomCheck && !opts.satsPerVByte_CustomCheck(o.satsPerVByte)) return new Error(`${path}.satsPerVByte: custom check failed`)

View file

@ -431,7 +431,7 @@ message NewAddressResponse{
} }
message PayAddressRequest{ message PayAddressRequest{
string address = 1; string address = 1;
int64 amoutSats = 2; int64 amountSats = 2;
int64 satsPerVByte = 3; int64 satsPerVByte = 3;
optional string swap_operation_id = 4; optional string swap_operation_id = 4;
} }

View file

@ -114,7 +114,7 @@ export class Swaps {
if (swappers.length === 0) { if (swappers.length === 0) {
throw new Error("No swap services available") throw new Error("No swap services available")
} }
const res = await Promise.allSettled(Object.values(this.revSwappers).map(sw => this.getTxSwapQuote(sw, appUserId, amt, getServiceFee))) const res = await Promise.allSettled(swappers.map(sw => this.getTxSwapQuote(sw, appUserId, amt, getServiceFee)))
const failures: string[] = [] const failures: string[] = []
const success: Types.TransactionSwapQuote[] = [] const success: Types.TransactionSwapQuote[] = []
for (const r of res) { for (const r of res) {

View file

@ -552,7 +552,7 @@ export default class {
async PayAddress(ctx: Types.UserContext, req: Types.PayAddressRequest): Promise<Types.PayAddressResponse> { async PayAddress(ctx: Types.UserContext, req: Types.PayAddressRequest): Promise<Types.PayAddressResponse> {
await this.watchDog.PaymentRequested() await this.watchDog.PaymentRequested()
this.log("paying address", req.address, "for user", ctx.user_id, "with amount", req.amoutSats) this.log("paying address", req.address, "for user", ctx.user_id, "with amount", req.amountSats)
const maybeBanned = await this.storage.userStorage.GetUser(ctx.user_id) const maybeBanned = await this.storage.userStorage.GetUser(ctx.user_id)
if (maybeBanned.locked) { if (maybeBanned.locked) {
throw new Error("user is banned, cannot send chain tx") throw new Error("user is banned, cannot send chain tx")
@ -593,21 +593,21 @@ export default class {
const { blockHeight } = await this.lnd.GetInfo() const { blockHeight } = await this.lnd.GetInfo()
const app = await this.storage.applicationStorage.GetApplication(ctx.app_id) const app = await this.storage.applicationStorage.GetApplication(ctx.app_id)
const isManagedUser = ctx.user_id !== app.owner.user_id const isManagedUser = ctx.user_id !== app.owner.user_id
const serviceFee = this.getSendServiceFee(Types.UserOperationType.OUTGOING_USER_TO_USER, req.amoutSats, isManagedUser) const serviceFee = this.getSendServiceFee(Types.UserOperationType.OUTGOING_USER_TO_USER, req.amountSats, isManagedUser)
const txId = crypto.randomBytes(32).toString("hex") const txId = crypto.randomBytes(32).toString("hex")
const addressData = `${req.address}:${txId}` const addressData = `${req.address}:${txId}`
await this.storage.userStorage.DecrementUserBalance(ctx.user_id, req.amoutSats + serviceFee, addressData) await this.storage.userStorage.DecrementUserBalance(ctx.user_id, req.amountSats + serviceFee, addressData)
this.addressPaidCb({ hash: txId, index: 0 }, req.address, req.amoutSats, 'internal') this.addressPaidCb({ hash: txId, index: 0 }, req.address, req.amountSats, 'internal')
if (isManagedUser && serviceFee > 0) { if (isManagedUser && serviceFee > 0) {
await this.storage.userStorage.IncrementUserBalance(app.owner.user_id, serviceFee, 'fees') await this.storage.userStorage.IncrementUserBalance(app.owner.user_id, serviceFee, 'fees')
} }
const chainFees = 0 const chainFees = 0
const internalAddress = true const internalAddress = true
const newTx = await this.storage.paymentStorage.AddUserTransactionPayment(ctx.user_id, req.address, txId, 0, req.amoutSats, chainFees, serviceFee, internalAddress, blockHeight, app) const newTx = await this.storage.paymentStorage.AddUserTransactionPayment(ctx.user_id, req.address, txId, 0, req.amountSats, chainFees, serviceFee, internalAddress, blockHeight, app)
const user = await this.storage.userStorage.GetUser(ctx.user_id) const user = await this.storage.userStorage.GetUser(ctx.user_id)
const txData = `${newTx.address}:${newTx.tx_hash}` const txData = `${newTx.address}:${newTx.tx_hash}`
this.storage.eventsLog.LogEvent({ type: 'address_payment', userId: ctx.user_id, appId: app.app_id, appUserId: "", balance: user.balance_sats, data: txData, amount: req.amoutSats }) this.storage.eventsLog.LogEvent({ type: 'address_payment', userId: ctx.user_id, appId: app.app_id, appUserId: "", balance: user.balance_sats, data: txData, amount: req.amountSats })
return { return {
txId: txId, txId: txId,
operation_id: `${Types.UserOperationType.OUTGOING_TX}-${newTx.serial_id}`, operation_id: `${Types.UserOperationType.OUTGOING_TX}-${newTx.serial_id}`,

View file

@ -26,6 +26,7 @@ export class NostrSender {
if (!this.isReady) { if (!this.isReady) {
this.log("tried to send before nostr was ready, caching request") this.log("tried to send before nostr was ready, caching request")
this.pendingSends.push({ initiator, data, relays }) this.pendingSends.push({ initiator, data, relays })
return
} }
this._nostrSend(initiator, data, relays) this._nostrSend(initiator, data, relays)
} }

View file

@ -159,7 +159,7 @@ export default (mainHandler: Main): Types.ServerMethods => {
PayAddress: async ({ ctx, req }) => { PayAddress: async ({ ctx, req }) => {
const err = Types.PayAddressRequestValidate(req, { const err = Types.PayAddressRequestValidate(req, {
address_CustomCheck: addr => addr !== '', address_CustomCheck: addr => addr !== '',
amoutSats_CustomCheck: amt => amt > 0, amountSats_CustomCheck: amt => amt > 0,
// satsPerVByte_CustomCheck: spb => spb > 0 // satsPerVByte_CustomCheck: spb => spb > 0
}) })
if (err != null) throw new Error(err.message) if (err != null) throw new Error(err.message)