Secret Network v1.4 (CosmWasm 1.0)
CosmWasm 1.0 Breaking Changes
Address API Changes
HumanAddr
has been deprecated in favour of simplyString
. It never added any significant safety bonus overString
and was just a marker type. The new typeAddr
was created to hold validated addresses. Those can be created viaAddr::unchecked
,Api::addr_validate
,Api::addr_humanize
and JSON deserialization. In order to maintain type safety, deserialization intoAddr
must 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
Then add the macro attribute #[cfg_attr(not(feature = "library"), entry_point)]
to your contract.rs as follows:
init
Env
split intoEnv
andMessageInfo
InitResponse
andInitResult
deprecated, please useResponse
function name changed from
init
toinstantiate
handle
Env
split intoEnv
andMessageInfo
HandleResponse
andHandleResult
deprecated, please useResponse
function name changed from
handle
toexecute
query
new argument
Env
added
migrate
Env
split intoEnv
andMessageInfo
MigrateResponse
andMigrateResult
deprecated, please useResponse
Response no longer be built using a structure literal
This is a step toward better API stability.
Sub-messages & Reply
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::Item
Remove
read_*
andstore_*
functionsDefine
Item
as following (must prepend the length of key)
cosmwasm_storage::Bucket
->cw_storage_plus::Map
Remove
read_*
andstore_*
functionsDefine
Map
as 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?