Skip to content

Commit

Permalink
Added BakerPoolPendingChange
Browse files Browse the repository at this point in the history
  • Loading branch information
schwartz-concordium committed Aug 1, 2023
1 parent 35b3bef commit 1189143
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
version is 6 or higher
- `BlockInfo`
- new fields `Round` and `Epoch` that are present in protocol 6 or higher.
- `BakerPoolStatus`
- Added nullable `BakerPoolPendingChange` which is present if any change is pending on baker pool.

## 3.0.0
- Added
Expand Down
46 changes: 46 additions & 0 deletions src/Types/BakerPoolPendingChange.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Concordium.Grpc.V2;
using Concordium.Sdk.Exceptions;
using Concordium.Sdk.Helpers;

namespace Concordium.Sdk.Types;

/// <summary>
/// Pending change in the baker's stake.
/// </summary>
public abstract record BakerPoolPendingChange
{
internal static BakerPoolPendingChange? From(PoolPendingChange? pendingChange)
{
if (pendingChange is null)
{
return null;
}

return pendingChange.ChangeCase switch
{
PoolPendingChange.ChangeOneofCase.Reduce =>
new BakerPoolReduceStakePending(CcdAmount.From(pendingChange.Reduce.ReducedEquityCapital), pendingChange.Reduce.EffectiveTime.ToDateTimeOffset()),
PoolPendingChange.ChangeOneofCase.Remove =>
new BakerPoolRemovePending(pendingChange.Remove.EffectiveTime.ToDateTimeOffset())
,
PoolPendingChange.ChangeOneofCase.None => null,
_ => throw new MissingEnumException<PoolPendingChange.ChangeOneofCase>(pendingChange.ChangeCase)
};
}
}

/// <summary>
/// The baker will be removed at the given time.
/// </summary>
/// <param name="EffectiveTime">Time when the baker will be removed.</param>
public sealed record BakerPoolRemovePending(DateTimeOffset EffectiveTime) : BakerPoolPendingChange;
/// <summary>
/// The stake is being reduced. The new stake will take affect at the given time.
/// </summary>
/// <param name="NewStake">New stake which will take effect.</param>
/// <param name="EffectiveTime">Time when the baker will be removed.</param>
public sealed record BakerPoolReduceStakePending(CcdAmount NewStake, DateTimeOffset EffectiveTime) : BakerPoolPendingChange;




10 changes: 6 additions & 4 deletions src/Types/BakerPoolStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace Concordium.Sdk.Types;
/// if the pool is not a baker in the payday (e.g., because they just
/// registered and a new payday has not started yet).
/// </param>
/// <param name="BakerStakePendingChange">Any pending change to the baker's stake.</param>
/// <param name="AllPoolTotalCapital">Total capital staked across all pools.</param>
public sealed record BakerPoolStatus(
BakerId BakerId,
Expand All @@ -32,7 +33,8 @@ public sealed record BakerPoolStatus(
CcdAmount DelegatedCapitalCap,
BakerPoolInfo PoolInfo,
CurrentPaydayBakerPoolStatus? CurrentPaydayStatus,
CcdAmount AllPoolTotalCapital)
CcdAmount AllPoolTotalCapital,
BakerPoolPendingChange? BakerStakePendingChange)
{
internal static BakerPoolStatus From(Grpc.V2.PoolInfoResponse poolInfoResponse) =>
new(
Expand All @@ -43,7 +45,7 @@ internal static BakerPoolStatus From(Grpc.V2.PoolInfoResponse poolInfoResponse)
CcdAmount.From(poolInfoResponse.DelegatedCapitalCap),
BakerPoolInfo.From(poolInfoResponse.PoolInfo)!,
CurrentPaydayBakerPoolStatus.From(poolInfoResponse.CurrentPaydayInfo),
CcdAmount.From(poolInfoResponse.AllPoolTotalCapital));
CcdAmount.From(poolInfoResponse.AllPoolTotalCapital),
BakerPoolPendingChange.From(poolInfoResponse.EquityPendingChange)
);
}


0 comments on commit 1189143

Please sign in to comment.