Skip to content

Commit 2883c78

Browse files
canndrewknocte
authored andcommitted
Add SpendableBalanceFromParts function
This is needed in geewallet for getting the spendable balance of channel when we only have the components of a Channel object but not the Channel object itself. This method can be moved onto SavedChannelState when the necessary fields remaining in Channel/Commitments are moved there.
1 parent d3f833b commit 2883c78

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

src/DotNetLightning.Core/Channel/Channel.fs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,18 +1166,22 @@ and Channel = {
11661166
(not self.SavedChannelState.LocalChanges.ACKed.IsEmpty)
11671167
|| (not self.Commitments.ProposedRemoteChanges.IsEmpty)
11681168

1169-
member self.SpendableBalance (): LNMoney =
1170-
let remoteParams = self.SavedChannelState.StaticChannelConfig.RemoteParams
1169+
// FIXME: This is a temporary hack to make the geewallet updates easier.
1170+
static member SpendableBalanceFromParts (savedChannelState: SavedChannelState)
1171+
(remoteNextCommitInfo: Option<RemoteNextCommitInfo>)
1172+
(commitments: Commitments)
1173+
: LNMoney =
1174+
let remoteParams = savedChannelState.StaticChannelConfig.RemoteParams
11711175
let remoteCommit =
1172-
match self.RemoteNextCommitInfo with
1176+
match remoteNextCommitInfo with
11731177
| Some (RemoteNextCommitInfo.Waiting nextRemoteCommit) -> nextRemoteCommit
1174-
| Some (RemoteNextCommitInfo.Revoked _info) -> self.SavedChannelState.RemoteCommit
1178+
| Some (RemoteNextCommitInfo.Revoked _info) -> savedChannelState.RemoteCommit
11751179
// TODO: This could return a proper error, or report the full balance
11761180
| None -> failwith "funding is not locked"
11771181
let reducedRes =
11781182
remoteCommit.Spec.Reduce(
1179-
self.SavedChannelState.RemoteChanges.ACKed,
1180-
self.Commitments.ProposedLocalChanges
1183+
savedChannelState.RemoteChanges.ACKed,
1184+
commitments.ProposedLocalChanges
11811185
)
11821186
let reduced =
11831187
match reducedRes with
@@ -1188,7 +1192,7 @@ and Channel = {
11881192
err
11891193
| Ok reduced -> reduced
11901194
let fees =
1191-
if self.SavedChannelState.StaticChannelConfig.IsFunder then
1195+
if savedChannelState.StaticChannelConfig.IsFunder then
11921196
Transactions.commitTxFee remoteParams.DustLimitSatoshis reduced
11931197
|> LNMoney.FromMoney
11941198
else
@@ -1205,6 +1209,13 @@ and Channel = {
12051209
let spendableBalance = LNMoney.Max(untrimmedMax, untrimmedSpendableBalance)
12061210
spendableBalance
12071211

1212+
1213+
member self.SpendableBalance (): LNMoney =
1214+
Channel.SpendableBalanceFromParts
1215+
self.SavedChannelState
1216+
self.RemoteNextCommitInfo
1217+
self.Commitments
1218+
12081219
member private self.sendCommit (remoteNextCommitInfo: RemoteNextCommitInfo)
12091220
: Result<CommitmentSignedMsg * Channel, ChannelError> =
12101221
let channelPrivKeys = self.ChannelPrivKeys

0 commit comments

Comments
 (0)