move examples
Types with Abilities
Simply described:
Copy – value can be copied (or cloned by value).
Drop – value can be dropped by the end of scope.
Key – value can be used as a key for global storage operations.
Store – value can be stored inside global storage.
https://move-book.com/advanced-topics/types-with-abilities.html
table
A table is a map-like collection. But unlike a traditional collection, it’s keys and values are not stored within the Table value, but instead are stored using Sui’s object system. The Table struct acts only as a handle into the object system to retrieve those keys and values. Note that this means that Table values with exactly the same key-value mapping will not be equal, with ==, at runtime. For example
https://github.com/MystenLabs/sui/blob/main/crates/sui-framework/docs/table.md
u64
参考 https://github.com/corriente-labs/evm-sui-poc/blob/develop/sources/account.move
public fun get_value(acct: &Account, key: Big256): Big256 { if (table::contains(&acct.storage, key)) { *table::borrow(&acct.storage, key) } else { u256::zero() } } public fun set_value(acct: &mut Account, key: Big256, val: Big256) { if (table::contains(&acct.storage, key)) { let v = table::borrow_mut(&mut acct.storage, key); *v = val; } else { table::add(&mut acct.storage, key, val); }; }
struct
struct MintedAmount2 has store { whitelist_sale: u64, public_sale: u64 } minted_table: Table<address, MintedAmount2>, minted_table: table::new<address, MintedAmount2>(ctx),
table::add(&mut global.minted_table, sender, MintedAmount2{ whitelist_sale: 0, public_sale: 0 }); let minted_table = table::borrow_mut(&mut global.minted_table, sender); minted_table.whitelist_sale = minted_table.whitelist_sale + 1; minted_table.public_sale = minted_table.public_sale + 2; print(&minted_table.whitelist_sale); print(&minted_table.public_sale);