aptos-sf-stream

Crates.ioaptos-sf-stream
lib.rsaptos-sf-stream
version0.2.7
sourcesrc
created_at2022-08-14 08:08:30.677906
updated_at2022-08-16 07:53:57.681226
descriptionAptos StreamingFast Stream
homepagehttps://aptoslabs.com
repositoryhttps://github.com/aptos-labs/aptos-core
max_upload_size
id645281
size126,828
(aptos-crates)

documentation

README

API

This module provides a StreamingFast Streamer for pushing protobuf data from the Aptos Blockchain

Overview

Models

Models or types are defined in the aptos-api-types package (in the directory /api/types).

These types handle deserialization between internal data types and API response JSON types. These are then used to construct the Protobuf messages.

Error Handling

All internal errors should be converted into anyhow::Error first.

Unit Test

Handler tests should cover all aspects of features and functions.

A TestContext is implemented to create components' stubs that API handlers are connected to. These stubs are more close to real production components, instead of mocks, so that tests can ensure the handlers are working well with other components in the systems. For example, we use real AptosDB implementation in tests for API layers to interact with the database.

Most of the utility functions are provided by the TestContext.

Integration/Smoke Test

Run integration/smoke tests in testsuite/smoke-test

cargo test --test "forge" "api::"

Aptos Node Operation

The Aptos node generates the following default SF-Stream configuration:

sf_stream:
  enabled: false

When sf_stream.enabled is set to true, the SF-Stream will be enabled, and transactions will be streamed to stdout.

Installing Protobuf Compiler

Install protoc

protoc is a Protocol Buffer compiler. It is needed to generate code for Rust and other languages, out of the protobuf definitions you will create or get through third-party Substreams packages.

There are multiple ways on how to do it. Here is the official documentation of protocol buffer compiler.

Install protoc-gen-prost

This tool helps you render Rust structures out of protobuf definitions, for use in your Substreams modules. It is called by protoc following their plugin system. Install it with:

  cargo install protoc-gen-prost

If you forget to install protoc, when generating the definitions, you might see error about cmake not defined, this is a fallback when protoc is not found.

Install buf

https://buf.build is a tool used to simplify the generation of typed structures in any language. It invokes protoc and simplifies a good number of things. Substreams packages are compatible with buf Images.

See the installation instructions here.

Build proto

cargo build

Testing

Connect to Firehose

To test with firehose, we need to build aptos-node

cd ../aptos-node
cargo install --path .

If necessary, set path to aptos-node

export PATH={path to directory containing aptos-core repo}:$PATH

Then follow instructions in https://github.com/streamingfast/firehose-aptos

Commit count: 18889

cargo fmt