Skip to content

Commit

Permalink
refactor: Clean up the examples and dev-dependencies (#83)
Browse files Browse the repository at this point in the history
* refactor: Clean up the examples and dev-dependencies

* Mark code-snippets in the docs to be ignored (they miss the dependency)
  • Loading branch information
khorolets authored Jun 6, 2023
1 parent 260e5f4 commit 2710f3b
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ For more information [refer to the docs](https://docs.rs/near-lake-framework)

### More examples

We're keeping a set of examples in the [examples](./examples/) folder. The examples there are always up-to-date with the latest version of the NEAR Lake Framework.

And here are some more examples. Despite the fact that they are not up-to-date with the latest version of the NEAR Lake Framework, they still can be used as a reference. Though, we try to keep them updated as well.

- [`near-examples/near-lake-raw-printer`](https://github.com/near-examples/near-lake-raw-printer) simple example of a data printer built on top of NEAR Lake Framework
- [`near-examples/near-lake-accounts-watcher`](https://github.com/near-examples/near-lake-accounts-watcher) another simple example of the indexer built on top of NEAR Lake Framework for a tutorial purpose
- [`near-examples/indexer-tx-watcher-example-lake`](https://github.com/near-examples/indexer-tx-watcher-example-lake) an example of the indexer built on top of NEAR Lake Framework that watches for transactions related to specified account(s)
Expand Down
52 changes: 52 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# NEAR Lake Framework Examples

This directory contains several example scripts showcasing the usage of the NEAR Lake Framework. Each example demonstrates different aspects and features of the framework. Below is a brief description of each example:

## simple.rs

A simple example of how to use the Lake Framework. This indexer will listen to the NEAR blockchain and print the block height of each block.

```bash
$ cd lake-framework
$ cargo run --example simple
```

## actions.rs

This example shows how to filter actions in a block. It is a more real-life example than the simple example. It is going to follow the NEAR Social contract and print all function calls to it.

```bash
$ cd lake-framework
$ cargo run --example actions
```

## nft_indexer.rs

This is a more complex real-life example of how to use the NEAR Lake Framework.

It is going to follow the network and watch for the Events according to the [Events Format][1]. It will monitor for nft_mint events from the known marketplaces, such as Mintbase and Paras, and index them to print in the terminal.

[1]: https://nomicon.io/Standards/EventsFormat

```bash
$ cd lake-framework
$ cargo run --example nft_indexer
```

## with_context.rs

This example show how to use a context with Lake Framework. It is going to follow the NEAR Social contract and the block height along with a number of calls to the contract.

```bash
$ cd lake-framework
$ cargo run --example with_context
```

## with_context_parent_tx_cache.rs

This example show how to use a context `ParentTransactionCache` with the Lake Framework. It is going to follow the NEAR Social contract and cache the parent Transaction for the Receipts. Thus we would be able to capture the Transaction where the change to the contract state has started.

```bash
$ cd lake-parent-transaction-cache
$ cargo run --example with_context_parent_tx_cache
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 15 additions & 2 deletions lake-framework/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,18 @@ once_cell = "1.8.0"
# used in the doc examples
diesel = { version = "2", features = ["postgres_backend", "postgres"] }

# used by with_context_parent_tx_cache example
near-lake-parent-transaction-cache = { path = "../lake-parent-transaction-cache", version = "0.8.0-beta.2" }
[[example]]
name = "simple"
path = "../examples/simple.rs"

[[example]]
name = "actions"
path = "../examples/actions.rs"

[[example]]
name = "nft_indexer"
path = "../examples/nft_indexer.rs"

[[example]]
name = "with_context"
path = "../examples/with_context.rs"
2 changes: 1 addition & 1 deletion lake-framework/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async fn handle_block(

It is an old problem that the NEAR Protocol doesn't provide the parent transaction hash in the receipt. This is a problem for the indexer that needs to know the parent transaction hash to build the transaction tree. We've got you covered with the [`lake-parent-transaction-cache`](../lake-parent-transaction-cache/) crate that provides a cache for the parent transaction hashes.

```no_run
```ignore
use near_lake_framework::near_lake_primitives;
use near_lake_primitives::CryptoHash;
use near_lake_parent_transaction_cache::{ParentTransactionCache, ParentTransactionCacheBuilder};
Expand Down
2 changes: 1 addition & 1 deletion lake-framework/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ pub enum LakeError {
/// #### Advanced Context example
/// In this example we will extend a previous one with the `ParentTransactionCache` context Lake Framework team has created and shared with everybody.
///
/// ```no_run
/// ```ignore
/// use near_lake_framework::LakeContext; // This is a derive macro
/// use near_lake_parent_transaction_cache::{ParentTransactionCache, ParentTransactionCacheBuilder}; // This is a ready-to-use Context from the community that impls LakeContext trait
/// use near_lake_framework::LakeBuilder;
Expand Down
4 changes: 4 additions & 0 deletions lake-parent-transaction-cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ near-lake-framework = { path = "../lake-framework", version = "0.8.0-beta.2" }

[dev-dependencies]
anyhow = "1.0.44"

[[example]]
name = "with_context_parent_tx_cache"
path = "../examples/with_context_parent_tx_cache.rs"

0 comments on commit 2710f3b

Please sign in to comment.