Skip to content

Commit

Permalink
Merge branch 'master' into tests-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
boufni95 committed Apr 25, 2024
2 parents 9528ede + c2a9770 commit ddea84a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
4 changes: 3 additions & 1 deletion src/services/lnd/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Types from '../../../proto/autogenerated/ts/types.js'
import { GetInfoResponse, NewAddressResponse, AddInvoiceResponse, PayReq, Payment, SendCoinsResponse, EstimateFeeResponse, TransactionDetails, ClosedChannelsResponse, ListChannelsResponse, PendingChannelsResponse, ListInvoiceResponse, ListPaymentsResponse } from '../../../proto/lnd/lightning.js'
import { GetInfoResponse, NewAddressResponse, AddInvoiceResponse, PayReq, Payment, SendCoinsResponse, EstimateFeeResponse, TransactionDetails, ClosedChannelsResponse, ListChannelsResponse, PendingChannelsResponse, ListInvoiceResponse, ListPaymentsResponse, ChannelBalanceResponse, WalletBalanceResponse } from '../../../proto/lnd/lightning.js'
import { EnvMustBeNonEmptyString, EnvMustBeInteger, EnvCanBeBoolean } from '../helpers/envParser.js'
import { AddressPaidCb, BalanceInfo, DecodedInvoice, HtlcCb, Invoice, InvoicePaidCb, LndSettings, NewBlockCb, NodeInfo, PaidInvoice } from './settings.js'
import LND from './lnd.js'
Expand Down Expand Up @@ -32,6 +32,8 @@ export interface LightningHandler {
ChannelBalance(): Promise<{ local: number, remote: number }>
GetTransactions(startHeight: number): Promise<TransactionDetails>
GetBalance(): Promise<BalanceInfo>
GetWalletBalance(): Promise<WalletBalanceResponse>
GetChannelBalance(): Promise<ChannelBalanceResponse>
ListClosedChannels(): Promise<ClosedChannelsResponse>
ListChannels(): Promise<ListChannelsResponse>
ListPendingChannels(): Promise<PendingChannelsResponse>
Expand Down
10 changes: 10 additions & 0 deletions src/services/lnd/lnd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,16 @@ export default class {
return res.response
}

async GetChannelBalance() {
const res = await this.lightning.channelBalance({}, DeadLineMetadata())
return res.response
}

async GetWalletBalance() {
const res = await this.lightning.walletBalance({}, DeadLineMetadata())
return res.response
}

async GetBalance(): Promise<BalanceInfo> {
const wRes = await this.lightning.walletBalance({}, DeadLineMetadata())
const { confirmedBalance, unconfirmedBalance, totalBalance } = wRes.response
Expand Down
7 changes: 5 additions & 2 deletions src/services/lnd/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as Types from '../../../proto/autogenerated/ts/types.js'
import { LightningClient } from '../../../proto/lnd/lightning.client.js'
import { InvoicesClient } from '../../../proto/lnd/invoices.client.js'
import { RouterClient } from '../../../proto/lnd/router.client.js'
import { GetInfoResponse, AddressType, NewAddressResponse, AddInvoiceResponse, Invoice_InvoiceState, PayReq, Payment_PaymentStatus, Payment, PaymentFailureReason, SendCoinsResponse, EstimateFeeResponse, TransactionDetails, ClosedChannelsResponse, ListChannelsResponse, PendingChannelsResponse, ListInvoiceResponse, ListPaymentsResponse } from '../../../proto/lnd/lightning.js'
import { GetInfoResponse, AddressType, NewAddressResponse, AddInvoiceResponse, Invoice_InvoiceState, PayReq, Payment_PaymentStatus, Payment, PaymentFailureReason, SendCoinsResponse, EstimateFeeResponse, TransactionDetails, ClosedChannelsResponse, ListChannelsResponse, PendingChannelsResponse, ListInvoiceResponse, ListPaymentsResponse, ChannelBalanceResponse, WalletBalanceResponse } from '../../../proto/lnd/lightning.js'
import { OpenChannelReq } from './openChannelReq.js';
import { AddInvoiceReq } from './addInvoiceReq.js';
import { PayInvoiceReq } from './payInvoiceReq.js';
Expand Down Expand Up @@ -35,10 +35,13 @@ export default class {
this.invoicePaidCb(invoice, decoded.numSatoshis || amount, false)
delete this.invoicesAwaiting[invoice]
}

GetChannelBalance(): Promise<ChannelBalanceResponse> {
throw new Error("Method not implemented.");
}
Stop() { }
async Warmup() { }

async GetWalletBalance(): Promise<WalletBalanceResponse> { throw new Error("ListClosedChannels disabled in mock mode") }
async ListClosedChannels(): Promise<ClosedChannelsResponse> { throw new Error("ListClosedChannels disabled in mock mode") }
async ListChannels(): Promise<ListChannelsResponse> { throw new Error("ListChannels disabled in mock mode") }
async ListPendingChannels(): Promise<PendingChannelsResponse> { throw new Error("ListPendingChannels disabled in mock mode") }
Expand Down
25 changes: 8 additions & 17 deletions src/services/main/watchdog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,15 @@ export class Watchdog {
}, 1000 * 60)
}



getTotalLndBalance = async (usersTotal: number) => {
const localLog = getLogger({ appName: "debugLndBalancev2" })
const { confirmedBalance, channelsBalance } = await this.lnd.GetBalance()
this.log(confirmedBalance, "sats in chain wallet")
localLog({ c: channelsBalance, u: usersTotal })
let totalBalance = confirmedBalance
channelsBalance.forEach(c => {
let totalBalanceInHtlcs = 0
c.htlcs.forEach(htlc => {
if (htlc.incoming) {
totalBalanceInHtlcs += htlc.amount
} else {
//totalBalanceInHtlcs -= htlc.amount
}
})
totalBalance += c.localBalanceSats + totalBalanceInHtlcs
})
return totalBalance
const walletBalance = await this.lnd.GetWalletBalance()
this.log(Number(walletBalance.confirmedBalance), "sats in chain wallet")
const channelsBalance = await this.lnd.GetChannelBalance()
getLogger({ appName: "debugLndBalancev3" })({ w: walletBalance, c: channelsBalance, u: usersTotal })
const localChannelsBalance = Number(channelsBalance.localBalance?.sat || 0)
return Number(walletBalance.confirmedBalance) + localChannelsBalance
}

checkBalanceUpdate = (deltaLnd: number, deltaUsers: number) => {
Expand Down

0 comments on commit ddea84a

Please sign in to comment.