Secret Network v1.4 (CosmWasm 1.0)
CosmWasm 1.0 Breaking Changes
Address API Changes
HumanAddrhas been deprecated in favour of simplyString. It never added any significant safety bonus overStringand was just a marker type. The new typeAddrwas created to hold validated addresses. Those can be created viaAddr::unchecked,Api::addr_validate,Api::addr_humanizeand JSON deserialization. In order to maintain type safety, deserialization intoAddrmust only be done from trusted sources like a contract's state or a query response. User inputs must be deserialized intoString.deps.api.human_address(&CanonicalAddr)=>deps.api.addr_humanize(&CanonicalAddr)deps.api.canonical_address(&HumanAddr)=>deps.api.addr_canonicalize(&str)
Extern Method Interface Changes
Use the new entry point system. From lib.rs remove
#[cfg(target_arch = "wasm32")]
cosmwasm_std::create_entry_points!(contract);
// or
#[cfg(target_arch = "wasm32")]
cosmwasm_std::create_entry_points_with_migration!(contract);Then add the macro attribute #[cfg_attr(not(feature = "library"), entry_point)] to your contract.rs as follows:
initEnvsplit intoEnvandMessageInfoInitResponseandInitResultdeprecated, please useResponsefunction name changed from
inittoinstantiate
handleEnvsplit intoEnvandMessageInfoHandleResponseandHandleResultdeprecated, please useResponsefunction name changed from
handletoexecute
querynew argument
Envadded
migrateEnvsplit intoEnvandMessageInfoMigrateResponseandMigrateResultdeprecated, please useResponse
Response no longer be built using a structure literal
Response can no longer be built using a struct literal. Please use Response::new as well as relevant builder-style setters to set the data.
This is a step toward better API stability.
Sub-messages & Reply
The sub-messages feature can be used to get the response data or events from the executed contract. For example, if a contract wants to get the address of the child contract which is instantiated from the contract. The contract can send MsgInstantiate as sub-messages with ReplyOn::Success option like https://github.com/terraswap/terraswap/blob/7cf47f5e811fe0c4643a7cd09500702c1e7f3a6b/contracts/terraswap_factory/src/contract.rs#L128-L142.
Then the reply is only executed when the instantiate is successful with the instantiate response data. https://github.com/terraswap/terraswap/blob/7cf47f5e811fe0c4643a7cd09500702c1e7f3a6b/contracts/terraswap_factory/src/contract.rs#L148-L170.
Storage Migration
Rename the type Extern to Deps, and radically simplify the init/handle/migrate/query entrypoints. Rather than &mut Extern<S, A, Q>, use DepsMut. And instead of &Extern<S, A, Q>, use Deps. If you ever pass eg. foo<A: Api>(api: A) around, you must now use dynamic trait pointers: foo(api: &dyn Api). Here is the quick search-replace guide on how to fix contract.rs:
In production (non-test) code:
In test code only:
If you use cosmwasm-storage, in state.rs:
Advanced Storage
We can still use singleton and bucket. But if you want more advanced storage access, you can use cw-storage-plus with following migration steps.
cowmasm_storage::Singleton->cw_stroage_plus::ItemRemove
read_*andstore_*functionsDefine
Itemas following (must prepend the length of key)
cosmwasm_storage::Bucket->cw_storage_plus::MapRemove
read_*andstore_*functionsDefine
Mapas following
Raw Querier migration
The core now just returns raw bytes without json encoding, so we can receive the query response as what the data was stored.
Also, mock_querier has to remove one to_binary from its raw query response.
Last updated
Was this helpful?