From f5606a37d582420c47185f02b9ceda903bdc831d Mon Sep 17 00:00:00 2001 From: Thomas Dinsdale-Young Date: Thu, 19 Sep 2024 15:17:07 +0200 Subject: [PATCH] Report correct available balance with node version < 7. --- ChangeLog.md | 2 ++ src/Concordium/Client/GRPC2.hs | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 2b1f9370..a36a2ce7 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,8 @@ ## Unreleased +- Display the correct "at disposal" balance when used with node versions prior to 7. + ## 7.0.0 - Support node version 7 and protocol version 7. diff --git a/src/Concordium/Client/GRPC2.hs b/src/Concordium/Client/GRPC2.hs index b84c019f..4e95bc7d 100644 --- a/src/Concordium/Client/GRPC2.hs +++ b/src/Concordium/Client/GRPC2.hs @@ -729,7 +729,17 @@ instance FromProto Proto.AccountInfo where Just asi -> fromProto asi aiAccountAddress <- fromProto $ ai ^. ProtoFields.address aiAccountCooldowns <- mapM fromProto $ ai ^. ProtoFields.cooldowns - aiAccountAvailableAmount <- fromProto $ ai ^. ProtoFields.availableBalance + -- The available balance is only provided by node version 7 onwards, so we compute it + -- if it is not present. + mAvailableBalance <- mapM fromProto $ ai ^. ProtoFields.maybe'availableBalance + let stakedTotal = + sum (cooldownAmount <$> aiAccountCooldowns) + case aiStakingInfo of + AccountStakingDelegated{..} -> asiStakedAmount + AccountStakingBaker{..} -> asiStakedAmount + AccountStakingNone -> 0 + let computedAvailable = + aiAccountAmount - max stakedTotal (releaseTotal aiAccountReleaseSchedule) + let aiAccountAvailableAmount = fromMaybe computedAvailable mAvailableBalance return AccountInfo{..} where versionTag = 0