From 2710f3bd882e188f6dd2c4a8cc3182ea2e217c75 Mon Sep 17 00:00:00 2001 From: Bohdan Khorolets Date: Tue, 6 Jun 2023 22:18:03 +0300 Subject: [PATCH] refactor: Clean up the examples and dev-dependencies (#83) * refactor: Clean up the examples and dev-dependencies * Mark code-snippets in the docs to be ignored (they miss the dependency) --- README.md | 4 ++ examples/README.md | 52 +++++++++++++++++++ .../examples => examples}/actions.rs | 0 .../examples => examples}/nft_indexer.rs | 0 .../examples => examples}/simple.rs | 0 .../examples => examples}/with_context.rs | 0 .../with_context_parent_tx_cache.rs | 0 lake-framework/Cargo.toml | 17 +++++- lake-framework/README.md | 2 +- lake-framework/src/types.rs | 2 +- lake-parent-transaction-cache/Cargo.toml | 4 ++ 11 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 examples/README.md rename {lake-framework/examples => examples}/actions.rs (100%) rename {lake-framework/examples => examples}/nft_indexer.rs (100%) rename {lake-framework/examples => examples}/simple.rs (100%) rename {lake-framework/examples => examples}/with_context.rs (100%) rename {lake-framework/examples => examples}/with_context_parent_tx_cache.rs (100%) diff --git a/README.md b/README.md index 6ef9dde..b3cba24 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..f07d5db --- /dev/null +++ b/examples/README.md @@ -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 +``` \ No newline at end of file diff --git a/lake-framework/examples/actions.rs b/examples/actions.rs similarity index 100% rename from lake-framework/examples/actions.rs rename to examples/actions.rs diff --git a/lake-framework/examples/nft_indexer.rs b/examples/nft_indexer.rs similarity index 100% rename from lake-framework/examples/nft_indexer.rs rename to examples/nft_indexer.rs diff --git a/lake-framework/examples/simple.rs b/examples/simple.rs similarity index 100% rename from lake-framework/examples/simple.rs rename to examples/simple.rs diff --git a/lake-framework/examples/with_context.rs b/examples/with_context.rs similarity index 100% rename from lake-framework/examples/with_context.rs rename to examples/with_context.rs diff --git a/lake-framework/examples/with_context_parent_tx_cache.rs b/examples/with_context_parent_tx_cache.rs similarity index 100% rename from lake-framework/examples/with_context_parent_tx_cache.rs rename to examples/with_context_parent_tx_cache.rs diff --git a/lake-framework/Cargo.toml b/lake-framework/Cargo.toml index 919ae35..cc70fdd 100644 --- a/lake-framework/Cargo.toml +++ b/lake-framework/Cargo.toml @@ -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" diff --git a/lake-framework/README.md b/lake-framework/README.md index 5516e5f..3ae153e 100644 --- a/lake-framework/README.md +++ b/lake-framework/README.md @@ -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}; diff --git a/lake-framework/src/types.rs b/lake-framework/src/types.rs index 9932906..a97feb0 100644 --- a/lake-framework/src/types.rs +++ b/lake-framework/src/types.rs @@ -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; diff --git a/lake-parent-transaction-cache/Cargo.toml b/lake-parent-transaction-cache/Cargo.toml index e9d8f59..b290eb9 100644 --- a/lake-parent-transaction-cache/Cargo.toml +++ b/lake-parent-transaction-cache/Cargo.toml @@ -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"