diff --git a/src/pages/cw-storage-plus.md b/src/pages/cw-storage-plus.md index 81304969..4158318a 100644 --- a/src/pages/cw-storage-plus.md +++ b/src/pages/cw-storage-plus.md @@ -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 @@ -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. @@ -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! diff --git a/src/pages/cw-storage-plus/basics.mdx b/src/pages/cw-storage-plus/basics.mdx index 3cf1dcee..7bc30af4 100644 --- a/src/pages/cw-storage-plus/basics.mdx +++ b/src/pages/cw-storage-plus/basics.mdx @@ -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 @@ -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 @@ -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! @@ -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.