You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/build/indexer/indexer-sdk/documentation/create-processor.mdx
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ This guide will walk you through setting up the basic template for a new process
6
6
7
7
## Pre-requisites
8
8
9
-
You've already set up your environment and have the Indexer SDK `aptos-indexer-sdk`and `aptos-indexer-sdk-server-framework`installed.
9
+
You've already set up your environment and have the Indexer SDK `aptos-indexer-sdk` installed.
10
10
If you haven't, follow the [Indexer SDK installation guide](/build/indexer/indexer-sdk/documentation/setup).
11
11
12
12
## Overview
@@ -25,9 +25,9 @@ The next section goes through each of these pieces more explicitly and provides
25
25
The `IndexerProcessorConfig` defines the base configuration for all processors that you'll be running.
26
26
It should include configuration for things that are shared across multiple processors, like the database configuration and [Transaction Stream](/build/indexer/txn-stream) configuration.
27
27
28
-
[`ServerArgs`](https://github.com/aptos-labs/aptos-indexer-processor-sdk/blob/main/aptos-indexer-processors-sdk/sdk-server-framework/src/lib.rs#L26) parses a `config.yaml` file and bootstraps a server with all the common pieces to run a processor.
28
+
`ServerArgs` parses a `config.yaml` file and bootstraps a server with all the common pieces to run a processor.
29
29
30
-
To setup the configuration for your processor and make it work with `ServerArgs`, you'll need to define a `IndexerProcessorConfig` that implements the [`RunnableConfig`](https://github.com/aptos-labs/aptos-indexer-processor-sdk/blob/main/aptos-indexer-processors-sdk/sdk-server-framework/src/lib.rs#L102) trait.
30
+
To setup the configuration for your processor and make it work with `ServerArgs`, you'll need to define a `IndexerProcessorConfig` that implements the `RunnableConfig` trait.
31
31
It also triggers a run method, which can be invoked in `main.rs`.
32
32
33
33
For basic cases, you can copy the [`IndexerProcessorConfig` from the `aptos-indexer-processor-example`](https://github.com/aptos-labs/aptos-indexer-processor-example/blob/main/aptos-indexer-processor-example/src/config/indexer_processor_config.rs) repository and modify it to fit your needs.
Copy file name to clipboardExpand all lines: src/content/docs/build/indexer/indexer-sdk/documentation/setup.mdx
+6-11Lines changed: 6 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,21 +7,16 @@ The quickstart guide provides a template processor and includes all of this setu
7
7
8
8
If you're migrating an existing processor to the Indexer SDK, follow the steps below.
9
9
10
-
The Indexer SDK provides several Rust crates:
11
-
12
-
1.[`aptos-indexer-processor-sdk`](https://github.com/aptos-labs/aptos-indexer-processor-sdk/tree/main/aptos-indexer-processors-sdk/sdk) - The core SDK that provides the building blocks for writing a processor.
13
-
2.[`aptos-indexer-processor-sdk-server-framework`](https://github.com/aptos-labs/aptos-indexer-processor-sdk/tree/main/aptos-indexer-processors-sdk/sdk-server-framework) - A server framework for creating a server that runs the processor and includes health checks and metrics logging probes.
14
-
If you're setting up a server to host your processor, you will need to include this crate.
15
-
3.[`aptos-indexer-testing-framework`](https://github.com/aptos-labs/aptos-indexer-processor-sdk/tree/main/aptos-indexer-processors-sdk/testing-framework) - An e2e testing framework for testing processors.
16
-
If you want to write tests for your processor, you will need to include this crate.
17
-
18
-
Depending on your use case, you can import the crates to your `Cargo.toml`.
10
+
Add `aptos-indexer-processor-sdk` to your `Cargo.toml`.
@@ -8,17 +8,17 @@ This guide will walk you through setting up and running a Rust processor to inde
8
8
We provide a template processor that you can customize to index events from your custom contracts.
9
9
By the end of the guide, you should have a basic understanding of how a processor works and be able to customize the processor for your indexing needs.
10
10
11
-
## Getting started
11
+
## Get started
12
12
13
13
To get started, clone
14
-
the [aptos-indexer-processors-example](https://github.com/aptos-labs/aptos-indexer-processor-example/tree/main) repo.
14
+
the [aptos-indexer-processor-sdk](https://github.com/aptos-labs/aptos-indexer-processor-sdk) repo.
2. `process` is a helper function that wraps around a regular processor.
209
+
In the background, this powerful function handles connecting to Transaction Stream, processing transactions given a transform function that you define, applying database migrations, and tracking the processor's status.
210
+
211
+
```rust
212
+
process(
213
+
"events_processor".to_string(), // name of the processor that will be used to track the processor status
214
+
MIGRATIONS, // migrations to be applied to the database
215
+
async |transactions, conn_pool| {
216
+
// transform from transaction to events and insert the events into the database
217
+
},
218
+
).await?;
219
+
```
220
+
221
+
## Run the processor
201
222
202
223
With the `config.yaml` you created earlier, you’re ready to run the events processor:
203
224
204
225
```shellscript
205
-
cd aptos-indexer-processor-example
226
+
cd examples/postgres-basic-events-example
206
227
cargo run --release -- -c config.yaml
207
228
```
208
229
@@ -214,30 +235,86 @@ You should see the processor start to index Aptos blockchain events!
214
235
{"timestamp":"2024-08-15T01:06:35.257801Z","level":"INFO","message":"Finished processing events from versions [0, 4999]","filename":"src/processors/events/events_processor.rs","line_number":90,"threadName":"tokio-runtime-worker","threadId":"ThreadId(17)"}
215
236
```
216
237
217
-
# Customizing the processor
238
+
## Customize the processor
218
239
219
240
In most cases, you want to index events from your own contracts. The example processor offers a good starting point to
220
241
creating your own custom processor.
221
242
222
-
To customize the processor to index events from your custom contract, you can make change in these places:
243
+
To customize the processor to index events from your custom contract, you can make these changes:
223
244
224
-
- `EventsExtractor`
225
-
- In `process()`, you can filter by specific event types and extract specific event data from your custom contract
226
-
- `EventsStorer`
245
+
1. Change the database schema to a format that better matches your dapp or API.
246
+
a. Create a new migration with diesel:
227
247
228
-
- If you need to change the database model, you can generate a new database migration by going to `src/db/postgres`
229
-
and running
230
-
231
-
```shellscript
248
+
```shellscript
232
249
diesel migration generate {migration_name}
233
-
```
250
+
```
234
251
235
-
- Add your migration changes to `up.sql` and `down.sql`, then run
252
+
b. Add your migration changes to `up.sql` and `down.sql`, then apply the migration:
236
253
237
-
```shellscript
254
+
```shellscript
238
255
diesel migration run --database-url={YOUR_DATABASE_URL}
239
-
```
256
+
```
257
+
258
+
c. The `schema.rs` file will be updated automatically. You can then create a diesel query that uses the new schema.
259
+
2\. Update the transform logic in `process()`. You can filter by specific event types and extract specific event data from your custom contract
240
260
241
-
to update `schema.rs`.
261
+
## Migrate from legacy processors
262
+
263
+
If you're migrating from the legacy processors, you can still start with the same steps above to create a new processor with the Indexer SDK.
264
+
265
+
You'll also need to follow these:
266
+
267
+
1. Copy your migration files to `src/db/`.
268
+
2. With the legacy processors, the processing logic is defined inside the `process_transactions` method.
269
+
270
+
```rust
271
+
// Example with the legacy processors
272
+
#[async_trait]
273
+
impl ProcessorTrait for EventsProcessor {
274
+
async fn process_transactions(
275
+
...
276
+
) -> anyhow::Result<ProcessingResult> {
277
+
// Extract events from transactions
278
+
let events: Vec<EventModel> = process_events(transactions);
279
+
280
+
// Store the events in the database
281
+
let tx_result = insert_to_db(
282
+
self.get_pool(),
283
+
self.name(),
284
+
start_version,
285
+
end_version,
286
+
&events,
287
+
&self.per_table_chunk_sizes,
288
+
)
289
+
.await;
290
+
291
+
return tx_result;
292
+
}
293
+
}
294
+
```
295
+
296
+
Migrate to the SDK by copying over the logic in `process_transactions` method to the SDK `process` transform function.
297
+
298
+
```rust
299
+
// Example with SDK processor
300
+
process(
301
+
"events_processor".to_string(),
302
+
MIGRATIONS,
303
+
async |transactions, conn_pool| {
304
+
// Extract events from transactions
305
+
let events: Vec<EventModel> = process_events(transactions);
Copy file name to clipboardExpand all lines: src/content/docs/build/sdks/ts-sdk/building-transactions/script-composer.mdx
+1-3Lines changed: 1 addition & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,7 @@
1
1
---
2
-
title: "Dynamically invoke chains of Move calls with ScriptComposer"
2
+
title: "Invoke chains of Move calls with Dynamic Script Composer"
3
3
---
4
4
5
-
This is so far an **experimental** feature that is only released to [this particular](https://www.npmjs.com/package/@aptos-labs/ts-sdk/v/1.33.0-sc.0) version of typescript SDK and is subject to change.
6
-
7
5
In the naive api, you only get to specify one entry function to invoke for one transaction. An advanced builder might want to be able to invoke multiple **public** Move functions inside one transaction. This is now enabled by the new `scriptComposer` api provided in the transaction builder.
0 commit comments