Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
enhancement: add predicate support
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashad Alston authored and ra0x3 committed Nov 16, 2023
1 parent 61824b1 commit 220eb96
Show file tree
Hide file tree
Showing 78 changed files with 3,734 additions and 1,294 deletions.
1,005 changes: 560 additions & 445 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ fuel-tx = { version = "=0.35.4", default-features = false }
fuel-types = { version = "=0.35.4", default-features = false, features = ["serde"] }
fuel-vm = { version = "=0.35.4", default-features = false }
fuels = { version = "0.50", default-features = false }
fuels-code-gen = { version = "0.50", default-features = false }
serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_json = { version = "1.0", default-features = false }
thiserror = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions ci/Dockerfile.fuel-node
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update -y \
COPY --from=builder /build/target/release/fuel-node .
COPY --from=builder /build/target/release/fuel-node.d .
COPY --from=builder /build/packages/fuel-indexer-tests/test-chain-config.json .
COPY --from=builder /build/packages/fuel-indexer-tests/contracts/fuel-indexer-test/out/debug/fuel-indexer-test.bin .
COPY --from=builder /build/examples/greetings/contracts/greeting/out/debug/greeting.bin .
COPY --from=builder /build/packages/fuel-indexer-tests/sway/fuel-indexer-test/out/debug/fuel-indexer-test.bin .
COPY --from=builder /build/examples/hello-world/contracts/greeting/out/debug/greeting.bin .
1 change: 1 addition & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- [Blocks](./indexing-fuel-types/blocks.md)
- [Transactions](./indexing-fuel-types/transactions.md)
- [Receipts](./indexing-fuel-types/receipts.md)
- [Predicates](./indexing-fuel-types/predicates.md)
- [Indexing Custom Types](./indexing-custom-types/index.md)
- [Storing Records](./storing-records/index.md)
- [Querying](./querying/index.md)
Expand Down
12 changes: 5 additions & 7 deletions docs/src/indexing-custom-types/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,11 @@ Specifically, we should ensure that the `contract_abi` and `graphql_schema` fiel
# as an organization identifier
namespace: fuellabs

# The identifier field is used to identify the given index.
# Unique identifier for this indexer.
identifier: custom_types_example

# The abi option is used to provide a link to the Sway JSON ABI that is generated when you
# build your project.
abi: path/to/custom/type/example/contract-abi.json
# A file path to the contract JSON ABI that is generated when you build your Sway contract.
contract_abi: path/to/custom/type/example/contract-abi.json

# The particular start block after which you'd like your indexer to start indexing events.
start_block: ~
Expand All @@ -197,11 +196,10 @@ end_block: ~
# with the `--indexer_net_config` option.
fuel_client: ~

# The contract_id specifies which particular contract you would like your index to subscribe to.
# Specifies which particular contract(s) you would like your indexer to subscribe to.
contract_id: ~

# The graphql_schema field contains the file path that points to the GraphQL schema for the
# given index.
# A file path that points to the GraphQL schema for the given indexer.
graphql_schema: path/to/custom/type/example/indexer.schema.graphql

# The module field contains a file path that points to code that will be run as an executor inside
Expand Down
1 change: 1 addition & 0 deletions docs/src/indexing-fuel-types/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ This document provides information about Fuel-specific types and provides exampl
- [Blocks](./blocks.md)
- [Transactions](./transactions.md)
- [Receipts](./receipts.md)
- [Predicates](./predicates.md)
56 changes: 56 additions & 0 deletions docs/src/indexing-fuel-types/predicates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Predicates

## Definition

- Immutable and ephemeral.
- Predicates are one of the most important abstractions that Fuel makes availabe. A predicate effectively has two states: a _created_ state, and a _spent_ state. A predicate has a `created` state when the predicate is...created.

- A predicate becomes "created" when a given UTXO inclues certain parameters in its [witness data](./transactions.md).
- A predicate becomes "spent" when the aforementioned UTXO is used as an input into a subsequent [Transaction](./transactions.md), where this subsequent Transaction also includes certain parameters in its witness data.

> TLDR: A predicate is a UTXO that includes extra information sent in the Transaction.
```rust,ignore
/// Standardized `Witness` data format for predicates.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct IndexerPredicate {
/// Hash of associated predicate bytecode
template_id: Bytes32,
/// Configurable constants in predicates.
configurables: Vec<u8>,
/// Relevant TX output indices of predicates that need to be watched.
output_index: u64,
/// UTXO held by predicate.
coin_output: CoinOutput,
/// ID of transaction in which predicate was created.
unspent_tx_id: Bytes32,
/// ID of transaction in which predicate was spent.
spent_tx_id: Option<Bytes32>,
}
```

## Usage

In order to get started indexing Predicates, users will need to:

1. Create a new Predicate project using [`forc`]
2. Build this predicate project in order to get the JSON ABI.
3. Add this predicate template hash to your indexer manifest.
4. Include the appropriate witness data in transactions you wish to flag to your indexer

```rust,ignore
extern crate alloc;
use fuel_indexer_utils::prelude::*;
#[indexer(manifest = "indexer.manifest.yaml")]
mod indexer_mod {
fn handle_spent_predicates(predicates: Vec<IndexerPredicate>) {
unimplemented!()
}
}
```
3 changes: 3 additions & 0 deletions docs/src/indexing-fuel-types/receipts.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ pub struct Burn {
```

```rust, ignore
extern crate alloc;
use fuel_indexer_utils::prelude::*;
mod indexer_mod {
fn handle_burn_receipt(block_data: BlockData) {
let height = block_data.header.height;
Expand Down
42 changes: 36 additions & 6 deletions docs/src/project-components/manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ Below is a sample indexer manifest file
namespace: fuellabs
identifier: order_book_v1
fuel_client: beta-4.fuel.network:80
abi: path/to/my/contract-abi.json
contract_id: "fuels0x39150017c9e38e5e280432d546fae345d6ce6d8fe4710162c2e3a95a6faff051"
contract:
abi: path/to/my/contract-abi.json
subscriptions:
- fuels0x39150017c9e38e5e280432d546fae345d6ce6d8fe4710162c2e3a95a6faff051
graphql_schema: path/to/my/schema.graphql
start_block: 1564
end_block: 310000
module:
wasm: path/to/my/wasm_module.wasm
predicates:
abis: ~
templates: ~
```
## `namespace`
Expand All @@ -35,19 +40,26 @@ _Optional._

The `fuel_client` denotes the address (host, port combination) of the running Fuel client that you would like your indexer to index events from. In order to use this per-indexer `fuel_client` option, the indexer service at which your indexer is deployed will have to run with the `--indexer_net_config` option.

## `abi`
## `contract`

_Optional._

Indexer contract settings.

### `abi`

_Optional._

The `abi` option is used to provide a link to the Sway JSON application binary interface (ABI) that is generated when you build your Sway project. This generated ABI contains all types, type IDs, logged types, and message types used in your Sway contract.

## `contract_id`
### `subscriptions`

_Optional._

The `contract_id` specifies the particular contract to which you would like an indexer to subscribe. Setting this field to an empty string will index events from any contract that is currently executing on the network. This field accepts either a single string, or a list of strings. The indexer will index events from all IDs if a list is passed.
The `contract_subscriptions` specifies the particular contract to which you would like an indexer to subscribe. Setting this field to an empty string will index events from any contract that is currently executing on the network. This field accepts either a single string, or a list of strings. The indexer will index events from all IDs if a list is passed.

> Important: Contract IDs are unique to the content of a contract. If you are subscribing to a certain contract and then the contract itself is changed or updated, you will need to change the `contract_id` field of the manifest to the new ID.
> Important: Contract IDs are unique to the content of a contract. If you are subscribing to a certain contract and then the contract itself is changed or updated, you will need to change the `subscriptions` field of the manifest with the new contract ID.
>
> Note: This parameter supports both Bech32 contract IDs and non-Bech32 contract IDs

## `graphql_schema`
Expand Down Expand Up @@ -83,3 +95,21 @@ The `module` field contains a file path that points to code that will be run as
_Optional._

The `resumable` field contains a boolean value and specifies whether the indexer should synchronise with the latest block if it has fallen out of sync.

## `predicates`

_Optional._

Indexer predication configuration.

### `abis`

_Optional._

List of file paths to ABIs for predicates used by this indexer.

### `templates`

_Optional._

A list of template hashes and template names used to identify each predicate used by this indexer.
20 changes: 14 additions & 6 deletions examples/fuel-explorer/fuel-explorer/fuel_explorer.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ namespace: fuellabs
# The identifier field is used to identify the given index.
identifier: explorer

# The abi option is used to provide a link to the Sway JSON ABI that is generated when you
# build your project.
abi: ~
# Indexer contract configuration.
contract:

# File paths to the contract JSON ABIs that are generated when you build your Sway contracts.
abi: ~

# Specifies which particular contracts you would like your indexer to subscribe to.
subscriptions: ~

# The particular start block after which you'd like your indexer to start indexing events.
start_block: ~
Expand All @@ -21,9 +26,6 @@ end_block: ~
# with the `--indexer_net_config` option.
fuel_client: ~

# The contract_id specifies which particular contract you would like your index to subscribe to.
contract_id: ~

# The graphql_schema field contains the file path that points to the GraphQL schema for the
# given index.
graphql_schema: examples/fuel-explorer/fuel-explorer/schema/fuel_explorer.schema.graphql
Expand All @@ -37,3 +39,9 @@ module:
# The resumable field contains a boolean that specifies whether or not the indexer should, synchronise
# with the latest block if it has fallen out of sync.
resumable: true

# Indexer predicate configuration.
predicates:

# Template commitments (hashes) of the bytecode of predicates used by this indexer.
templates: ~
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ namespace: fuellabs
# The identifier field is used to identify the given index.
identifier: greetings

# The abi option is used to provide a link to the Sway JSON ABI that is generated when you
# build your project.
abi: examples/greetings/contracts/greeting/out/debug/greeting-abi.json
# Indexer contract configuration.
contract:

# File paths to the contract JSON ABIs that are generated when you build your Sway contracts.
abi: examples/greetings/contracts/greeting/out/debug/greeting-abi.json

# Specifies which particular contracts you would like your indexer to subscribe to.
subscriptions:
- fuel1q6sj2srt0u40jdqg2lvvnspyuhse9rs2s2fv9nmv0hqjcrdc7sqsfpwv9x

# The particular start block after which you'd like your indexer to start indexing events.
start_block: ~
Expand All @@ -21,9 +27,6 @@ end_block: ~
# with the `--indexer_net_config` option.
fuel_client: ~

# The contract_id specifies which particular contract you would like your index to subscribe to.
contract_id: fuel1q6sj2srt0u40jdqg2lvvnspyuhse9rs2s2fv9nmv0hqjcrdc7sqsfpwv9x

# The graphql_schema field contains the file path that points to the GraphQL schema for the
# given index.
graphql_schema: examples/greetings/greetings-indexer/schema/greetings_indexer.schema.graphql
Expand All @@ -36,4 +39,10 @@ module:

# The resumable field contains a boolean that specifies whether or not the indexer should, synchronise
# with the latest block if it has fallen out of sync.
resumable: true
resumable: true

# Indexer predicate configuration.
predicates:

# Template commitments (hashes) of the bytecode of predicates used by this indexer.
templates: ~
22 changes: 15 additions & 7 deletions examples/hello-world/hello-world/hello_world.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ namespace: fuellabs
# The identifier field is used to identify the given index.
identifier: hello_world

# The abi option is used to provide a link to the Sway JSON ABI that is generated when you
# build your project.
abi: ~
# Indexer contract configuration.
contract:

# File paths to the contract JSON ABIs that are generated when you build your Sway contracts.
abi: ~

# Specifies which particular contracts you would like your indexer to subscribe to.
subscriptions: ~

# The particular start block after which you'd like your indexer to start indexing events.
start_block: ~
Expand All @@ -21,9 +26,6 @@ end_block: ~
# with the `--indexer_net_config` option.
fuel_client: ~

# The contract_id specifies which particular contract you would like your index to subscribe to.
contract_id: ~

# The graphql_schema field contains the file path that points to the GraphQL schema for the
# given index.
graphql_schema: examples/hello-world/hello-world/schema/hello_world.schema.graphql
Expand All @@ -36,4 +38,10 @@ module:

# The resumable field contains a boolean that specifies whether or not the indexer should, synchronise
# with the latest block if it has fallen out of sync.
resumable: true
resumable: true

# Indexer predicate configuration.
predicates:

# Template commitments (hashes) of the bytecode of predicates used by this indexer.
templates: ~
2 changes: 1 addition & 1 deletion packages/fuel-indexer-api-server/src/uses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ pub(crate) async fn verify_signature(
}
_ => {
error!("Unsupported authentication strategy.");
unimplemented!();
unimplemented!("Unsupported authentication strategy.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use fuel_indexer_lib::{config::IndexerConfig, manifest::Manifest};
fn setup_fuel_explorer_manifest() -> Manifest {
let manifest_str = r#"
namespace: indexer_benchmarks
abi: ~
contract_abi: ~
identifier: fuel_explorer
fuel_client: ~
graphql_schema: ../../examples/fuel-explorer/fuel-explorer/schema/fuel_explorer.schema.graphql
Expand All @@ -16,6 +16,8 @@ contract_id: ~
start_block: ~
end_block: ~
resumable: ~
predicates:
templates: ~
"#;

Manifest::try_from(manifest_str).unwrap()
Expand Down
1 change: 0 additions & 1 deletion packages/fuel-indexer-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ fuel-indexer-types = { workspace = true }
http = { version = "0.2", default-features = false }
lazy_static = { version = "1.4" }
serde = { workspace = true }
serde_json = { workspace = true }
serde_yaml = "0.8"
sha2 = "0.9"
strum = { version = "0.24", default-features = false, features = ["derive"] }
Expand Down
Loading

0 comments on commit 220eb96

Please sign in to comment.