https://github.com/cardano-foundation/cf-cardano-conversions-java
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
https://github.com/cardano-foundation/cf-cardano-conversions-java
Last synced: 12 days ago
JSON representation
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
- Host: GitHub
- URL: https://github.com/cardano-foundation/cf-cardano-conversions-java
- Owner: cardano-foundation
- License: mit
- Created: 2023-09-04T11:09:23.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-29T16:14:24.000Z (9 months ago)
- Last Synced: 2024-08-29T18:05:34.628Z (9 months ago)
- Language: Java
- Homepage:
- Size: 782 KB
- Stars: 4
- Watchers: 10
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# Cardano Conversions Utility
[](https://github.com/cardano-foundation/cf-cardano-conversions-java/actions/workflows/tests.yaml)
[](https://github.com/cardano-foundation/cf-cardano-conversions-java/blob/master/LICENSE)
## 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
```shell
git clone https://github.com/cardano-foundation/cf-cardano-conversions-javacd cf-cardano-conversions-java
./mvnw clean install
```## Maven / Gradle
Maven:
```xmlorg.cardanofoundation
cf-cardano-conversions-java
1.2.0```
Gradle:
```
implementation("org.cardanofoundation:cf-cardano-conversions-java:1.2.0")
```## Example usages:
```java
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
- [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md)
- [SECURITY.md](SECURITY.md)
- [CONTRIBUTING.md](CONTRIBUTING.md)
- [CHANGELOG.md](CHANGELOG.md)