Skip to content

Commit

Permalink
Merge branch 'master' into event-index-filter
Browse files Browse the repository at this point in the history
  • Loading branch information
h0ngcha0 authored Dec 25, 2024
2 parents 03c0adb + 58f74c1 commit b2d6bfd
Show file tree
Hide file tree
Showing 171 changed files with 8,767 additions and 2,809 deletions.
124 changes: 82 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Alephium explorer backend

Alephium's explorer backend is an indexer that provides a RESTful API to query the Alephium blockchain.

It serves https://explorer.alephium.org/ as well as our wallets.


## Prerequisites

- Java (11 or 17 is recommended)
- [PostgreSQL](https://www.postgresql.org)
- A running [full node](full-node/getting-started.md)

## Development

### 1. Install the dependencies
Expand Down Expand Up @@ -27,33 +38,75 @@ You need to have [Postgresql][postgresql] and [sbt][sbt] installed in your syste
postgres=# CREATE DATABASE explorer;
```

### 3. Start the server
### 3. Run explorer-backend
#### 3.1 Using `sbt`
##### Start the server

```shell
sbt app/run
```

### 4. Single Jar
##### Build the Jar

```shell
sbt app/assembly
```

The resulting assembly file will appear in `app/target/scala-2.13/` directory.

#### 3.2 Run the released jar

Download the lastest jar in our [release page](https://github.com/alephium/explorer-backend/releases/latest)

Run it with:

```shell
java -jar explorer-backend-x.x.x.jar
```

### 4. Configuration

Configuration file at [`/app/src/main/resources/application.conf`](https://github.com/alephium/explorer-backend/blob/master/app/src/main/resources/application.conf) can be customized using environment variables

Everything can be overridden in two ways:

#### `user.conf` file

You can change the config in the `~/.alephium-explorer-backend/user.conf` file. e.g:

```conf
alephium {
explorer {
port = 9191 //Change default 9090 port
}
}
```

#### Environment variables

Every value has a corresponding environment variable, you can find all of them in the [application.conf](https://github.com/alephium/explorer-backend/blob/master/app/src/main/resources/application.conf). e.g:

```shell
export EXPLORER_PORT=9191
```

### 5. Restore archived database

Syncing all data from scratch can take a while, you can choose to start from a snapshot instead.
Snapshots are available at https://archives.alephium.org/
Download the `explore-db` dump you want and simply run:

Alephium [archives repository](https://archives.alephium.org) contains the snapshots for explorer backend database.
The snapshot can be loaded in the postgresql database of the explorer-backend at the first run, using the command below.

* Make sure to use the network you want to load the snapshot for, and the correct database name and user.
* The database must be created before running the command and must be empty.

```shell
psql database_name < dump_file
alephium_network=mainnet
pg_user=postgres
database=explorer
curl -L $(curl -L -s https://archives.alephium.org/archives/${alephium_network}/explorer-db/_latest.txt) | gunzip -c | psql -U $pg_user -d $database
```

Please note that `database_name` must have been created before, see point 2 on how to do it.

### Querying hashes

Hash strings are stored as [bytea][bytea]. To query a hash string in
Expand All @@ -65,6 +118,28 @@ from "utransactions"
where "hash" = decode('f25f43b7fb13b1ec5f1a2d3acd1bebb9d27143cdc4586725162b9d88301b9bd7', 'hex');
```

### 6. Configuration

There are two ways to configure the application:

#### Environment variables

Every value in [application.conf](/app/src/main/resources/application.conf) file can be overridden by an environment variable.

```shell
export BLOCKFLOW_NETWORK_ID = 1
export DB_NAME = "testnet"
```

#### Using `user.conf` file

The same way it's done in our full node, you can override the [application.conf](/app/src/main/resources/application.conf) file by creating a `user.conf` file in the `EXPLORER_HOME` folder, which default to `~/.alephium-explorer-backend`.

```conf
alephium.blockflow.network-id = 1
db.db.name = "testnet"
```

## Benchmark

### 1. Create benchmark database
Expand Down Expand Up @@ -129,38 +204,3 @@ apiMappings ++=
)
)
```

## Node Customization

The steps below are for developers who want to reference a full node on another computer, such as a Raspberry Pi, that is on the same subnet.

### Explorer: `/app/src/main/resources/application.conf`

```shell
blockflow {
host = "full-node-ip-address"
port = 12973

direct-clique-access = false
direct-clique-access = ${?BLOCKFLOW_DIRECT_CLIQUE_ACCESS}

network-id = 0
network-id = ${?BLOCKFLOW_NETWORK_ID}
groupNum = 4
api-key = "full-node-api-key"
}
```

### Full Node: `user.conf`

```shell
alephium.api.api-key = "full-node-api-key"
alephium.api.network-interface = "0.0.0.0"

alephium.network.bind-address = "0.0.0.0:9973"
alephium.network.internal-address = "full-node-ip-address:9973"
alephium.network.coordinator-address = "full-node-ip-address:9973"
```



25 changes: 16 additions & 9 deletions app/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ explorer {
sync-period = 5 seconds
sync-period = ${?EXPLORER_SYNC_PERIOD}

# Schedule time for HolderService
holder-service-schedule-time = "04:00"
holder-service-schedule-time = ${?EXPLORER_HOLDER_SERVICE_SCHEDULE_TIME}

# Schedule time for TokenSupplyService
token-supply-service-schedule-time = "02:00"
token-supply-service-schedule-time = ${?EXPLORER_TOKEN_SUPPLY_SERVICE_SCHEDULE_TIME}
Expand All @@ -38,6 +42,7 @@ explorer {
cache-row-count-reload-period = 10 seconds
cache-block-times-reload-period = 5 seconds
cache-latest-blocks-reload-period = 5 seconds
cache-metrics-reload-period = 1 minutes

#How many transaction can be exported at max
export-txs-number-threshold = 10000
Expand Down Expand Up @@ -68,17 +73,12 @@ explorer {
}

market {
symbol-name {
"ALPH" = "alephium",
"USDC" = "usd-coin",
"USDT" = "tether",
"WBTC" = "wrapped-bitcoin",
"WETH" = "weth",
"DAI" = "dai",
"AYIN" = "ayin"
chart-symbol-name {
"ALPH" = "alephium"
}
currencies = [
"btc",
"eth",
"usd",
"eur",
"chf",
Expand All @@ -90,8 +90,15 @@ explorer {
"cad",
"aud"
]
liquidity-minimum = 100 # in USD
liquidity-minimum = ${?EXPLORER_MARKET_LIQUIDITY_MINIMUM}
mobula-uri = "https://api.mobula.io/api/1"
mobula-uri = ${?EXPLORER_MARKET_MOBULA_URI}
coingecko-uri = "https://api.coingecko.com/api/v3"
market-chart-days = 366
coingecko-uri = ${?EXPLORER_MARKET_COINGECKO_URI}
token-list-uri = "https://raw.githubusercontent.com/alephium/token-list/master/tokens/mainnet.json"
token-list-uri = ${?EXPLORER_MARKET_TOKEN_LIST_URI}
market-chart-days = 365
market-chart-days = ${?EXPLORER_MARKET_CHART_DAYS}
}
}
Expand Down
Loading

0 comments on commit b2d6bfd

Please sign in to comment.