#photon #indexer #solana #general #compression #local #model

bin+lib photon-indexer

Solana indexer for general compression

24 breaking releases

new 0.25.0 Jun 18, 2024
0.23.0 Jun 11, 2024
0.3.0 Mar 29, 2024

#2353 in Magic Beans

Download history 241/week @ 2024-03-25 217/week @ 2024-04-01 784/week @ 2024-04-08 244/week @ 2024-04-15 588/week @ 2024-04-22 137/week @ 2024-04-29 557/week @ 2024-05-06 244/week @ 2024-05-13 120/week @ 2024-05-20 226/week @ 2024-05-27 206/week @ 2024-06-03 759/week @ 2024-06-10

1,315 downloads per month

Apache-2.0

2MB
7K SLoC

Photon

Solana indexer for general compression

Installation

To install the photon indexer run:

cargo install photon-indexer

Running Photon

To run photon run:

# Against localnet
photon

# Against devnet
photon --rpc-url=https://api.devnet.solana.com

# Using your local Postgres database instead of the default temporary SQL database
photon --db-url=postgres://postgres@localhost/postgres

# Specifying a start slot. Defaults to 0 for localnet and current for devnet/mainnet
photon --start-slot=123 

# To see more configuration options
photon --help

Database Management

We support both Postgres and SQLite as database backends. Photon uses a auto-configured SQLite in-memory database by default. To specify another database backend run migrations and specify the database url when running Photon.

export DATABASE_URL="postgres://postgres@localhost/postgres" # Or your SQLlite database url
photon-migration up
photon --db-url=$DATABASE_URL

Local Development

Running Tests

To run tests, install and run Postgres and SQLlite locally. For MacOS users, we recommend using Homebrew to run local Postgres: https://wiki.postgresql.org/wiki/Homebrew.

Then export environment variables to configure your RPC and your test Postgres url. For SQLlite testing, we always use an in-memory SQLlite database, so there is no need to configure a test url.

export MAINNET_RPC_URL=https://api.devnet.solana.com
export DEVNET_RPC_URL=https://api.mainnet-beta.solana.com
export TEST_DATABASE_URL="postgres://postgres@localhost/postgres"

Additionally, for tests we use swagger-cli to validate our OpenAPI schemas. So please install it:

npm install -g @apidevtools/swagger-cli

Afterwards finishing setup simply run:

cargo test

Note that for both Postgres and SQLlite all migrations will run automatically during tests. So no prior configuration is needed.

Database Model Autogeneration

To generate database models first install sea-orm-cli:

cargo install sea-orm-cli --version 0.10.6

Then run:

sea-orm-cli generate entity -o src/dao/generated

Documentation Generation

In order to update the OpenAPI schemas for the API please first install the swagger-cli through:

npm install -g @apidevtools/swagger-cli

Then run:

cargo run --bin=photon-openapi

Dependencies

~116MB
~2M SLoC