Skip to content

Commit

Permalink
Fix grammatical errors and add docs hyperlinks (#172)
Browse files Browse the repository at this point in the history
* Fix grammatical errors and add docs hyperlinks

* use docs.rs links

* Update steps/18/README.md

---------

Co-authored-by: Shawn Tabrizi <[email protected]>
  • Loading branch information
mittal-parth and shawntabrizi authored Aug 4, 2024
1 parent 54a30f9 commit 4a9f17a
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions steps/18/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Now that you have learned everything you need to know about `StorageValue`s, it

## Syntax

Declaring a new `StorageMap` is very similar to a `StorageValue`:
Declaring a new [`StorageMap`](https://docs.rs/frame-support/37.0.0/frame_support/storage/types/struct.StorageMap.html) is very similar to a `StorageValue`:

```rust
#[pallet::storage]
Expand All @@ -23,8 +23,8 @@ In this case `[u8; 32]` represents some unique identifier for each Kitty we will

The key difference between a `StorageValue` and a `StorageMap` is:

- A `StorageValue` stores a single value into a single key the Merkle Trie.
- A `StorageMap` stores multiple values under different storage keys, all into different places in the merkle trie.
- A `StorageValue` stores a single value into a single key in the Merkle Trie.
- A `StorageMap` stores multiple values under different storage keys, all into different places in the Merkle Trie.

Let's clarify further.

Expand All @@ -44,11 +44,11 @@ and
pub(super) type MyMap<T: Config> = StorageMap<Key = u8, Value = ()>;
```

They both can store the same data, but the `StorageValue` puts all of the data into a single object and stores that all into a single key in the merkle trie.
They both can store the same data, but the `StorageValue` puts all of the data into a single object and stores that all into a single key in the Merkle Trie.

This means if we want to read just a single key / value pair, we must read ALL data in the whole map, and parse out just the single value we want.

In a `StorageMap`, each value is stored in its own spot in the merkle trie, so you are able to read just one key / value on its own. This can be way more efficient for reading just a single item.
In a `StorageMap`, each value is stored in its own spot in the Merkle Trie, so you are able to read just one key / value on its own. This can be way more efficient for reading just a single item.

However, trying to read multiple items from a `StorageMap` is extremely expensive.

Expand All @@ -62,7 +62,7 @@ The most common example would be trying to store the token balance of all users

In our pallet, we use the `StorageMap` to store unique information about each `Kitty` in our pallet.

These use cases makes sense because all of the logic in our pallet only touch one key at a time on average.
These use cases make sense because all the logic in our pallet typically touches only one key at a time.

- when you mint a kitty, we create one key / value.
- when you transfer a kitty, we mutate one key / value.
Expand Down
2 changes: 1 addition & 1 deletion steps/20/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Check out the [`StorageMap` documentation](https://docs.rs/frame-support/37.0.0/

### Reading Storage

To read the current value of a key in a `StorageMap`, you can simply call the `get(key)` API:
To read the current value of a key in a `StorageMap`, you can simply call the [`get(key)`](https://docs.rs/frame-support/37.0.0/frame_support/storage/types/struct.StorageMap.html#method.get) API:

```rust
let my_key: [u8; 32] = [0u8; 32];
Expand Down
2 changes: 1 addition & 1 deletion steps/27/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ What you need to know about SCALE is that it defines how every object in the `po

### Max Encoded Length

Now that we have a tools to define the way objects should be encoded, we are able to create a trait which tracks the maximum encoded length of an object: `MaxEncodedLen.
Now that we have the tools to define the way objects should be encoded, we are able to create a trait which tracks the maximum encoded length of an object: `MaxEncodedLen`.

We then use that information to predict in the worst case scenario how much data will be used when we store it.

Expand Down
8 changes: 4 additions & 4 deletions steps/40/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Every blockchain has a cryptocurrency associated with it. Bitcoin has BTC. Ether

For Polkadot, that native token is the DOT token.

Polkadot is built using FRAME and Pallets just like you have been building so far. Included in the `polkadot-sdk` is `pallet_balances`.
Polkadot is built using FRAME and Pallets just like you have been building so far. Included in the `polkadot-sdk` is [`pallet_balances`](https://docs.rs/pallet-balances/38.0.0/pallet_balances/index.html).

This is a Pallet designed specifically to manage the native balance for users.

Expand Down Expand Up @@ -85,10 +85,10 @@ pub trait Config: frame_system::Config {
}
```

You can see we introduce a new associated type called `NativeBalance`. We then require that this type must implment two traits:
You can see we introduce a new associated type called `NativeBalance`. We then require that this type must implement two traits:

- [`fungible::Inspect`](https://paritytech.github.io/polkadot-sdk/master/frame_support/traits/tokens/fungible/trait.Inspect.html): A trait allowing us to read data about a fungible token.
- [`fungible::Mutate`](https://paritytech.github.io/polkadot-sdk/master/frame_support/traits/tokens/fungible/trait.Mutate.html): A trait allowing us to write data about a fungible token.
- [`fungible::Inspect`](https://docs.rs/frame-support/37.0.0/frame_support/traits/tokens/fungible/trait.Inspect.html): A trait allowing us to read data about a fungible token.
- [`fungible::Mutate`](https://docs.rs/frame-support/37.0.0/frame_support/traits/tokens/fungible/trait.Mutate.html): A trait allowing us to write data about a fungible token.

So with this, we are able to access our native balance using APIs like:

Expand Down
4 changes: 2 additions & 2 deletions steps/41/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ pub trait Config: frame_system::Config {

You can see we introduce a new associated type called `NativeBalance`. We then require that this type must implment two traits:

- [`fungible::Inspect`](https://paritytech.github.io/polkadot-sdk/master/frame_support/traits/tokens/fungible/trait.Inspect.html): A trait allowing us to read data about a fungible token.
- [`fungible::Mutate`](https://paritytech.github.io/polkadot-sdk/master/frame_support/traits/tokens/fungible/trait.Mutate.html): A trait allowing us to write data about a fungible token.
- [`fungible::Inspect`](https://docs.rs/frame-support/37.0.0/frame_support/traits/tokens/fungible/trait.Inspect.html): A trait allowing us to read data about a fungible token.
- [`fungible::Mutate`](https://docs.rs/frame-support/37.0.0/frame_support/traits/tokens/fungible/trait.Mutate.html): A trait allowing us to write data about a fungible token.

So with this, we are able to access our native balance using APIs like:

Expand Down
2 changes: 1 addition & 1 deletion steps/42/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn add_one(input: BalanceOf<T>) -> BalanceOf<T> {

Even if we don't include `u128`, we cannot write the line above. This is because that line assumes that `input` must be some specific number type, and in that code, it is simply generic.

However, `BalanceOf<T>` [does have traits](https://paritytech.github.io/polkadot-sdk/master/frame_support/traits/tokens/trait.Balance.html) that we can use to interact with it. The key one being [`AtLeast32BitUnsigned`](https://paritytech.github.io/polkadot-sdk/master/polkadot_sdk_frame/arithmetic/trait.AtLeast32BitUnsigned.html).
However, `BalanceOf<T>` [does have traits](https://docs.rs/frame-support/37.0.0/frame_support/traits/tokens/trait.Balance.html) that we can use to interact with it. The key one being [`AtLeast32BitUnsigned`](https://docs.rs/polkadot-sdk-frame/0.6.0/polkadot_sdk_frame/arithmetic/trait.AtLeast32BitUnsigned.html).

This means our `BalanceOf<T>` must be an unsigned integer, and must be at least `u32`. So it could be `u32`, `u64`, `u128`, or even bigger if you import other crates with those larger unsigned types.

Expand Down
2 changes: 1 addition & 1 deletion steps/43/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn add_one(input: BalanceOf<T>) -> BalanceOf<T> {

Even if we don't include `u128`, we cannot write the line above. This is because that line assumes that `input` must be some specific number type, and in that code, it is simply generic.

However, `BalanceOf<T>` [does have traits](https://paritytech.github.io/polkadot-sdk/master/frame_support/traits/tokens/trait.Balance.html) that we can use to interact with it. The key one being [`AtLeast32BitUnsigned`](https://paritytech.github.io/polkadot-sdk/master/polkadot_sdk_frame/arithmetic/trait.AtLeast32BitUnsigned.html).
However, `BalanceOf<T>` [does have traits](https://docs.rs/frame-support/37.0.0/frame_support/traits/tokens/trait.Balance.html) that we can use to interact with it. The key one being [`AtLeast32BitUnsigned`](https://docs.rs/polkadot-sdk-frame/0.6.0/polkadot_sdk_frame/arithmetic/trait.AtLeast32BitUnsigned.html).

This means our `BalanceOf<T>` must be an unsigned integer, and must be at least `u32`. So it could be `u32`, `u64`, `u128`, or even bigger if you import other crates with those larger unsigned types.

Expand Down
2 changes: 1 addition & 1 deletion steps/50/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ To execute a purchase, we need to transfer two things:

### Transfer the Native Balance

To transfer the `NativeBalance`, you can use the [`transfer`](https://paritytech.github.io/polkadot-sdk/master/frame_support/traits/tokens/fungible/trait.Mutate.html#method.transfer) API which is included in the `fungible::Mutate` trait.
To transfer the `NativeBalance`, you can use the [`transfer`](https://docs.rs/frame-support/37.0.0/frame_support/traits/tokens/fungible/trait.Mutate.html#method.transfer) API which is included in the `fungible::Mutate` trait.

```rust
fn transfer(
Expand Down
2 changes: 1 addition & 1 deletion steps/8/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The last thing we have included in our starting template is a simple event.

When an callable function completes successfully, there is often some metadata you would like to expose to the outside world about what exactly happened during the execution.
When a callable function completes successfully, there is often some metadata you would like to expose to the outside world about what exactly happened during the execution.

Events allow Pallets to express that something has happened, and allows off-chain systems like indexers or block explorers to track certain state transitions.

Expand Down

0 comments on commit 4a9f17a

Please sign in to comment.