Skip to content

Commit

Permalink
Load amounts paid so far for existing open payment channels
Browse files Browse the repository at this point in the history
  • Loading branch information
neerajvijay1997 committed Oct 17, 2023
1 parent 7190cfc commit 8200d8d
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion paymentsmanager/payments_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/hashicorp/golang-lru/v2/expirable"
"github.com/statechannels/go-nitro/node"
"github.com/statechannels/go-nitro/node/query"
"github.com/statechannels/go-nitro/payments"
"github.com/statechannels/go-nitro/types"
)
Expand Down Expand Up @@ -183,6 +184,25 @@ func (pm *PaymentsManager) getChannelCounterparty(channelId types.Destination) (
}

func (pm *PaymentsManager) loadPaymentChannels() error {
// TODO: Implement
ledgerChannels, err := pm.nitro.GetAllLedgerChannels()
if err != nil {
return err
}

for _, ledgerChannel := range ledgerChannels {
if ledgerChannel.Status == query.Open {
paymentChannels, err := pm.nitro.GetPaymentChannelsByLedger(ledgerChannel.ID)
if err != nil {
return err
}

for _, paymentChannel := range paymentChannels {
if paymentChannel.Status == query.Open {
pm.paidSoFarOnChannel.Add(paymentChannel.ID.String(), (*big.Int)(paymentChannel.Balance.PaidSoFar))
}
}
}
}

return nil
}

0 comments on commit 8200d8d

Please sign in to comment.