# Cosmwasm notes ## Top level interface - `init` - `execute` - `query` ## Execute ### Input - the message - block information - Storage, Queries, Bulitin APIs ### Output - sub calls - sub cosmos msgs - attributes (Events) - attribute `contract_address` is inserted automatically ## Storage plus Encapulate cosmos-sdk storage apis (leveldb), flush is handled by host. The underlying storage api supports get/set/iterate_with_prefix. ### Abstractions - `Item`, a singleton key. - `Map`, `(prefix, pkey) -> value`. - `Prefix`, iterate key value subset which shares common prefix. - `IndexedMap`, `Map` with secondary indexes. - `trait Index/IndexList` secondary indexes. - When update, a) update primary map, b) remove old and insert new secondary indexes. #### Indexes - `UniqueIndex`, unique index, value is cloned. `(namespace, index_name, idx_value) -> {key, value}` - `MultiIndex`, support multiple values under same index key. `(namespace, index_name, idx_value, pk) -> b"pk_len"` ## Misc - Use `HumanAddr` in messages, use `CanonicalAddr` in storage.