Skip to content

Commit

Permalink
Add indexer guide (#617)
Browse files Browse the repository at this point in the history
* add indexer concept

* indexer project setup

* constructing main.rs

* configure network / run indexer

* fix indexer link

* minor edits

* Update docs/tools/near-indexer.md

Co-authored-by: Bohdan Khorolets <b@khorolets.com>

* Update docs/tools/near-indexer.md

Co-authored-by: Bohdan Khorolets <b@khorolets.com>

* Update docs/tools/near-indexer.md

Co-authored-by: Bohdan Khorolets <b@khorolets.com>

* Update docs/tools/near-indexer.md

Co-authored-by: Bohdan Khorolets <b@khorolets.com>

* Update docs/tools/near-indexer.md

Co-authored-by: Bohdan Khorolets <b@khorolets.com>

* Update docs/tools/near-indexer.md

Co-authored-by: Bohdan Khorolets <b@khorolets.com>

* Update near-indexer tutorial

* Add the link to final code of example-indexer

* Update example indexer code according to recent updated in nearcore

* Apply suggestions from code review

Co-authored-by: Vlad Frolov <frolvlad@gmail.com>

* Update docs/tools/near-indexer.md

Co-authored-by: Vlad Frolov <frolvlad@gmail.com>

* update rust tags

* final edits

Co-authored-by: Bohdan Khorolets <b@khorolets.com>
Co-authored-by: Bohdan Khorolets <bogdan@khorolets.com>
Co-authored-by: Vlad Frolov <frolvlad@gmail.com>
  • Loading branch information
4 people authored Mar 12, 2021
1 parent 2cf5cf8 commit 9aa5c13
Show file tree
Hide file tree
Showing 5 changed files with 559 additions and 9 deletions.
12 changes: 6 additions & 6 deletions docs/concepts/data-collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,15 @@ map.getSome(key)
- To add data:

```rs
```rust
pub fn add_lookup_map(&mut self, key: String, value: String) {
self.lookup_map.insert(&key, &value);
}
```

- To get data:

```rs
```rust
pub fn get_lookup_map(&self, key: String) -> String {
match self.lookup_map.get(&key) {
Some(value) => {
Expand Down Expand Up @@ -326,15 +326,15 @@ pub fn get_lookup_map(&self, key: String) -> String {
- To add data:

```rs
```rust
pub fn add_unordered_map(&mut self, key: String, value: String) {
self.unordered_map.insert(&key, &value);
}
```

- To get data:

```rs
```rust
pub fn get_unordered_map(&self, key: String) -> String {
match self.unordered_map.get(&key) {
Some(value) => {
Expand Down Expand Up @@ -365,15 +365,15 @@ pub fn get_unordered_map(&self, key: String) -> String {
- To add data:

```rs
```rust
pub fn add_tree_map(&mut self, key: String, value: String) {
self.tree_map.insert(&key, &value);
}
```

- To get data:

```rs
```rust
pub fn get_tree_map(&self, key: String) -> String {
match self.tree_map.get(&key) {
Some(value) => {
Expand Down
18 changes: 18 additions & 0 deletions docs/concepts/indexer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
id: indexer
title: NEAR Indexer
sidebar_label: Indexer
---

> NEAR Indexer is a library included with [nearcore](https://github.com/near/nearcore) that allows you to run a node on the network which listens for targeted information on the blockchain. The [NEAR Indexer Framework](https://github.com/near/nearcore/tree/master/chain/indexer) provides the logic of polling a node for blocks produced in a network then aggregating and streaming these blocks to a listener.
To better understand this, blockchain data is optimized for serialized writes, one block at a time, as the chain is being created. Querying the blockchain for data about a specific block or account is a fairly straightforward or "narrow" query. However, querying data across many blocks can be cumbersome because we have to aggregate results from multiple single-block queries. We can consider these "wide" queries.

- An indexer listens to the stream of data as it's being written on chain and can then be immediately filtered and processed to detect interesting events or patterns.
- This stream of data can then be written to a permanent database for later data analysis using a convenient query language like SQL.

- One example that highlights the need for a "wide query" is when you use a seed phrase to recover one or more accounts. Since a seed phrase essentially represents a signing key pair, the recovery is for **all** accounts that share the associated public key. Therefore, when a seed phrase is used to recover an account via [NEAR Wallet](https://wallet.near.org/), the query requires that **all accounts** with a matching public key are found and recovered.

- The easiest way to achieve a "wide query" is to utilize a database that has been filled by an indexing service. For this purpose we’ve built the [NEAR Indexer for wallet](https://github.com/near/near-indexer-for-wallet) which listens to all actions on chain that might create or delete [access keys](/docs/concepts/account#access-keys) and stores them into a relational database for easier querying of accounts.

[ **[Click Here](/docs/tools/near-indexer)** ] For a walkthrough on creating an indexer.
4 changes: 2 additions & 2 deletions docs/faq/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Each method call on a contract is recorded as a transaction. This transaction ca

**Rust**

```rs
```rust
env::signer_account_pk()
```

Expand Down Expand Up @@ -52,7 +52,7 @@ See here for an [example in our Guestbook](https://github.com/near-examples/gues
See here for an [example in our Rust library test fixtures](https://github.com/near/near-sdk-rs/blob/master/examples/cross-contract-high-level/src/lib.rs#L125)


```rs
```rust
ext_status_message::set_status(message, &account_id, 0, SINGLE_CALL_GAS);
```

Expand Down
Loading

0 comments on commit 9aa5c13

Please sign in to comment.