Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…rosetta-java into refactor/RA-106-find-block-opt
  • Loading branch information
shleger committed May 8, 2024
2 parents 4e97a45 + 0382f05 commit 3931f26
Show file tree
Hide file tree
Showing 31 changed files with 159 additions and 458 deletions.
2 changes: 2 additions & 0 deletions .env.IntegrationTest
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ CARDANO_NODE_DB="node/db"
CARDANO_CONFIG="./config/${NETWORK}"

#api env
API_DOCKER_IMAGE_TAG="main"
API_SPRING_PROFILES_ACTIVE_API="dev"
API_PORT="8081"
TRANSACTION_TTL=3000
Expand All @@ -44,6 +45,7 @@ GENESIS_CONWAY_PATH=/config/${NETWORK}/conway-genesis.json
PRINT_EXCEPTION=true

#yaci env
INDEXER_DOCKER_IMAGE_TAG="main"
YACI_SPRING_PROFILES="postgres" # database profiles: h2, postgres
INDEXER_NODE_PORT=3001
INITIAL_BALANCE_CALCULATION_BLOCK=0
Expand Down
2 changes: 2 additions & 0 deletions .env.docker-compose
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ CARDANO_NODE_DB="./node/db"
CARDANO_CONFIG="./config/${NETWORK}"

#api env
API_DOCKER_IMAGE_TAG="main"
API_SPRING_PROFILES_ACTIVE_API="dev" # staging. Additional profiles: mempool (if mempool should be activated)
API_PORT=8081
TRANSACTION_TTL=3000
Expand All @@ -43,6 +44,7 @@ API_NODE_SOCKET_PATH=./node/node.socket
PRINT_EXCEPTION=true

#yaci env
INDEXER_DOCKER_IMAGE_TAG="main"
YACI_SPRING_PROFILES="postgres" # database profiles: h2, postgres
INDEXER_NODE_PORT=3001
MEMPOOL_ENABLED=false
Expand Down
2 changes: 2 additions & 0 deletions .env.h2
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ NODE_SUBMIT_API_PORT=8090
CARDANO_NODE_SOCKET=./node-ipc

#api env
API_DOCKER_IMAGE_TAG="main"
API_SPRING_PROFILES_ACTIVE=h2
API_SPRING_PROFILES_ACTIVE_API=dev
API_EXPOSED_PORT=8081
Expand All @@ -42,6 +43,7 @@ GENESIS_CONWAY_PATH=config/${NETWORK}/conway-genesis.json
PRINT_EXCEPTION=true

#yaci env
INDEXER_DOCKER_IMAGE_TAG="main"
API_SPRING_PROFILES_ACTIVE_YACI_INDEXER=postgres # database profiles: h2, postgres
INDEXER_NODE_PORT=3001
INITIAL_BALANCE_CALCULATION_BLOCK=0
61 changes: 61 additions & 0 deletions .github/actions/build_docker_images/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Build Docker images
description: Builds and pushes Docker images for the Cardano Rosetta project including API, Indexer and All-in-one Image
inputs:
tag:
description: Docker tag
required: true
default: main
isRelease:
description: Is this a release build? If true, the latest tag will be applied
required: false
default: false
secrets:
DOCKERHUB_USERNAME:
description: Docker Hub username
required: true
DOCKERHUB_TOKEN:
description: Docker Hub token
required: true
runs:
using: composite
steps:
- name: API - Build and push Docker ${{ inputs.tag }} image
uses: docker/build-push-action@v4
with:
file: ./api/Dockerfile
tags: cardanofoundation/cardano-rosetta-java-api:${{ inputs.tag }}
push: true
- name: API - Build and push Docker latest image
uses: docker/build-push-action@v4
if: ${{ inputs.isRelease == 'true' }}
with:
file: ./api/Dockerfile
tags: cardanofoundation/cardano-rosetta-java-api:latest
push: true
- name: Indexer - Build and push Docker ${{ inputs.tag }} image
uses: docker/build-push-action@v4
with:
file: ./yaci-indexer/Dockerfile
tags: cardanofoundation/cardano-rosetta-java-indexer:${{ inputs.tag }}
push: true
- name: Indexer - Build and push Docker latest image
uses: docker/build-push-action@v4
if: ${{ inputs.isRelease == 'true' }}
with:
file: ./api/Dockerfile
tags: cardanofoundation/cardano-rosetta-java-indexer:latest
push: true
# TODO will be added when the all-in-one image is ready
# - name: All-in-one - Build and push Docker image
# uses: docker/build-push-action@v4
# with:
# file: ./Dockerfile
# tags: cardanofoundation/cardano-rosetta-java:${{ inputs.tag }}
# push: true
# - name: All-in-one - Build and push Docker latest image
# uses: docker/build-push-action@v4
# if: ${{ inputs.isRelease == 'true' }}
# with:
# file: ./Dockerfile
# tags: cardanofoundation/cardano-rosetta-java:latest
# push: true
39 changes: 9 additions & 30 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -1,42 +1,21 @@
name: Main branch
name: Build main branch

on:
push:
branches: [ main ]
workflow_dispatch:
branches: [ main, feat/RA-64-Containerisation-for-Distribution ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Checkout badges branch
uses: actions/checkout@v3
with:
ref: badges
path: badges

- name: Set up JDK 21
uses: actions/setup-java@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
java-version: '21'
distribution: 'temurin'
cache: maven

- name: Build project
run: mvn -s $GITHUB_WORKSPACE/.github/workflows/maven-settings.xml --batch-mode --update-snapshots clean package --file ./pom.xml
env:
GH_PACKAGES_USER_NAME: ${{ secrets.GH_PACKAGES_USER_NAME }}
GH_PACKAGES_ACCESS_TOKEN: ${{ secrets.GH_PACKAGES_ACCESS_TOKEN }}
- name: Test project
run: mvn -s $GITHUB_WORKSPACE/.github/workflows/maven-settings.xml --batch-mode --update-snapshots clean verify --file ./pom.xml
env:
GH_PACKAGES_USER_NAME: ${{ secrets.GH_PACKAGES_USER_NAME }}
GH_PACKAGES_ACCESS_TOKEN: ${{ secrets.GH_PACKAGES_ACCESS_TOKEN }}

- name: Upload artifacts
uses: actions/upload-artifact@v3
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build Cardano Rosetta Release
uses: ./.github/actions/build_docker_images
with:
name: cardano-rosetta-java
path: api/target/*.jar
tag: main
23 changes: 23 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Build release

on:
release:
types:
- published

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build Cardano Rosetta Release
uses: ./.github/actions/build_docker_images
with:
tag: ${{ github.event.release.tag_name }}
isRelease: true
80 changes: 0 additions & 80 deletions CONTRIBUTING.md

This file was deleted.

84 changes: 6 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,86 +1,14 @@
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=cardano-foundation_cardano-rosetta-java&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=cardano-foundation_cardano-rosetta-java)

# Cardano Rosetta API Java implementation
This repository provides a lightweight java implementation of the Rosetta API. It uses [Yaci-Store](https://github.com/bloxbean/yaci-store) as an indexer
to fetch the data from the node.
## What the project is about?

## :construction: Current Development status :construction:
- [x] Architecture clean up for yaci-store
- [x] Docker-compose setup
- [x] Integration test setup
- API calls
- Data API
- [x] /network/*
- [x] /block/*
- [x] /account/*
- /mempool
- [x] /mempool
- [ ] /mempool/transaction
- [x] Construction API
- [ ] Extending Tests
- [ ] Refactoring
This repository provides a lightweight java implementation of the [Rosetta API](https://github.com/coinbase/mesh-specifications). It uses [Yaci-Store](https://github.com/bloxbean/yaci-store) as an indexer
to fetch the data from a Cardano node.

## Getting Started

### Prerequisites
## Documentation

- Docker
- Docker Compose
- Java 21
- For integration tests: Node 14+

### How to build

- Clone the repository
- For local environment:
- Copy `.env.docker-compose` to `.env`
- Fill the `.env` file with your values (explain below) or use the provided for docker-compose setup
- Start SpringBoot application with `mvn spring-boot:run` within submodule `api` or `yaci-indexer`
- Run `docker compose -f docker-compose.yaml up --build` to start rosetta api service including yaci-store and a cardano node
- Using the provided env file `docker-compose --env-file .env.docker-compose -f docker-compose.yaml up --build`
* Note: the first time you run the command, it will take a little bit of your time to build the cardano-node, and next time it will be cached when run. So please be patient.

### How to run integration tests

- Run `docker compose --env-file .env.IntegrationTest -f docker-integration-test-environment.yaml up --build -d --wait`
- Using CLI
- Install newman `npm install -g newman` (Node version 14+ needed)
- Run `newman run ./postmanTests/rosetta-java.postman_collection.json -e ./postmanTests/Rosetta-java-env.postman_environment.json -r cli`
- Using Postman
- Install [Postman](https://www.postman.com)
- Import the collection `./postmanTests/rosetta-java.postman_collection.json`
- Import the environment `./postmanTests/Rosetta-java-env.postman_environment.json`
- Run the collection


### Restore a snapshot
**TBD for yaci-store**

A node snapshot can be downloaded from [here](https://csnapshots.io/). Download the snapshot and place the files within the `CARDANO_NODE_DB` Path.

For mainnet the following command can be used to restore the snapshot:
```bash
curl -o - https://downloads.csnapshots.io/mainnet/$(curl -s https://downloads.csnapshots.io/mainnet/mainnet-db-snapshot.json| jq -r .[].file_name ) | lz4 -c -d - | tar -x -C ${CARDANO_NODE_DB}
```

### Mempool Monitoring
Mempool monitoring can be activated when adding the spring profile `mempool` to the rosetta api service.
It will be turned off by default. Since it is only working for nodes, which participate in the network and available within P2P from other nodes.
So the Node itself needs extra configuration to be able to query mempool transactions.

### Documentation
- [Architecture Overview](https://github.com/cardano-foundation/cardano-rosetta-java/wiki)
- [Cardano specific API Additions](./docs/cardano-specific-api-additions.md)
- [Dev H2 Quickstart Guide](./docs/dev-h2-quick-start-guide.md)
- [Environment Variables](./docs/environment-variables.md)
- [Rosetta-cli tests](./docs/rosetta-cli-tests.md)

## Contributing

File an issue or a PR or reach out directly to us if you want to contribute.

When contributing to this project and interacting with others, please follow our [Contributing Guidelines](./CONTRIBUTING.md) and [Code of Conduct](./CODE-OF-CONDUCT.md).
Please refer to our [wiki pages](https://github.com/cardano-foundation/cardano-rosetta-java/wiki) for more information on the project.

---

Thanks for visiting and enjoy :heart:!
Thanks for visiting us and enjoy :heart:!
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class BlockTx {
protected String hash;
protected String blockHash;
protected Long blockNo;
protected String fee; // TODO can be removed if we found another way to calculate the size
protected String fee;
protected Long size;
protected Long scriptSize;
protected List<Utxo> inputs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ProtocolParams {
private ExtraEntropy extraEntropy; //13
private ProtocolVersion protocolVersion; //14
@JsonProperty("minUTxOValue")
private BigInteger minUtxo; //TODO //15
private BigInteger minUtxoValue; //15

private BigInteger minPoolCost; //16
private BigInteger adaPerUtxoByte; //17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ProtocolParamsEntity {
private String extraEntropy; //13
private Integer protocolMajorVer; //14
private Integer protocolMinorVer; //14
private BigInteger minUtxo; //TODO //15
private BigInteger minUtxo; //15

private BigInteger minPoolCost; //16
private BigInteger adaPerUtxoByte; //17
Expand Down

0 comments on commit 3931f26

Please sign in to comment.