From 28183ed3ed86b9dffb00c7688d7f681d2697d106 Mon Sep 17 00:00:00 2001 From: boufni95 Date: Fri, 24 Nov 2023 22:52:42 +0100 Subject: [PATCH] fix --- proto/lnd/router.ts | 16 ++++++++-------- src/services/lnd/index.spec.ts | 2 +- src/services/main/index.ts | 19 ++++++++++--------- src/services/main/paymentManager.ts | 4 +++- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/proto/lnd/router.ts b/proto/lnd/router.ts index 2a52b054..edb624cd 100644 --- a/proto/lnd/router.ts +++ b/proto/lnd/router.ts @@ -1,7 +1,7 @@ // @generated by protobuf-ts 2.8.1 // @generated from protobuf file "router.proto" (package "routerrpc", syntax proto3) // tslint:disable -import { Payment } from "./lightning"; +import { Payment } from "./lightning.js"; import { ServiceType } from "@protobuf-ts/runtime-rpc"; import type { BinaryWriteOptions } from "@protobuf-ts/runtime"; import type { IBinaryWriter } from "@protobuf-ts/runtime"; @@ -13,13 +13,13 @@ import type { PartialMessage } from "@protobuf-ts/runtime"; import { reflectionMergePartial } from "@protobuf-ts/runtime"; import { MESSAGE_TYPE } from "@protobuf-ts/runtime"; import { MessageType } from "@protobuf-ts/runtime"; -import { ChannelPoint } from "./lightning"; -import { HTLCAttempt } from "./lightning"; -import { Failure_FailureCode } from "./lightning"; -import { Failure } from "./lightning"; -import { Route } from "./lightning"; -import { FeatureBit } from "./lightning"; -import { RouteHint } from "./lightning"; +import { ChannelPoint } from "./lightning.js"; +import { HTLCAttempt } from "./lightning.js"; +import { Failure_FailureCode } from "./lightning.js"; +import { Failure } from "./lightning.js"; +import { Route } from "./lightning.js"; +import { FeatureBit } from "./lightning.js"; +import { RouteHint } from "./lightning.js"; /** * @generated from protobuf message routerrpc.SendPaymentRequest */ diff --git a/src/services/lnd/index.spec.ts b/src/services/lnd/index.spec.ts index f8deb889..cd0f27ed 100644 --- a/src/services/lnd/index.spec.ts +++ b/src/services/lnd/index.spec.ts @@ -5,7 +5,7 @@ import NewLightningHandler, { LightningHandler, LoadLndSettingsFromEnv } from '. let lnd: LightningHandler export const ignore = true export const setup = async () => { - lnd = NewLightningHandler(LoadLndSettingsFromEnv(true), console.log, console.log) + lnd = NewLightningHandler(LoadLndSettingsFromEnv(true), console.log, console.log, console.log) await lnd.Warmup() } export const teardown = () => { diff --git a/src/services/main/index.ts b/src/services/main/index.ts index 787d1288..9da3ab25 100644 --- a/src/services/main/index.ts +++ b/src/services/main/index.ts @@ -74,16 +74,17 @@ export default class { NewBlockHandler = async (height: number) => { const confirmed = await this.paymentManager.CheckPendingTransactions(height) - await Promise.all(confirmed.map(async ({ confs, type, tx: t }) => { - const { serial_id } = t - if (type === 'outgoing') { - await this.storage.paymentStorage.UpdateUserTransactionPayment(serial_id, { confs }) + await Promise.all(confirmed.map(async c => { + + if (c.type === 'outgoing') { + await this.storage.paymentStorage.UpdateUserTransactionPayment(c.tx.serial_id, { confs: c.confs }) } else { - await this.storage.paymentStorage.UpdateAddressReceivingTransaction(serial_id, { confs }) - await this.storage.userStorage.IncrementUserBalance(t.user_address.user.user_id, t.paid_amount - t.service_fee) - const operationId = `${Types.UserOperationType.INCOMING_TX}-${t.user_address.serial_id}` - const op = { amount: t.paid_amount, paidAtUnix: Date.now() / 1000, inbound: true, type: Types.UserOperationType.INCOMING_TX, identifier: t.user_address.address, operationId, network_fee: 0, service_fee: t.service_fee, confirmed: true } - this.sendOperationToNostr(t.user_address.linkedApplication!, t.user_address.user.user_id, op) + const { user_address: userAddress, paid_amount: amount, service_fee: serviceFee, serial_id: serialId } = c.tx + await this.storage.paymentStorage.UpdateAddressReceivingTransaction(serialId, { confs: c.confs }) + await this.storage.userStorage.IncrementUserBalance(userAddress.user.user_id, amount - serviceFee) + const operationId = `${Types.UserOperationType.INCOMING_TX}-${userAddress.serial_id}` + const op = { amount, paidAtUnix: Date.now() / 1000, inbound: true, type: Types.UserOperationType.INCOMING_TX, identifier: userAddress.address, operationId, network_fee: 0, service_fee: serviceFee, confirmed: true } + this.sendOperationToNostr(userAddress.linkedApplication!, userAddress.user.user_id, op) } })) } diff --git a/src/services/main/paymentManager.ts b/src/services/main/paymentManager.ts index 759e0f8b..fbc2e356 100644 --- a/src/services/main/paymentManager.ts +++ b/src/services/main/paymentManager.ts @@ -26,6 +26,7 @@ interface UserOperationInfo { service_fees?: number routing_fees?: number chain_fees?: number + confs?: number } type PendingTx = { type: 'incoming', tx: AddressReceivingTransaction } | { type: 'outgoing', tx: UserTransactionPayment } const defaultLnurlPayMetadata = `[["text/plain", "lnurl pay to Lightning.pub"]]` @@ -416,7 +417,8 @@ export default class { identifier, operationId: `${type}-${o.serial_id}`, network_fee: o.chain_fees || o.routing_fees || 0, - service_fee: o.service_fee || o.service_fees || 0 + service_fee: o.service_fee || o.service_fees || 0, + confirmed: typeof o.confs === 'number' ? o.confs > 0 : true } }) }