This commit is contained in:
boufni95 2023-11-24 22:52:42 +01:00
parent 6c219c6f62
commit 28183ed3ed
4 changed files with 22 additions and 19 deletions

View file

@ -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
*/

View file

@ -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 = () => {

View file

@ -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)
}
}))
}

View file

@ -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
}
})
}