Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .env.IntegrationTest
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ NETWORK=devkit
PROTOCOL_MAGIC=42

## Postgres image
DB_IMAGE_NAME=postgres
DB_IMAGE_TAG=latest
PG_VERSION_TAG=REL_14_11

## Yaci image
YACI_VERSION=0.10.5
Expand Down Expand Up @@ -138,4 +137,4 @@ DB_POSTGRES_MAX_PARALLEL_WORKERS=4
DB_POSTGRES_SEQ_PAGE_COST=1.0
DB_POSTGRES_JIT=off
DB_POSTGRES_BGWRITER_LRU_MAXPAGES=50
DB_POSTGRES_BGWRITER_DELAY=500ms
DB_POSTGRES_BGWRITER_DELAY=500ms
5 changes: 2 additions & 3 deletions .env.docker-compose
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ PROTOCOL_MAGIC=764824073
# mainnet 764824073, preprod 1, preview 2, sanchonet 4, devkit 42

## Postgres image
DB_IMAGE_NAME=postgres
DB_IMAGE_TAG=14.11-bullseye
PG_VERSION_TAG=REL_14_11

## Postgres variables
DB_NAME=rosetta-java
Expand All @@ -26,7 +25,7 @@ CARDANO_NODE_HOST=cardano-node
CARDANO_NODE_PORT=3001
# Uncomment if you are using local cardano node
CARDANO_NODE_VERSION=10.2.1
CARDANO_NODE_SUBMIT_HOST=cardano-submit-api
CARDANO_NODE_SUBMIT_HOST=$CARDANO_NODE_HOST
NODE_SUBMIT_API_PORT=8090
CARDANO_NODE_DIR=/node
CARDANO_NODE_SOCKET_PATH=${CARDANO_NODE_DIR}/node.socket
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ For every Release we provide pre-built docker images stored in the DockerHub Rep
To start it use the following command:

```bash
docker run --name rosetta -v {CUSTOM_MOUNT_PATH}:/node --env-file ./docker/.env.dockerfile --env-file ./docker/.env.docker-profile-mid-level -p 8082:8082 --shm-size=4g -d cardanofoundation/cardano-rosetta-java:1.2.7
docker run --name rosetta -v {CUSTOM_MOUNT_PATH}:/node --env-file ./docker/.env.dockerfile --env-file ./docker/.env.docker-profile-mid-level -p 8082:8082 --shm-size=4g -d cardanofoundation/cardano-rosetta-java:1.2.8
```

Changes to the configuration can be made by adjusting the `docker/.env.dockerfile` file. For more information on the environment variables, please refer to the [documentation](https://cardano-foundation.github.io/cardano-rosetta-java/docs/install-and-deploy/env-vars).

If you want to use the `cardano-submit-api` you can additionally expose port `8090`. It can then be used to submit raw cbor transaction (API documentation here: [Link](https://input-output-hk.github.io/cardano-rest/submit-api/))

```bash
docker run --name rosetta -v {CUSTOM_MOUNT_PATH}:/node --env-file ./docker/.env.dockerfile --env-file ./docker/.env.docker-profile-mid-level -p 8090:8090 -p 8082:8082 --shm-size=4g -d cardanofoundation/cardano-rosetta-java:1.2.7
docker run --name rosetta -v {CUSTOM_MOUNT_PATH}:/node --env-file ./docker/.env.dockerfile --env-file ./docker/.env.docker-profile-mid-level -p 8090:8090 -p 8082:8082 --shm-size=4g -d cardanofoundation/cardano-rosetta-java:1.2.8
```

### Docker compose
Expand Down
2 changes: 1 addition & 1 deletion api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:22.04 AS build-common
FROM ubuntu:24.04 AS build-common
WORKDIR /build

RUN apt update --fix-missing \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.NoArgsConstructor;

import org.openapitools.client.model.Peer;
import org.openapitools.client.model.SyncStatus;

@Data
@Builder
Expand All @@ -17,5 +18,7 @@ public class NetworkStatus {

private BlockIdentifierExtended latestBlock;
private BlockIdentifierExtended genesisBlock;
private SyncStatus syncStatus;
private List<Peer> peers;

}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public Array decodeTransaction(String encoded) {

@Override
public Long calculateTtl(Long ttlOffset) {
long absoluteSlot = offlineMode ? offlineSlotService.getCurrentSlotBasedOnTime()
long absoluteSlot = offlineMode ? offlineSlotService.getCurrentSlotBasedOnTimeWithFallback()
: ledgerBlockService.findLatestBlockIdentifier().getSlot();

return absoluteSlot + ttlOffset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public ConstructionPreprocessResponse constructionPreprocessService(

int relativeTtl = calculateRelativeTtl(metadata);

long currentSlotBasedOnTime = offlineSlotService.getCurrentSlotBasedOnTime() + relativeTtl;
long currentSlotBasedOnTime = offlineSlotService.getCurrentSlotBasedOnTimeWithFallback() + relativeTtl;

NetworkEnum networkEnum = NetworkEnum.findByName(
networkIdentifier.getNetwork())
Expand Down Expand Up @@ -216,7 +216,7 @@ public ConstructionPayloadsResponse constructionPayloadsService(
private long calculateTtl(ConstructionPayloadsRequestMetadata metadata) {
return metadata != null ?
cardanoConstructionService.checkOrReturnDefaultTtl(metadata.getTtl()) :
offlineSlotService.getCurrentSlotBasedOnTime() + Constants.DEFAULT_RELATIVE_TTL;
offlineSlotService.getCurrentSlotBasedOnTimeWithFallback() + Constants.DEFAULT_RELATIVE_TTL;
}

private ProtocolParams convertProtocolParams(@Nullable ConstructionPayloadsRequestMetadata metadata) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,32 @@ public class NetworkApiImpl implements NetworkApi {

@Override
public ResponseEntity<NetworkListResponse> networkList(
@RequestBody MetadataRequest metadataRequest) {
@RequestBody MetadataRequest metadataRequest) {
final NetworkListResponse networkListResponse = networkService.getNetworkList(metadataRequest);
return ResponseEntity.ok(networkListResponse);
}

@Override
public ResponseEntity<NetworkOptionsResponse> networkOptions(
@RequestBody NetworkRequest networkRequest) {
@RequestBody NetworkRequest networkRequest) {
networkService.verifyNetworkRequest(networkRequest.getNetworkIdentifier());
final NetworkOptionsResponse networkOptionsResponse = networkService.getNetworkOptions(
networkRequest);
networkRequest);

return ResponseEntity.ok(networkOptionsResponse);
}

@Override
public ResponseEntity<NetworkStatusResponse> networkStatus(
@RequestBody NetworkRequest networkRequest) {
@RequestBody NetworkRequest networkRequest) {
if (offlineMode) {
throw ExceptionFactory.notSupportedInOfflineMode();
}

networkService.verifyNetworkRequest(networkRequest.getNetworkIdentifier());

final NetworkStatusResponse networkStatusResponse = networkService.getNetworkStatus(
networkRequest);
networkRequest);

return ResponseEntity.ok(networkStatusResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public interface NetworkMapper {

@Mapping(target = "currentBlockIdentifier.index", source = "latestBlock.number")
@Mapping(target = "currentBlockIdentifier.hash", source = "latestBlock.hash")
@Mapping(target = "syncStatus", source = "syncStatus")
@Mapping(target = "currentBlockTimestamp",
expression = "java(java.util.concurrent.TimeUnit.SECONDS.toMillis(networkStatus.getLatestBlock().getBlockTimeInSeconds()))")
@Mapping(target = "genesisBlockIdentifier.index", source = "genesisBlock.number", defaultValue = "0L")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.cardanofoundation.rosetta.api.network.service;

public interface GenesisDataProvider {

int getProtocolMagic();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.cardanofoundation.rosetta.api.network.service;

import java.io.IOException;
import java.util.Map;
import javax.annotation.PostConstruct;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.cardanofoundation.rosetta.common.exception.ExceptionFactory;
import org.cardanofoundation.rosetta.common.util.FileUtils;

import static org.cardanofoundation.rosetta.common.util.Constants.NETWORK_MAGIC_NAME;

@Service
@Slf4j
@RequiredArgsConstructor
public class GenesisDataProviderImpl implements GenesisDataProvider {

@Value("${cardano.rosetta.GENESIS_SHELLEY_PATH}")
private String genesisShelleyPath;

private int protocolMagic;

@PostConstruct
public void init() {
Map<String, Object> jsonMap = loadGenesisShelleyConfig();
protocolMagic = (Integer) jsonMap.get(NETWORK_MAGIC_NAME);

log.info("Protocol magic number: {} loaded from genesis config json", protocolMagic);
}

@Override
public int getProtocolMagic() {
return protocolMagic;
}

private Map<String, Object> loadGenesisShelleyConfig() {
try {
String content = FileUtils.fileReader(genesisShelleyPath);

return new ObjectMapper().readValue(content, new TypeReference<>() {
});
} catch (IOException e) {
throw ExceptionFactory.configNotFoundException(genesisShelleyPath);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.cardanofoundation.rosetta.api.network.service;


import com.bloxbean.cardano.client.common.model.Network;
import org.openapitools.client.model.MetadataRequest;
import org.openapitools.client.model.NetworkIdentifier;
Expand All @@ -10,6 +9,7 @@
import org.openapitools.client.model.NetworkStatusResponse;

public interface NetworkService {

NetworkListResponse getNetworkList(final MetadataRequest metadataRequest);

NetworkOptionsResponse getNetworkOptions(final NetworkRequest networkRequest);
Expand Down
Loading
Loading