A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/second-state/SewUp/wiki/Storage-Guide below:

Storage Guide · second-state/SewUp Wiki · GitHub

The basic storage unit of Ethereum is Bytes32, this means you still need store 32 bytes to store a byte of data. There are some low level concern on the storage, but it should not be required for a developer to build some application on top of blockchain network. This why Sewup try to provide kv, rdb features and try to do some abstraction on the storage. However, the thing developer still keep in mind is that the storage space on blockchain is expensive than traditional web, due to multiple data copy in the clusters.

In SewUp, the Raw structure is the basic storage unit. It also a wrapper of Bytes32. It is easy to convert from Address, unsigned integers, str, &str, String, &String, Vec<u8>, [u8], Address, unsigned integer types or into Bytes32, Bytes20. Row is the list structure of Raw, and Raw can try_from Row, on the other hand Raw can convert into Row.

For example,

let proposals_bucket = storage.bucket::<usize, Proposal>("proposals")?
let raw = Raw::from(777usize);
let lucky_number: usize = raw.into();

Currently, there is no constant, singleton, and array-like storage.
Here are some suggestions:

If you want to store a limited length of String, you can use the SizedString! and SizedString, this macro help you use correct size of Raw to store the String.

For example,

let ss = sewup::types::SizedString::new(10).from_str("hello").unwrap();
assert!(ss.len() == 5);
assert!(ss.capacity() == 10);
assert_eq!(ss.to_utf8_string().unwrap(), "hello");

If you want to debug the storage, you can use ewasm_storage_debug!() or ewasm_storage_debug!(point1) to inspect the contract storage as following image.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4