GithubHelp home page GithubHelp logo

encryptedriver / fuel-indexer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fuellabs/fuel-indexer

0.0 0.0 0.0 24.96 MB

๐Ÿ—ƒ The Fuel indexer is a standalone service that can be used to index various components of the Fuel blockchain.

Home Page: https://fuellabs.github.io/fuel-indexer

Shell 1.22% Rust 97.49% Smarty 0.16% Dockerfile 0.26% Sway 0.87%

fuel-indexer's Introduction

Fuel Indexer logo

GitHub commits since latest release (by date including pre-releases)

The Fuel indexer is a standalone service that can be used to index various components of the blockchain. These indexable components include blocks, transactions, receipts, and state within the Fuel network, allowing for high-performance read-only access to the blockchain for advanced dApp use-cases.

Want to get started right away? Check out our Quickstart!

For Users

Users of the Fuel indexer project include dApp developers looking to write flexible data-based backends for their dApp frontends, as well as index operators who are interested in managing one or many indexer projects for dApp developers.

Dependencies

fuelup

  • We use fuelup in order to get the binaries produced by services in the Fuel ecosystem. Fuelup will install binaries related to the Fuel node, the Fuel indexer, the Fuel orchestrator (forc), and other components.
  • fuelup can be downloaded here.

WebAssembly

Two additonal cargo components will be required to build your indexers: wasm-snip and the wasm32-unknown-unknown target.

  • To install wasm-snip:
cargo install wasm-snip

To install the wasm32-unknown-unknown target via rustup:

rustup target add wasm32-unknown-unknown

IMPORTANT: Users on Apple Silicon macOS systems may experience trouble when trying to build WASM modules due to its clang binary not supporting WASM targets. If encountered, you can install a binary with better support from Homebrew (brew install llvm) and instruct rustc to leverage it by setting the following environment variables:

  • AR=/opt/homebrew/opt/llvm/bin/llvm-ar
  • CC=/opt/homebrew/opt/llvm/bin/clang

forc-index Plugin

The primary way of developing Fuel indexers for end users is via the forc-index plugin. The forc-index plugin, is a CLI tool that is bundled with Fuel's primary CLI tooling interface, forc ("Fuel Orchestrator").

As mentioned in the dependencies section, the forc-index plugin is made available once you download fuelup.

If you've successfully gone through the Quickstart, you should already have forc-index installed and available in your PATH.

forc index --help
Fuel Indexer Orchestrator

USAGE:
    forc-index <SUBCOMMAND>

OPTIONS:
    -h, --help       Print help information
    -V, --version    Print version information

SUBCOMMANDS:
    auth        Authenticate against an indexer service
    build       Build an indexer
    check       Check for Fuel indexer components
    deploy      Deploy an indexer to an indexer service
    help        Print this message or the help of the given subcommand(s)
    kill        Kill the indexer process. Note that this command will kill any process listening
                    on the default indexer port or the port specified by the `--port` flag
    new         Create a new indexer project in a new directory
    postgres    Fuel Postgres Orchestrator
    remove      Stop and remove a running indexer
    start       Standalone binary for the Fuel indexer service
    status      Check the status of a registered indexer

WebAssembly (WASM) modules

Within the context of the Fuel indexer, WebAssembly (WASM) modules are binaries that are compiled to a wasm32-unknown-unknown target, which can then be deployed to a running indexer service, and run as isolated runtime environments.

There are a few points that Fuel indexer users should know when using WASM:

  1. WASM modules are only used if the execution mode specified in your manifest file is wasm.

  2. Developers should be aware of what things may not work off-the-shelf in a module: file I/O, thread spawning, and anything that depends on system libraries. This is due to the technological limitations of WASM as a whole; more information can be found here.

  3. As of this writing, there is a small bug in newly built Fuel indexer WASM modules that produces a WASM runtime error due to an errant upstream dependency. For now, a quick workaround requires the use of wasm-snip to remove the errant symbols from the WASM module. More info can be found in the related script here.

IMPORTANT: Users on Apple Silicon macOS systems may experience trouble when trying to build WASM modules due to its clang binary not supporting WASM targets. If encountered, you can install a binary with better support from Homebrew (brew install llvm) and instruct rustc to leverage it by setting the following environment variables:

  • export AR=/opt/homebrew/opt/llvm/bin/llvm-ar
  • export CC=/opt/homebrew/opt/llvm/bin/clang

For Contributors

Contributors of the Fuel indexer project are devs looking to help backends for their dApps.

Dev Dependencies

docker

IMPORTANT: Docker is not required to run the Fuel indexer.

  • We use Docker to produce reproducible environments for users that may be concerned with installing components with large sets of dependencies (e.g. PostgreSQL).
  • Docker can be downloaded here.

Database

At this time, the Fuel indexer requires the use of a database. We currently support a single database option: PostgreSQL. PostgreSQL is a database solution with a complex feature set and requires a database server.

PostgreSQL

Note: The following explanation is for demonstration purposes only. A production setup should use secure users, permissions, and passwords.

On macOS systems, you can install PostgreSQL through Homebrew. If it isn't present on your system, you can install it according to the instructions. Once installed, you can add PostgreSQL to your system by running brew install postgresql. You can then start the service through brew services start postgresql. You'll need to create a database for your indexed data, which you can do by running createdb [DATABASE_NAME]. You may also need to create the postgres role; you can do so by running createuser -s postgres.

For Linux-based systems, the installation process is similar. First, you should install PostgreSQL according to your distribution's instructions. Once installed, there should be a new postgres user account; you can switch to that account by running sudo -i -u postgres. After you have switched accounts, you may need to create a postgres database role by running createuser --interactive. You will be asked a few questions; the name of the role should be postgres and you should elect for the new role to be a superuser. Finally, you can create a database by running createdb [DATABASE_NAME].

In either case, your PostgreSQL database should now be accessible at postgres://postgres@localhost:5432/[DATABASE_NAME].

SQLx

  • After setting up your database, you should install sqlx-cli in order to run migrations for your indexer service.
  • You can do so by running cargo install sqlx-cli --features postgres.
  • Once installed, you can run the migrations by running the following command after changing DATABASE_URL to match your setup.

Building from Source

Clone repository

git clone [email protected]:FuelLabs/fuel-indexer.git && cd fuel-indexer/

Run migrations

PostgreSQL migrations

cd packages/fuel-indexer-database/postgres
DATABASE_URL=postgres://postgres@localhost sqlx migrate run

Start the service

cargo run --bin fuel-indexer

If no configuration file or other options are passed, the service will default to a postgres://postgres@localhost database connection.

Testing

Fuel indexer tests are currently broken out by a database feature flag. In order to run tests with a PostgreSQL backend, use --features postgres.

Default tests

cargo test --locked --workspace --all-targets

End-to-end tests

cargo test --locked --workspace --all-targets --features postgres

trybuild tests

For tests related to the meta-programming used in the Fuel indexer, we use trybuild.

RUSTFLAGS='-D warnings' cargo test -p fuel-indexer-tests --features trybuild --locked

Contributing

If you're interested in contributing PRs to make the Fuel indexer a better project, feel free to read our contributors document.

Read the book

Whether you're a user or a contributor, for more detailed info on how the Fuel indexer service works, make sure you read the book.

fuel-indexer's People

Contributors

0xmovses avatar adlerjohn avatar alicanc avatar ap-atul avatar bitzoic avatar braqzen avatar deekerno avatar ellioty avatar lostman avatar luizstacio avatar mitchmindtree avatar ra0x3 avatar rakita avatar rfuelsh avatar sarahschwartz avatar tjsharp1 avatar uberscott avatar valanm22 avatar voxelot avatar yash251 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.