Skip to content

Cardano Conversions is a library that exposes a various deterministic conversions that can be done in Cardano, e.g. utc time to absolute slot, utc time to epoch no, epoch no to absolute slot, etc

License

Notifications You must be signed in to change notification settings

cardano-foundation/cf-cardano-conversions-java

Repository files navigation

Cardano Conversions Utility

Build License Discord

Motivation

In Cardano, as a developer, it is common to find in various projects that there is a need to convert between various metrics, eg. start epoch to utc time, or slot number to epoch number or yet another metric.

This library aims to provide a common place for such conversions.

Requirements

  • JDK (>= 17)
  • maven (>= 3)

Local Cloning && Building

git clone https://github.com/cardano-foundation/cf-cardano-conversions-java

cd cf-cardano-conversions-java
./mvnw clean install

Maven / Gradle

Maven:

<dependency>
    <groupId>org.cardanofoundation</groupId>
    <artifactId>cf-cardano-conversions-java</artifactId>
    <version>1.1.0</version>
</dependency>

Gradle:

implementation("org.cardanofoundation:cf-cardano-conversions-java:1.1.0")

Example usages:

var converters = ClasspathConversionsFactory.createConverters(NetworkType.MAINNET);

var epochStartTime = converters.epoch().beginningOfEpochToUTCTime(445);
var utcTime = converters.slot().slotToTime(109090938L);
var epochNo = converters.time().utcTimeToEpochNo(LocalDateTime.of(2023, 11, 22, 9, 48, 58));
var lastAlonzoAbsoluteSlot = converters.epoch().endingOfEpochToAbsoluteSlot(364);
var firstRealAbsoluteSlotBabbage = converters.era().firstRealSlot(EraType.Babbage);
var firstRealTimeBabbage = converters.era().firstRealEraTime(EraType.Babbage);

System.out.println(epochStartTime); // LocalDateTime.of(2023, 10, 27, 21, 44, 51)
System.out.println(utcTime); // LocalDateTime.of(2023, 11, 22, 12, 47, 9)
System.out.println(epochNo); // 450
System.out.println(lastAlonzoAbsoluteSlot); // 72316799L
System.out.println(firstRealAbsoluteSlotBabbage); // 72316896L
System.out.println(firstRealTimeBabbage); // LocalDateTime.of(2022, 9, 22, 21, 46, 27)

Additional Docs

About

Cardano Conversions is a library that exposes a various deterministic conversions that can be done in Cardano, e.g. utc time to absolute slot, utc time to epoch no, epoch no to absolute slot, etc

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages