Skip to content

Commit

Permalink
apply some suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
uint committed Jun 4, 2024
1 parent 1568dec commit ef4500f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
28 changes: 16 additions & 12 deletions src/pages/cw-storage-plus.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Introduction

Not being able to persist data across calls would limit the utility of smart
contracts. How could a smart contract
contracts. Think of these problems:

- implement a token if it could not keep track of balances,
- implement a voting system if it could not keep track of votes, or
- implement a game if it could not keep track of scores?
- How could a smart contract implement a token if it could not keep track of
balances?
- How could a smart contract implement a voting system if it could not keep
track of votes?
- How could a smart contract implement a game if it could not keep track of
scores?

This is why a _CosmWasm_ smart contract has access to the storage facilities
offered by the _Cosmos SDK_. These facilities are essentially a binary key-value
Expand All @@ -16,9 +19,9 @@ store, with records stored on-chain.
While developing smart contracts, it's important to remember on-chain storage
is, as always, pricey. Conventionally, developers often draw the line at a
"small logo image" (think a few KBs). If you need to store bigger things, it's
likely time to consider off-chain storage (like IPFS or some centralized storage).
Techniques for securely and reliably storing large data off-chain are beyond the
scope of this document.
likely time to consider off-chain storage (like IPFS or some centralized
storage). Techniques for securely and reliably storing large data off-chain are
beyond the scope of this document.

Trying to minimize bloat is always good practice when it comes to on-chain
storage.
Expand All @@ -31,11 +34,12 @@ storing and retrieving data. If you're curious, you can check it out right

This API is raw in that it exposes the **binary** key-value store. While you're
free to use it directly, you're likely to find that finicky and error-prone.
_cw-storage-plus_ is a library that builds on top of this API to
_cw-storage-plus_ is a library that builds on top of this API to do the
following:

- eliminate the need to manually serialize and deserialize data,
- provide a type-safe interface for storing and retrieving data,
- help manage keys, and
- provide featureful persistent data structures.
- eliminate the need to manually serialize and deserialize data
- provide a type-safe interface for storing and retrieving data
- help manage keys
- provide featureful persistent data structures

Let's explore!
16 changes: 9 additions & 7 deletions src/pages/cw-storage-plus/basics.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { Callout } from "nextra/components";
## Containers

_cw-storage-plus_ provides a number of storage containers that can be used to
store data on the blockchain. The fundamental ones are
store data on the blockchain. The fundamental ones are:

- [`Item`](containers/item),
- [`Map`](containers/map),
- [`Deque`](containers/deque).
- [`Item`](containers/item)
- [`Map`](containers/map)
- [`Deque`](containers/deque)

An [`Item`](containers/item) is a simple container that stores a single value.
The other two are a little more involved - they are collections capable of
Expand All @@ -20,7 +20,9 @@ storing multiple values, and provide several methods to interact with them.
One task of a storage library like `cw-storage-plus` is to manage the namespace
of keys provided by the blockchain.

When constructing a container, you must provide a key of type `&'static str`.
When constructing a container, you must provide a key of type `&'static str` (or
use
[`new_dyn`](https://docs.rs/cw-storage-plus/latest/cw_storage_plus/struct.Item.html#method.new_dyn)).
This usually means you'll be providing a string literal or some constant.

In the case of an [`Item`](containers/item), the provided key is the exact key
Expand Down Expand Up @@ -49,7 +51,7 @@ better advice.
is saved without any sort of length-prefixing of the key. It is, in theory,
possible for an `Item`'s key to conflict with one of the keys generated by a
`Map` or `Deque`. In practice, this is unlikely unless you use very long
prefixes or start your `Item`'s key with the ␀ ASCII character. Probably don't
prefixes or start your `Item`'s key with the null byte. Probably don't
do that!
</Callout>

Expand Down Expand Up @@ -78,5 +80,5 @@ storage, you'll have to derive these traits.
[*serde-json-wasm*](https://github.com/CosmWasm/serde-json-wasm) under the
hood. This provides determinism in some corners -
[*serde_json*](https://github.com/serde-rs/json) would not be suited for the
blockchain world!
blockchain world! On top of that, `serde-json-wasm` is just smaller.
</Callout>

0 comments on commit ef4500f

Please sign in to comment.