Skip to content

Commit

Permalink
Merge pull request #1636 from CosmWasm/deprecate-cosmwasm-storage-types
Browse files Browse the repository at this point in the history
Deprecate all cosmwasm-storage types
  • Loading branch information
webmaster128 authored May 4, 2023
2 parents c3cd52c + bdcd528 commit 14864cc
Show file tree
Hide file tree
Showing 32 changed files with 367 additions and 303 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ and this project adheres to
[#1664]: https://github.com/CosmWasm/cosmwasm/pull/1664
[#1667]: https://github.com/CosmWasm/cosmwasm/pull/1667

### Deprecated

- cosmwasm-storage: All exports are deprecated because this crate will be
removed with CosmWasm 2.0 ([#1596]).

[#1596]: https://github.com/CosmWasm/cosmwasm/issues/1596

## [1.2.5] - 2023-05-02

### Added
Expand Down
9 changes: 0 additions & 9 deletions contracts/crypto-verify/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion contracts/crypto-verify/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]
[dependencies]
cosmwasm-schema = { path = "../../packages/schema" }
cosmwasm-std = { path = "../../packages/std", features = ["iterator"] }
cosmwasm-storage = { path = "../../packages/storage", features = ["iterator"] }
hex = "0.4"
rlp = "0.5"
schemars = "0.8.3"
Expand Down
9 changes: 0 additions & 9 deletions contracts/cyberpunk/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion contracts/cyberpunk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ rust-argon2 = "0.8"
thiserror = "1.0.26"

[dev-dependencies]
cosmwasm-storage = { path = "../../packages/storage", default-features = false }
cosmwasm-vm = { path = "../../packages/vm", default-features = false }
9 changes: 0 additions & 9 deletions contracts/floaty/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion contracts/floaty/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ serde = { version = "1.0.103", default-features = false, features = ["derive"] }
thiserror = "1.0.26"

[dev-dependencies]
cosmwasm-storage = { path = "../../packages/storage" }
cosmwasm-vm = { path = "../../packages/vm", default-features = false, features = ["iterator"] }
9 changes: 0 additions & 9 deletions contracts/hackatom/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion contracts/hackatom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,4 @@ sha2 = "0.10"
thiserror = "1.0.26"

[dev-dependencies]
cosmwasm-storage = { path = "../../packages/storage", default-features = false }
cosmwasm-vm = { path = "../../packages/vm", default-features = false }
9 changes: 0 additions & 9 deletions contracts/ibc-reflect-send/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion contracts/ibc-reflect-send/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]
[dependencies]
cosmwasm-schema = { path = "../../packages/schema" }
cosmwasm-std = { path = "../../packages/std", features = ["iterator", "staking", "stargate"] }
cosmwasm-storage = { path = "../../packages/storage", features = ["iterator"] }
schemars = "0.8.3"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }

Expand Down
32 changes: 15 additions & 17 deletions contracts/ibc-reflect-send/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cosmwasm_std::{
entry_point, to_binary, CosmosMsg, Deps, DepsMut, Env, IbcMsg, MessageInfo, Order,
QueryResponse, Response, StdError, StdResult,
entry_point, to_binary, CosmosMsg, Deps, DepsMut, Env, IbcMsg, MessageInfo, QueryResponse,
Response, StdError, StdResult,
};

use crate::ibc::PACKET_LIFETIME;
Expand All @@ -9,7 +9,7 @@ use crate::msg::{
AccountInfo, AccountResponse, AdminResponse, ExecuteMsg, InstantiateMsg, ListAccountsResponse,
QueryMsg,
};
use crate::state::{accounts, accounts_read, config, config_read, Config};
use crate::state::{load_account, load_config, range_accounts, save_config, Config};

#[entry_point]
pub fn instantiate(
Expand All @@ -20,7 +20,7 @@ pub fn instantiate(
) -> StdResult<Response> {
// we store the reflect_id for creating accounts later
let cfg = Config { admin: info.sender };
config(deps.storage).save(&cfg)?;
save_config(deps.storage, &cfg)?;

Ok(Response::new().add_attribute("action", "instantiate"))
}
Expand Down Expand Up @@ -48,12 +48,12 @@ pub fn handle_update_admin(
new_admin: String,
) -> StdResult<Response> {
// auth check
let mut cfg = config(deps.storage).load()?;
let mut cfg = load_config(deps.storage)?;
if info.sender != cfg.admin {
return Err(StdError::generic_err("Only admin may set new admin"));
}
cfg.admin = deps.api.addr_validate(&new_admin)?;
config(deps.storage).save(&cfg)?;
save_config(deps.storage, &cfg)?;

Ok(Response::new()
.add_attribute("action", "handle_update_admin")
Expand All @@ -68,12 +68,12 @@ pub fn handle_send_msgs(
msgs: Vec<CosmosMsg>,
) -> StdResult<Response> {
// auth check
let cfg = config(deps.storage).load()?;
let cfg = load_config(deps.storage)?;
if info.sender != cfg.admin {
return Err(StdError::generic_err("Only admin may send messages"));
}
// ensure the channel exists (not found if not registered)
accounts(deps.storage).load(channel_id.as_bytes())?;
load_account(deps.storage, &channel_id)?;

// construct a packet to send
let packet = PacketMsg::Dispatch { msgs };
Expand All @@ -96,12 +96,12 @@ pub fn handle_check_remote_balance(
channel_id: String,
) -> StdResult<Response> {
// auth check
let cfg = config(deps.storage).load()?;
let cfg = load_config(deps.storage)?;
if info.sender != cfg.admin {
return Err(StdError::generic_err("Only admin may send messages"));
}
// ensure the channel exists (not found if not registered)
accounts(deps.storage).load(channel_id.as_bytes())?;
load_account(deps.storage, &channel_id)?;

// construct a packet to send
let packet = PacketMsg::Balances {};
Expand Down Expand Up @@ -141,7 +141,7 @@ pub fn handle_send_funds(
}

// load remote account
let data = accounts(deps.storage).load(reflect_channel_id.as_bytes())?;
let data = load_account(deps.storage, &reflect_channel_id)?;
let remote_addr = match data.remote_addr {
Some(addr) => addr,
None => {
Expand Down Expand Up @@ -175,16 +175,14 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<QueryResponse> {
}

fn query_account(deps: Deps, channel_id: String) -> StdResult<AccountResponse> {
let account = accounts_read(deps.storage).load(channel_id.as_bytes())?;
let account = load_account(deps.storage, &channel_id)?;
Ok(account.into())
}

fn query_list_accounts(deps: Deps) -> StdResult<ListAccountsResponse> {
let accounts: StdResult<Vec<_>> = accounts_read(deps.storage)
.range(None, None, Order::Ascending)
let accounts: StdResult<Vec<_>> = range_accounts(deps.storage)
.map(|r| {
let (k, account) = r?;
let channel_id = String::from_utf8(k)?;
let (channel_id, account) = r?;
Ok(AccountInfo::convert(channel_id, account))
})
.collect();
Expand All @@ -194,7 +192,7 @@ fn query_list_accounts(deps: Deps) -> StdResult<ListAccountsResponse> {
}

fn query_admin(deps: Deps) -> StdResult<AdminResponse> {
let Config { admin } = config_read(deps.storage).load()?;
let Config { admin } = load_config(deps.storage)?;
Ok(AdminResponse {
admin: admin.into(),
})
Expand Down
57 changes: 28 additions & 29 deletions contracts/ibc-reflect-send/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use cosmwasm_std::{
use crate::ibc_msg::{
AcknowledgementMsg, BalancesResponse, DispatchResponse, PacketMsg, WhoAmIResponse,
};
use crate::state::{accounts, AccountData};
use crate::state::{may_load_account, remove_account, save_account, AccountData};

pub const IBC_APP_VERSION: &str = "ibc-reflect-v1";

Expand Down Expand Up @@ -55,7 +55,7 @@ pub fn ibc_channel_connect(

// create an account holder the channel exists (not found if not registered)
let data = AccountData::default();
accounts(deps.storage).save(channel_id.as_bytes(), &data)?;
save_account(deps.storage, channel_id, &data)?;

// construct a packet to send
let packet = PacketMsg::WhoAmI {};
Expand All @@ -82,7 +82,7 @@ pub fn ibc_channel_close(

// remove the channel
let channel_id = &channel.endpoint.channel_id;
accounts(deps.storage).remove(channel_id.as_bytes());
remove_account(deps.storage, channel_id);

Ok(IbcBasicResponse::new()
.add_attribute("action", "ibc_close")
Expand Down Expand Up @@ -154,19 +154,16 @@ fn acknowledge_who_am_i(
.add_attribute("error", e))
}
};

accounts(deps.storage).update(caller.as_bytes(), |acct| -> StdResult<_> {
match acct {
Some(mut acct) => {
// set the account the first time
if acct.remote_addr.is_none() {
acct.remote_addr = Some(account);
}
Ok(acct)
match may_load_account(deps.storage, &caller)? {
Some(mut acct) => {
// set the account the first time
if acct.remote_addr.is_none() {
acct.remote_addr = Some(account);
}
None => Err(StdError::generic_err("no account to update")),
save_account(deps.storage, &caller, &acct)?;
}
})?;
None => return Err(StdError::generic_err("no account to update")),
}

Ok(IbcBasicResponse::new().add_attribute("action", "acknowledge_who_am_i"))
}
Expand All @@ -188,26 +185,28 @@ fn acknowledge_balances(
}
};

accounts(deps.storage).update(caller.as_bytes(), |acct| -> StdResult<_> {
match acct {
Some(acct) => {
if let Some(old_addr) = acct.remote_addr {
if old_addr != account {
return Err(StdError::generic_err(format!(
"remote account changed from {} to {}",
old_addr, account
)));
}
match may_load_account(deps.storage, &caller)? {
Some(acct) => {
if let Some(old_addr) = acct.remote_addr {
if old_addr != account {
return Err(StdError::generic_err(format!(
"remote account changed from {} to {}",
old_addr, account
)));
}
Ok(AccountData {
}
save_account(
deps.storage,
&caller,
&AccountData {
last_update_time: env.block.time,
remote_addr: Some(account),
remote_balance: balances,
})
}
None => Err(StdError::generic_err("no account to update")),
},
)?;
}
})?;
None => return Err(StdError::generic_err("no account to update")),
}

Ok(IbcBasicResponse::new().add_attribute("action", "acknowledge_balances"))
}
Expand Down
Loading

0 comments on commit 14864cc

Please sign in to comment.