Skip to content

Commit

Permalink
Update CHANGELOG and MIGRATING
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Oct 5, 2020
1 parent 365cbc6 commit 219ebd7
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 20 deletions.
13 changes: 10 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,20 @@

**cosmwasm-storage**

- Change order of arguments such that `storage` is always first followed by
namespace in `Bucket::new`, `Bucket::multilevel`, `ReadonlyBucket::new`,
`ReadonlyBucket::multilevel`, `bucket` and `bucket_read`.
- Change order of arguments such that `storage` is always first followed by
namespace in `PrefixedStorage::new`, `PrefixedStorage::multilevel`,
`ReadonlyPrefixedStorage::new`, `ReadonlyPrefixedStorage::multilevel`,
`prefixed` and `prefixed_read`.
- Remove `Storage` from the constructor of `Bucket::new` and rather pass
`&Storage` or `&mut Storage` as the first argument of every method.
- Remove `ReadonlyBucket` as `Bucket` now handles read-only and read-write
in one struct.
- Remove `Storage` from the constructor of `Singleton::new` and rather pass
`&Storage` or `&mut Storage` as the first argument of every method.
- Remove `ReadonlySingleton` as `Singleton` now handles read-only and read-write
in one struct.
- Modify `curval` and `nextval` to accept `Storage` and `key: &[u8]` directly
rather than require an intermediate `Sequence` object

**cosmwasm-vm**

Expand Down
86 changes: 69 additions & 17 deletions MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,6 @@ major releases of `cosmwasm`. Note that you can also view the
[staking development contract](https://github.com/CosmWasm/cosmwasm/tree/master/contracts/staking)
shows how this would look like using [snafu](https://crates.io/crates/snafu).

- Change order of arguments such that `storage` is always first followed by
namespace in `Bucket::new`, `Bucket::multilevel`, `ReadonlyBucket::new`,
`ReadonlyBucket::multilevel`, `PrefixedStorage::new`,
`PrefixedStorage::multilevel`, `ReadonlyPrefixedStorage::new`,
`ReadonlyPrefixedStorage::multilevel`, `bucket`, `bucket_read`, `prefixed` and
`prefixed_read`.

```rust
// before
let mut bucket = bucket::<_, Data>(b"data", &mut store);

// after
let mut bucket = bucket::<_, Data>(&mut store, b"data");
```

- Rename `InitResponse::log`, `MigrateResponse::log` and `HandleResponse::log`
to `InitResponse::attributes`, `MigrateResponse::attributes` and
`HandleResponse::attributes`. Replace calls to `log` with `attr`:
Expand Down Expand Up @@ -146,15 +131,15 @@ major releases of `cosmwasm`. Note that you can also view the

```rust
// before
bucket.update(b"maria", |mayd: Option<Data>| {
bucket.update(&mut storage, b"maria", |mayd: Option<Data>| {
let mut d = mayd.ok_or(StdError::not_found("Data"))?;
old_age = d.age;
d.age += 1;
Ok(d)
})

// after
bucket.update(b"maria", |mayd: Option<Data>| -> StdResult<_> {
bucket.update(&mut storage, b"maria", |mayd: Option<Data>| -> StdResult<_> {
let mut d = mayd.ok_or(StdError::not_found("Data"))?;
old_age = d.age;
d.age += 1;
Expand Down Expand Up @@ -255,6 +240,73 @@ major releases of `cosmwasm`. Note that you can also view the
let query_response = query(&mut deps, mock_env(), QueryMsg::Verifier {}).unwrap();
```

- Remove `Storage` from `Bucket` constructors and pass it in the calls.
You can also replace all usage of `ReadonlyBucket` with `Bucket`.
Same with `Singleton`. The following simplifications should be
made to `state.rs`:

```rust
// before
pub fn balances<S: Storage>(storage: &mut S) -> Bucket<S, Uint128> {
bucket(storage, PREFIX_BALANCE)
}

pub fn balances_read<S: ReadonlyStorage>(storage: &S) -> ReadonlyBucket<S, Uint128> {
bucket_read(storage, PREFIX_BALANCE)
}

pub fn token_info<S: Storage>(storage: &mut S) -> Singleton<S, TokenInfoResponse> {
singleton(storage, KEY_TOKEN_INFO)
}

pub fn token_info_read<S: ReadonlyStorage>(storage: &S) -> ReadonlySingleton<S, TokenInfoResponse> {
singleton_read(storage, KEY_TOKEN_INFO)
}

// after
pub fn balances() -> Bucket<Uint128> {
bucket(PREFIX_BALANCE)
}

pub fn token_info() -> Singleton<TokenInfoResponse> {
singleton(KEY_TOKEN_INFO)
}
```

The calling code in `contracts.rs` should be updated with the simpler
constructors and to pass in storage to the method calls. Note that you
never need `let mut bucket = ...` as all mutation occurs on the storage
argument, not the bucket itself:

```rust
// before
let invest = invest_info_read(&deps.storage).load()?;

claims(&mut deps.storage).update(sender_raw.as_slice(), |claim| {
Ok(claim.unwrap_or_default() + unbond)
})?;

let mut totals = total_supply(&mut deps.storage);
let mut supply = totals.load()?;
supply.issued += issued;
totals.save(&supply)?;

// after
let invest = invest_info().load(&deps.storage)?;

claims().update(&mut deps.storage, sender_raw.as_slice(), |claim| {
Ok(claim.unwrap_or_default() + unbond)
})?;

let totals = total_supply();
let mut supply = totals.load(&deps.storage)?;
supply.issued += issued;
totals.save(&mut deps.storage, &supply)?;
```

See [PR #559](https://github.com/CosmWasm/cosmwasm/pull/559/files)
for a complete example.

## 0.9 -> 0.10

Integration tests:
Expand Down

0 comments on commit 219ebd7

Please sign in to comment.