mirror of
https://github.com/MAGICGrants/rust-monero-explorer.git
synced 2026-01-08 04:03:50 -05:00
Add docker files, readme and workflow
This commit is contained in:
61
.github/workflows/publish.yml
vendored
Normal file
61
.github/workflows/publish.yml
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
#
|
||||
name: Create and publish a Docker image
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "*"
|
||||
|
||||
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
|
||||
env:
|
||||
REGISTRY: ghcr.io
|
||||
IMAGE_NAME: magicgrants/rust-monero-explorer-api
|
||||
|
||||
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
|
||||
jobs:
|
||||
build-and-push-image:
|
||||
runs-on: ubuntu-latest
|
||||
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
attestations: write
|
||||
id-token: write
|
||||
#
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
|
||||
- name: Log in to the Container registry
|
||||
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
|
||||
- name: Extract metadata (tags, labels) for Docker
|
||||
id: meta
|
||||
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
|
||||
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see [Usage](https://github.com/docker/build-push-action#usage) in the README of the `docker/build-push-action` repository.
|
||||
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
|
||||
- name: Build and push Docker image
|
||||
id: push
|
||||
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
|
||||
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see [Using artifact attestations to establish provenance for builds](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds).
|
||||
- name: Generate artifact attestation
|
||||
uses: actions/attest-build-provenance@v2
|
||||
with:
|
||||
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
subject-digest: ${{ steps.push.outputs.digest }}
|
||||
push-to-registry: true
|
||||
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -1941,8 +1941,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
||||
|
||||
[[package]]
|
||||
name = "rust-monero-explorer"
|
||||
version = "0.1.0"
|
||||
name = "rust-monero-explorer-api"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"actix-web",
|
||||
"clap",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rust-monero-explorer"
|
||||
version = "0.1.0"
|
||||
name = "rust-monero-explorer-api"
|
||||
version = "0.0.1"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
11
Dockerfile
11
Dockerfile
@@ -6,14 +6,15 @@ COPY .git ./.git
|
||||
COPY Cargo.toml Cargo.lock ./
|
||||
COPY external ./external
|
||||
COPY src ./src
|
||||
RUN apk add musl-dev git
|
||||
RUN apk add musl-dev git curl
|
||||
RUN cargo build --release
|
||||
|
||||
FROM alpine:3
|
||||
|
||||
COPY --from=builder /build/target/release/rust-monero-explorer /usr/local/bin
|
||||
RUN addgroup -S explorer && adduser -S explorer -G explorer
|
||||
USER explorer
|
||||
COPY --from=builder /build/target/release/rust-monero-explorer-api /usr/local/bin
|
||||
RUN addgroup -S cuprate && adduser -S cuprate -G cuprate
|
||||
USER cuprate
|
||||
|
||||
EXPOSE 8081
|
||||
ENTRYPOINT ["rust-monero-explorer"]
|
||||
ENTRYPOINT ["rust-monero-explorer-api"]
|
||||
CMD ["-i", "0.0.0.0"]
|
||||
135
README.md
Normal file
135
README.md
Normal file
@@ -0,0 +1,135 @@
|
||||
# Rust Monero Explorer API
|
||||
|
||||
This is a Monero block explorer API written in Rust, built on Cuprate. Features are currently limited to a `/transaction` and `/block` endpoints, and new features will be added as the Cuprate project grows.
|
||||
|
||||
## Building and running
|
||||
|
||||
To be able to run the program, you need a synced Cuprate node. The explorer will attempt to find
|
||||
the Cuprate directory at `/home/<user>/.local/share/cuprate` by default, you can use `-d <path>` to
|
||||
set a custom directory.
|
||||
|
||||
First, install the required packages:
|
||||
|
||||
```bash
|
||||
# ArchLinux-based
|
||||
sudo pacman -S gcc glibc
|
||||
|
||||
# Debian-based
|
||||
sudo apt install libgcc1 libc6
|
||||
```
|
||||
|
||||
You can build the program using:
|
||||
|
||||
```bash
|
||||
cargo build --release
|
||||
```
|
||||
|
||||
Then run:
|
||||
|
||||
```bash
|
||||
./target/release/rust-monero-explorer-api
|
||||
```
|
||||
|
||||
## Docker
|
||||
|
||||
You can spin up a Docker container as follows:
|
||||
|
||||
```bash
|
||||
docker run --name rust-monero-explorer-api -p 8081:8081 -v <REPLACE_WITH_CUPRATE_DIR>:/home/cuprate/.local/share/cuprate -d ghcr.io/magicgrants/rust-monero-explorer-api:latest
|
||||
```
|
||||
|
||||
If you wish to run `cuprated` as well, you can simply use:
|
||||
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
## Command line options
|
||||
|
||||
```
|
||||
$ ./target/release/rust-monero-explorer-api -h
|
||||
|
||||
Usage: rust-monero-explorer-api [OPTIONS]
|
||||
|
||||
Options:
|
||||
-d, --cuprate-dir <CUPRATE_DIR>
|
||||
-p, --port <PORT> [default: 8081]
|
||||
-i, --bind-ip <BIND_IP> [default: 127.0.0.1]
|
||||
-h, --help Print help
|
||||
-V, --version Print version
|
||||
```
|
||||
|
||||
## Endpoints
|
||||
|
||||
### `GET /api/block/<block_number>`
|
||||
|
||||
```json
|
||||
{
|
||||
"hash": "d29c51c4354a396f370335035540fc94372bd277c2f65b50cc5bd2608a92c69c",
|
||||
"timestamp": 1697813342,
|
||||
"weight": 100297,
|
||||
"cumulative_generated_coins": 18347197280903987000,
|
||||
"cumulative_difficulty_low": 312831186335450240,
|
||||
"cumulative_difficulty_high": 0,
|
||||
"cumulative_rct_outs": 82193323,
|
||||
"long_term_weight": 176470,
|
||||
"transactions": [
|
||||
{
|
||||
"hash": "e4516854a5984eaf5f8750ac7af41d1e0b2c602a2297a673001e8c0af88eba11",
|
||||
"version": 2,
|
||||
"is_coinbase": true,
|
||||
"weight": 2219,
|
||||
"extra": "0148b077c1706fe9070f867d478c74431276194bf6139ca3e852abe553b8d9bee40209016c16bd243ed88d7f"
|
||||
},
|
||||
...
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### `GET /api/transaction/<tx_hash>`
|
||||
|
||||
```json
|
||||
{
|
||||
"hash": "fc4f31a3c568e1584b7ceb2cb1b2ffb02c1a8a968f78d5a032baf82ff90187d0",
|
||||
"version": 2,
|
||||
"unlock_time": 0,
|
||||
"is_coinbase": false,
|
||||
"confirmation_height": 3000000,
|
||||
"timestamp": 1697813342,
|
||||
"weight": 2216,
|
||||
"inputs": [
|
||||
{
|
||||
"amount": 0,
|
||||
"key_image": "645fba8a0be85364d955c2796acb582f743a1a0e64e9aa16595d6f948bac7508",
|
||||
"mixins": [
|
||||
{
|
||||
"height": 2932485,
|
||||
"public_key": "2b454431c761008af372929fd672e2e5670c3e8b7016e133ae47ceb928f8ff32",
|
||||
"tx_hash": "b610f576147e7ad6fa1afbe76ab41c1c49c123e8a37244d97964fddf9e8e6de8"
|
||||
},
|
||||
...
|
||||
]
|
||||
},
|
||||
...
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"amount": 0,
|
||||
"public_key": "d519e7c800f03a2f38bfbf8087628721f44bfae992ec453b73d3c817b1015c26"
|
||||
},
|
||||
{
|
||||
"amount": 0,
|
||||
"public_key": "32c2334828c763909e403be1db3e7a9a9469c3de1144e9d31f52094437774152"
|
||||
}
|
||||
],
|
||||
"extra": "01b84f7e585851b9f1d82dc462991f7191418dd75f3cf4d3c90bd0451136f908dd0209018b24d81a9039ede7"
|
||||
}
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
Pull requests welcome! Thanks for supporting MAGIC Grants.
|
||||
|
||||
## License
|
||||
|
||||
[MIT](https://github.com/MAGICGrants/rust-monero-explorer-api/blob/main/LICENSE)
|
||||
23
docker-compose.yml
Normal file
23
docker-compose.yml
Normal file
@@ -0,0 +1,23 @@
|
||||
services:
|
||||
rust-monero-explorer-api:
|
||||
image: ghcr.io/magicgrants/rust-monero-explorer-api
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:8081/api/block/1"]
|
||||
interval: 1m30s
|
||||
timeout: 30s
|
||||
retries: 5
|
||||
start_period: 30s
|
||||
volumes:
|
||||
- cuprate-data:/home/cuprate/.local/share/cuprate
|
||||
ports:
|
||||
- 8081:8081
|
||||
|
||||
cuprated:
|
||||
image: ghcr.io/magicgrants/cuprate
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- cuprate-data:/home/cuprate/.local/share/cuprate
|
||||
|
||||
volumes:
|
||||
cuprate-data:
|
||||
11
src/main.rs
11
src/main.rs
@@ -51,19 +51,22 @@ impl error::ResponseError for AppError {
|
||||
}
|
||||
|
||||
impl From<FromHexError> for AppError {
|
||||
fn from(_: FromHexError) -> Self {
|
||||
fn from(error: FromHexError) -> Self {
|
||||
println!("{:?}", error);
|
||||
AppError::InternalServerError
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RuntimeError> for AppError {
|
||||
fn from(_: RuntimeError) -> Self {
|
||||
fn from(error: RuntimeError) -> Self {
|
||||
println!("{:?}", error);
|
||||
AppError::InternalServerError
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for AppError {
|
||||
fn from(_: std::io::Error) -> Self {
|
||||
fn from(error: std::io::Error) -> Self {
|
||||
println!("{:?}", error);
|
||||
AppError::InternalServerError
|
||||
}
|
||||
}
|
||||
@@ -374,7 +377,7 @@ async fn main() -> std::io::Result<()> {
|
||||
let mut data_file_path = final_cuprate_dir.clone();
|
||||
data_file_path.push("blockchain");
|
||||
data_file_path.push("data.mdb");
|
||||
|
||||
|
||||
if !final_cuprate_dir.exists() || !data_file_path.exists() {
|
||||
println!("Could not find Cuprate directory at {:?}", final_cuprate_dir);
|
||||
exit(1);
|
||||
|
||||
Reference in New Issue
Block a user