-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97da651
commit b42b92b
Showing
27 changed files
with
15,594 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.cardanofoundation; | ||
|
||
import java.net.URL; | ||
|
||
public record ConversionsConfig(URL byronGenesisFile, URL shelleyGenesisFile) {} |
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
src/main/java/org/cardanofoundation/conversions/AbsoluteSlotConversions.java
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
src/main/java/org/cardanofoundation/conversions/ConversionRuntimeException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.cardanofoundation.conversions; | ||
|
||
public class ConversionRuntimeException extends RuntimeException { | ||
|
||
public ConversionRuntimeException() {} | ||
|
||
public ConversionRuntimeException(String message) { | ||
super(message); | ||
} | ||
|
||
public ConversionRuntimeException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
public ConversionRuntimeException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
src/main/java/org/cardanofoundation/conversions/EpochConversions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,104 @@ | ||
package org.cardanofoundation.conversions; | ||
|
||
import static org.cardanofoundation.conversions.domain.EpochOffset.END; | ||
import static org.cardanofoundation.conversions.domain.EpochOffset.START; | ||
import static org.cardanofoundation.conversions.domain.Era.Byron; | ||
import static org.cardanofoundation.conversions.domain.Era.Shelley; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.cardanofoundation.conversions.domain.EpochOffset; | ||
import org.cardanofoundation.conversions.domain.Era; | ||
|
||
@AllArgsConstructor | ||
@Slf4j | ||
public final class EpochConversions { | ||
|
||
private final GenesisConfig genesisConfig; | ||
|
||
/** | ||
* @param epochNo | ||
* @return | ||
*/ | ||
public long beginningOfEpochToAbsoluteSlot(int epochNo) { | ||
return epochToAbsoluteSlot(epochNo, START); | ||
} | ||
|
||
/** | ||
* @param epochNo | ||
* @return | ||
*/ | ||
public long endingOfEpochToAbsoluteSlot(int epochNo) { | ||
return epochToAbsoluteSlot(epochNo, END); | ||
} | ||
|
||
/** | ||
* Converts epoch to absolute slot. | ||
* | ||
* @param epochNo | ||
* @param epochOffset - either epoch's start or epoch's end | ||
* @return | ||
*/ | ||
public long epochToAbsoluteSlot(int epochNo, EpochOffset epochOffset) { | ||
return switch (epochOffset) { | ||
case START -> { | ||
if (epochNo <= genesisConfig.lastByronEpochNo()) { | ||
yield absoluteSlotAssumingEra(Byron, epochNo, END) | ||
- genesisConfig.slotsPerEpoch(Byron) | ||
+ 1; | ||
} | ||
|
||
yield epochToAbsoluteSlot(epochNo, END) - genesisConfig.slotsPerEpoch(Shelley); | ||
} | ||
case END -> { | ||
if (epochNo <= genesisConfig.lastByronEpochNo()) { | ||
yield absoluteSlotAssumingEra(Byron, epochNo, END); | ||
} | ||
|
||
var lastByronSlot = genesisConfig.lastByronSlot(); | ||
var countLastByronSlot = lastByronSlot + 1; | ||
|
||
var postByronEpochs = (epochNo - genesisConfig.lastByronEpochNo() - 1); | ||
|
||
yield 1 + countLastByronSlot + absoluteSlotAssumingEra(Shelley, postByronEpochs, END); | ||
} | ||
}; | ||
} | ||
|
||
public LocalDateTime epochToTime(int epochNo, | ||
EpochOffset epochOffset) { | ||
// if (epochNo < 208) { | ||
// return genesisConfig.getByronSlotLength() * epochNo; | ||
// } | ||
// | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Returns absolute slot but assuming one is in particular era. | ||
* | ||
* @param era | ||
* @param epochNo | ||
* @param epochOffset - start or end of a given epoch | ||
* @return | ||
*/ | ||
long absoluteSlotAssumingEra(Era era, int epochNo, EpochOffset epochOffset) { | ||
long allSlotsPerEra = genesisConfig.slotsPerEpoch(era) * epochNo; | ||
|
||
return switch (epochOffset) { | ||
case START -> allSlotsPerEra; | ||
case END -> allSlotsPerEra + ((genesisConfig.slotsPerEpoch(era)) - 1); | ||
}; | ||
} | ||
|
||
long firstEpochSlot(Era era, int epochNo) { | ||
return absoluteSlotAssumingEra(era, epochNo, START); | ||
} | ||
|
||
long lastEpochSlot(Era era, int epochNo) { | ||
return absoluteSlotAssumingEra(era, epochNo, END); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/org/cardanofoundation/conversions/EraService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package org.cardanofoundation.conversions; | ||
|
||
import static org.cardanofoundation.conversions.domain.Consensus.*; | ||
import static org.cardanofoundation.conversions.domain.LedgerProtocol.Praos; | ||
import static org.cardanofoundation.conversions.domain.ProtocolVersion.VER_0_0; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import lombok.AllArgsConstructor; | ||
import org.cardanofoundation.conversions.domain.*; | ||
|
||
@AllArgsConstructor | ||
public class EraService { | ||
|
||
private final GenesisConfig genesisConfig; | ||
|
||
public List<EraLine> all(NetworkType networkType) { | ||
return switch (networkType) { | ||
case MAINNET -> mainnet(); | ||
case PREPROD -> preprod(); | ||
default -> List.of(); | ||
}; | ||
} | ||
|
||
private List<EraLine> mainnet() { | ||
return List.of( | ||
new EraLine(Phase.Byron, Era.Byron, 0, VER_0_0, Praos, Ouroboros_Classic), | ||
new EraLine(Phase.Byron, Era.Byron, 3801600, ProtocolVersion.VER_1_0, Praos, Ouroboros_BFT), | ||
new EraLine( | ||
Phase.Shelley, Era.Shelley, 4492800, ProtocolVersion.VER_2_0, Praos, Ouroboros_Praos), | ||
new EraLine( | ||
Phase.Gougen, Era.Allegra, 16588800, ProtocolVersion.VER_3_0, Praos, Ouroboros_Praos), | ||
new EraLine( | ||
Phase.Gougen, Era.Mary, 23068800, ProtocolVersion.VER_4_0, Praos, Ouroboros_Praos), | ||
new EraLine( | ||
Phase.Gougen, Era.Alonzo, 39916975, ProtocolVersion.VER_5_0, Praos, Ouroboros_Praos), | ||
new EraLine( | ||
Phase.Gougen, Era.Alonzo, 43372972, ProtocolVersion.VER_6_0, Praos, Ouroboros_Praos), | ||
new EraLine( | ||
Phase.Gougen, Era.Babbage, 72316896, ProtocolVersion.VER_7_0, Praos, Ouroboros_Praos), | ||
new EraLine( | ||
Phase.Gougen, Era.Babbage, 84844885, ProtocolVersion.VER_8_0, Praos, Ouroboros_Praos)); | ||
} | ||
|
||
private List<EraLine> preprod() { | ||
return List.of( | ||
new EraLine(Phase.Byron, Era.Byron, 0, ProtocolVersion.VER_1_0, Praos, Ouroboros_BFT), | ||
new EraLine( | ||
Phase.Shelley, Era.Shelley, 84242 + 1, ProtocolVersion.VER_2_0, Praos, Ouroboros_Praos), | ||
new EraLine( | ||
Phase.Gougen, Era.Allegra, 518360 + 1, ProtocolVersion.VER_3_0, Praos, Ouroboros_Praos), | ||
new EraLine( | ||
Phase.Gougen, Era.Mary, 950340 + 1, ProtocolVersion.VER_4_0, Praos, Ouroboros_Praos), | ||
new EraLine( | ||
Phase.Gougen, Era.Alonzo, 1382348 + 1, ProtocolVersion.VER_6_0, Praos, Ouroboros_Praos), | ||
new EraLine( | ||
Phase.Gougen, | ||
Era.Babbage, | ||
3542390 + 1, | ||
ProtocolVersion.VER_8_0, | ||
Praos, | ||
Ouroboros_Praos)); | ||
} | ||
|
||
public Optional<EraLine> findShelleyEraLine(NetworkType networkType) { | ||
return all(networkType).stream().filter(eraLine -> eraLine.era() == Era.Shelley).findFirst(); | ||
} | ||
} | ||
|
||
// last byron block on pre-prod: 84242 |
Oops, something went wrong.