Skip to content

Commit

Permalink
Resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
schwartz-concordium committed Aug 2, 2023
1 parent 1189143 commit 51c8d1a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 27 deletions.
9 changes: 4 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
- The SDK requires node version 6 or later.
- Breaking changes
- `ConsensusInfo`
- `SlotDuration` is now an nullable field, only present in protocols 1-5.
- `SlotDuration` is now a nullable field, only present in protocols 1-5.
- Bugfix: `BlockLastArrivedTime` was wrongly mapped from `BlockLastReceivedTime`.
- `BlockInfo`
- `BlockSlot` is nullable, and only present in protocols 1-5
- `BlockSlot` is now a nullable field, and only present in protocols 1-5
- Added
- `ConsensusInfo`
- a new field `ConcordiumBftDetails` is added, that is present if protocol
version is 6 or higher
- a new field `ConcordiumBftDetails` is added that is present if protocol 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.
- a new field`BakerPoolPendingChange` is added which is present if any change is pending on baker pool.

## 3.0.0
- Added
Expand Down
4 changes: 0 additions & 4 deletions src/Helpers/DateAndTimeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@ internal static class DateAndTimeExtensions

internal static DateTimeOffset ToDateTimeOffset(this TransactionTime seconds) => DateTimeOffset.FromUnixTimeSeconds((long)seconds.Value);

/// <summary>
/// Durations from mapped from GRPC are given in milliseconds.
/// </summary>
/// <returns></returns>
internal static TimeSpan ToTimeSpan(this Duration duration) => TimeSpan.FromMilliseconds(duration.Value);
}
3 changes: 1 addition & 2 deletions src/Types/BakerPoolPendingChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public abstract record BakerPoolPendingChange
PoolPendingChange.ChangeOneofCase.Reduce =>
new BakerPoolReduceStakePending(CcdAmount.From(pendingChange.Reduce.ReducedEquityCapital), pendingChange.Reduce.EffectiveTime.ToDateTimeOffset()),
PoolPendingChange.ChangeOneofCase.Remove =>
new BakerPoolRemovePending(pendingChange.Remove.EffectiveTime.ToDateTimeOffset())
,
new BakerPoolRemovePending(pendingChange.Remove.EffectiveTime.ToDateTimeOffset()),
PoolPendingChange.ChangeOneofCase.None => null,
_ => throw new MissingEnumException<PoolPendingChange.ChangeOneofCase>(pendingChange.ChangeCase)
};
Expand Down
16 changes: 7 additions & 9 deletions src/Types/ConcordiumBftDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,26 @@ namespace Concordium.Sdk.Types;
/// Parameters pertaining to the Concordium BFT consensus.
/// </summary>
/// <param name="CurrentTimeoutDuration">The current duration to wait before a round times out.</param>
/// <param name="Round">The current round.</param>
/// <param name="Epoch">The current epoch.</param>
/// <param name="CurrentRound">The current round.</param>
/// <param name="CurrentEpoch">The current epoch.</param>
/// <param name="TriggerBlockTime">
/// The first block in the epoch with timestamp at least this is considered
/// The first block in the epoc with a timestamp equal to or later than this timestamp, is considered
/// to be the trigger block for the epoch transition.
/// </param>
public sealed record ConcordiumBftDetails(TimeSpan CurrentTimeoutDuration, Round CurrentRound, Epoch Epoch, DateTimeOffset TriggerBlockTime)
public sealed record ConcordiumBftDetails(TimeSpan CurrentTimeoutDuration, Round CurrentRound, Epoch CurrentEpoch, DateTimeOffset TriggerBlockTime)
{
internal static bool TryFrom(Grpc.V2.ConsensusInfo info, out ConcordiumBftDetails? details)
internal static ConcordiumBftDetails? From(Grpc.V2.ConsensusInfo info)
{
if (info.CurrentTimeoutDuration == null || info.CurrentRound == null ||
info.CurrentEpoch == null || info.TriggerBlockTime == null)
{
details = null;
return false;
return null;
}

details = new ConcordiumBftDetails(
return new ConcordiumBftDetails(
info.CurrentTimeoutDuration.ToTimeSpan(),
Round.From(info.CurrentRound),
Epoch.From(info.CurrentEpoch),
info.TriggerBlockTime.ToDateTimeOffset());
return true;
}
}
10 changes: 3 additions & 7 deletions src/Types/ConsensusInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,8 @@ public sealed record ConsensusInfo(
ConcordiumBftDetails? ConcordiumBftDetails
)
{
internal static ConsensusInfo From(Grpc.V2.ConsensusInfo consensusInfo)
{
var _ = ConcordiumBftDetails.TryFrom(consensusInfo, out var concordiumBftDetails);

return new ConsensusInfo(
internal static ConsensusInfo From(Grpc.V2.ConsensusInfo consensusInfo) =>
new(
BestBlock: BlockHash.From(consensusInfo.BestBlock),
GenesisBlock: BlockHash.From(consensusInfo.GenesisBlock),
GenesisTime: consensusInfo.GenesisTime.ToDateTimeOffset(),
Expand Down Expand Up @@ -175,6 +172,5 @@ internal static ConsensusInfo From(Grpc.V2.ConsensusInfo consensusInfo)
LastFinalizedTime: consensusInfo.LastFinalizedTime?.ToDateTimeOffset(),
FinalizationPeriodEma: consensusInfo.HasFinalizationPeriodEma ? consensusInfo.FinalizationPeriodEma : null,
FinalizationPeriodEmsd: consensusInfo.HasFinalizationPeriodEmsd ? consensusInfo.FinalizationPeriodEmsd : null,
ConcordiumBftDetails: concordiumBftDetails);
}
ConcordiumBftDetails: ConcordiumBftDetails.From(consensusInfo));
}

0 comments on commit 51c8d1a

Please sign in to comment.