Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use storage instead of deps #747

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 53 additions & 47 deletions contracts/dao-dao-core/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use cosmwasm_std::entry_point;
use cosmwasm_std::{
from_binary, to_binary, Addr, Binary, CosmosMsg, Deps, DepsMut, Empty, Env, MessageInfo, Order,
Reply, Response, StdError, StdResult, SubMsg, WasmMsg,
Reply, Response, StdError, StdResult, Storage, SubMsg, WasmMsg,
};
use cw2::{get_contract_version, set_contract_version, ContractVersion};
use cw_paginate_storage::{paginate_map, paginate_map_keys, paginate_map_values};
Expand Down Expand Up @@ -121,8 +121,8 @@ pub fn execute(
execute_proposal_hook(deps.as_ref(), info.sender, msgs)
}
ExecuteMsg::Pause { duration } => execute_pause(deps, env, info.sender, duration),
ExecuteMsg::Receive(_) => execute_receive_cw20(deps, info.sender),
ExecuteMsg::ReceiveNft(_) => execute_receive_cw721(deps, info.sender),
ExecuteMsg::Receive(_) => execute_receive_cw20(deps.storage, info.sender),
ExecuteMsg::ReceiveNft(_) => execute_receive_cw721(deps.storage, info.sender),
ExecuteMsg::RemoveItem { key } => execute_remove_item(deps, env, info.sender, key),
ExecuteMsg::SetItem { key, value } => execute_set_item(deps, env, info.sender, key, value),
ExecuteMsg::UpdateConfig { config } => {
Expand Down Expand Up @@ -516,24 +516,30 @@ pub fn execute_update_sub_daos_list(
.add_attribute("sender", sender))
}

pub fn execute_receive_cw20(deps: DepsMut, sender: Addr) -> Result<Response, ContractError> {
let config = CONFIG.load(deps.storage)?;
pub fn execute_receive_cw20(
storage: &mut dyn Storage,
sender: Addr,
) -> Result<Response, ContractError> {
let config = CONFIG.load(storage)?;
if !config.automatically_add_cw20s {
Ok(Response::new())
} else {
CW20_LIST.save(deps.storage, sender.clone(), &Empty {})?;
CW20_LIST.save(storage, sender.clone(), &Empty {})?;
Ok(Response::new()
.add_attribute("action", "receive_cw20")
.add_attribute("token", sender))
}
}

pub fn execute_receive_cw721(deps: DepsMut, sender: Addr) -> Result<Response, ContractError> {
let config = CONFIG.load(deps.storage)?;
pub fn execute_receive_cw721(
storage: &mut dyn Storage,
sender: Addr,
) -> Result<Response, ContractError> {
let config = CONFIG.load(storage)?;
if !config.automatically_add_cw721s {
Ok(Response::new())
} else {
CW721_LIST.save(deps.storage, sender.clone(), &Empty {})?;
CW721_LIST.save(storage, sender.clone(), &Empty {})?;
Ok(Response::new()
.add_attribute("action", "receive_cw721")
.add_attribute("token", sender))
Expand All @@ -543,27 +549,27 @@ pub fn execute_receive_cw721(deps: DepsMut, sender: Addr) -> Result<Response, Co
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::Admin {} => query_admin(deps),
QueryMsg::AdminNomination {} => query_admin_nomination(deps),
QueryMsg::Config {} => query_config(deps),
QueryMsg::Admin {} => query_admin(deps.storage),
QueryMsg::AdminNomination {} => query_admin_nomination(deps.storage),
QueryMsg::Config {} => query_config(deps.storage),
QueryMsg::Cw20TokenList { start_after, limit } => query_cw20_list(deps, start_after, limit),
QueryMsg::Cw20Balances { start_after, limit } => {
query_cw20_balances(deps, env, start_after, limit)
}
QueryMsg::Cw721TokenList { start_after, limit } => {
query_cw721_list(deps, start_after, limit)
}
QueryMsg::DumpState {} => query_dump_state(deps, env),
QueryMsg::GetItem { key } => query_get_item(deps, key),
QueryMsg::Info {} => query_info(deps),
QueryMsg::DumpState {} => query_dump_state(deps.storage, env),
QueryMsg::GetItem { key } => query_get_item(deps.storage, key),
QueryMsg::Info {} => query_info(deps.storage),
QueryMsg::ListItems { start_after, limit } => query_list_items(deps, start_after, limit),
QueryMsg::PauseInfo {} => query_paused(deps, env),
QueryMsg::PauseInfo {} => query_paused(deps.storage, env),
QueryMsg::ProposalModules { start_after, limit } => {
query_proposal_modules(deps, start_after, limit)
}
QueryMsg::ProposalModuleCount {} => query_proposal_module_count(deps),
QueryMsg::TotalPowerAtHeight { height } => query_total_power_at_height(deps, height),
QueryMsg::VotingModule {} => query_voting_module(deps),
QueryMsg::VotingModule {} => query_voting_module(deps.storage),
QueryMsg::VotingPowerAtHeight { address, height } => {
query_voting_power_at_height(deps, address, height)
}
Expand All @@ -573,27 +579,27 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
QueryMsg::ListSubDaos { start_after, limit } => {
query_list_sub_daos(deps, start_after, limit)
}
QueryMsg::DaoURI {} => query_dao_uri(deps),
QueryMsg::DaoURI {} => query_dao_uri(deps.storage),
}
}

pub fn query_admin(deps: Deps) -> StdResult<Binary> {
let admin = ADMIN.load(deps.storage)?;
pub fn query_admin(storage: &dyn Storage) -> StdResult<Binary> {
let admin = ADMIN.load(storage)?;
to_binary(&admin)
}

pub fn query_admin_nomination(deps: Deps) -> StdResult<Binary> {
let nomination = NOMINATED_ADMIN.may_load(deps.storage)?;
pub fn query_admin_nomination(storage: &dyn Storage) -> StdResult<Binary> {
let nomination = NOMINATED_ADMIN.may_load(storage)?;
to_binary(&AdminNominationResponse { nomination })
}

pub fn query_config(deps: Deps) -> StdResult<Binary> {
let config = CONFIG.load(deps.storage)?;
pub fn query_config(storage: &dyn Storage) -> StdResult<Binary> {
let config = CONFIG.load(storage)?;
to_binary(&config)
}

pub fn query_voting_module(deps: Deps) -> StdResult<Binary> {
let voting_module = VOTING_MODULE.load(deps.storage)?;
pub fn query_voting_module(storage: &dyn Storage) -> StdResult<Binary> {
let voting_module = VOTING_MODULE.load(storage)?;
to_binary(&voting_module)
}

Expand Down Expand Up @@ -654,8 +660,8 @@ pub fn query_active_proposal_modules(
)
}

fn get_pause_info(deps: Deps, env: Env) -> StdResult<PauseInfoResponse> {
Ok(match PAUSED.may_load(deps.storage)? {
fn get_pause_info(storage: &dyn Storage, env: Env) -> StdResult<PauseInfoResponse> {
Ok(match PAUSED.may_load(storage)? {
Some(expiration) => {
if expiration.is_expired(&env.block) {
PauseInfoResponse::Unpaused {}
Expand All @@ -667,22 +673,22 @@ fn get_pause_info(deps: Deps, env: Env) -> StdResult<PauseInfoResponse> {
})
}

pub fn query_paused(deps: Deps, env: Env) -> StdResult<Binary> {
to_binary(&get_pause_info(deps, env)?)
pub fn query_paused(storage: &dyn Storage, env: Env) -> StdResult<Binary> {
to_binary(&get_pause_info(storage, env)?)
}

pub fn query_dump_state(deps: Deps, env: Env) -> StdResult<Binary> {
let admin = ADMIN.load(deps.storage)?;
let config = CONFIG.load(deps.storage)?;
let voting_module = VOTING_MODULE.load(deps.storage)?;
pub fn query_dump_state(storage: &dyn Storage, env: Env) -> StdResult<Binary> {
let admin = ADMIN.load(storage)?;
let config = CONFIG.load(storage)?;
let voting_module = VOTING_MODULE.load(storage)?;
let proposal_modules = PROPOSAL_MODULES
.range(deps.storage, None, None, cosmwasm_std::Order::Ascending)
.range(storage, None, None, cosmwasm_std::Order::Ascending)
.map(|kv| Ok(kv?.1))
.collect::<StdResult<Vec<ProposalModule>>>()?;
let pause_info = get_pause_info(deps, env)?;
let version = get_contract_version(deps.storage)?;
let active_proposal_module_count = ACTIVE_PROPOSAL_MODULE_COUNT.load(deps.storage)?;
let total_proposal_module_count = TOTAL_PROPOSAL_MODULE_COUNT.load(deps.storage)?;
let pause_info = get_pause_info(storage, env)?;
let version = get_contract_version(storage)?;
let active_proposal_module_count = ACTIVE_PROPOSAL_MODULE_COUNT.load(storage)?;
let total_proposal_module_count = TOTAL_PROPOSAL_MODULE_COUNT.load(storage)?;
to_binary(&DumpStateResponse {
admin,
config,
Expand Down Expand Up @@ -716,13 +722,13 @@ pub fn query_total_power_at_height(deps: Deps, height: Option<u64>) -> StdResult
to_binary(&total_power)
}

pub fn query_get_item(deps: Deps, item: String) -> StdResult<Binary> {
let item = ITEMS.may_load(deps.storage, item)?;
pub fn query_get_item(storage: &dyn Storage, item: String) -> StdResult<Binary> {
let item = ITEMS.may_load(storage, item)?;
to_binary(&GetItemResponse { item })
}

pub fn query_info(deps: Deps) -> StdResult<Binary> {
let info = cw2::get_contract_version(deps.storage)?;
pub fn query_info(storage: &dyn Storage) -> StdResult<Binary> {
let info = cw2::get_contract_version(storage)?;
to_binary(&dao_interface::voting::InfoResponse { info })
}

Expand All @@ -732,7 +738,7 @@ pub fn query_list_items(
limit: Option<u32>,
) -> StdResult<Binary> {
to_binary(&paginate_map(
deps,
deps.storage,
&ITEMS,
start_after,
limit,
Expand Down Expand Up @@ -815,7 +821,7 @@ pub fn query_list_sub_daos(
.transpose()?;

let subdaos = cw_paginate_storage::paginate_map(
deps,
deps.storage,
&SUBDAO_LIST,
start_at.as_ref(),
limit,
Expand All @@ -833,8 +839,8 @@ pub fn query_list_sub_daos(
to_binary(&subdaos)
}

pub fn query_dao_uri(deps: Deps) -> StdResult<Binary> {
let config = CONFIG.load(deps.storage)?;
pub fn query_dao_uri(storage: &dyn Storage) -> StdResult<Binary> {
let config = CONFIG.load(storage)?;
to_binary(&DaoURIResponse {
dao_uri: config.dao_uri,
})
Expand Down
44 changes: 28 additions & 16 deletions contracts/external/cw-fund-distributor/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::state::{
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_binary, Addr, BankMsg, Binary, Coin, Decimal, Deps, DepsMut, Env, Fraction, MessageInfo,
Order, Response, StdError, StdResult, Uint128, WasmMsg,
Order, Response, StdError, StdResult, Storage, Uint128, WasmMsg,
};
use cw2::set_contract_version;
use cw_paginate_storage::paginate_map;
Expand Down Expand Up @@ -382,10 +382,10 @@ pub fn execute_claim_all(
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::VotingContract {} => query_voting_contract(deps),
QueryMsg::TotalPower {} => query_total_power(deps),
QueryMsg::NativeDenoms {} => query_native_denoms(deps),
QueryMsg::CW20Tokens {} => query_cw20_tokens(deps),
QueryMsg::VotingContract {} => query_voting_contract(deps.storage),
QueryMsg::TotalPower {} => query_total_power(deps.storage),
QueryMsg::NativeDenoms {} => query_native_denoms(deps.storage),
QueryMsg::CW20Tokens {} => query_cw20_tokens(deps.storage),
QueryMsg::NativeEntitlement { sender, denom } => {
query_native_entitlement(deps, sender, denom)
}
Expand All @@ -403,22 +403,22 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
}
}

pub fn query_voting_contract(deps: Deps) -> StdResult<Binary> {
let contract = VOTING_CONTRACT.load(deps.storage)?;
let distribution_height = DISTRIBUTION_HEIGHT.load(deps.storage)?;
pub fn query_voting_contract(storage: &dyn Storage) -> StdResult<Binary> {
let contract = VOTING_CONTRACT.load(storage)?;
let distribution_height = DISTRIBUTION_HEIGHT.load(storage)?;
to_binary(&VotingContractResponse {
contract,
distribution_height,
})
}

pub fn query_total_power(deps: Deps) -> StdResult<Binary> {
let total_power: Uint128 = TOTAL_POWER.may_load(deps.storage)?.unwrap_or_default();
pub fn query_total_power(storage: &dyn Storage) -> StdResult<Binary> {
let total_power: Uint128 = TOTAL_POWER.may_load(storage)?.unwrap_or_default();
to_binary(&TotalPowerResponse { total_power })
}

pub fn query_native_denoms(deps: Deps) -> StdResult<Binary> {
let native_balances = NATIVE_BALANCES.range(deps.storage, None, None, Order::Ascending);
pub fn query_native_denoms(storage: &dyn Storage) -> StdResult<Binary> {
let native_balances = NATIVE_BALANCES.range(storage, None, None, Order::Ascending);

let mut denom_responses: Vec<DenomResponse> = vec![];
for entry in native_balances {
Expand All @@ -432,8 +432,8 @@ pub fn query_native_denoms(deps: Deps) -> StdResult<Binary> {
to_binary(&denom_responses)
}

pub fn query_cw20_tokens(deps: Deps) -> StdResult<Binary> {
let cw20_balances = CW20_BALANCES.range(deps.storage, None, None, Order::Ascending);
pub fn query_cw20_tokens(storage: &dyn Storage) -> StdResult<Binary> {
let cw20_balances = CW20_BALANCES.range(storage, None, None, Order::Ascending);

let mut cw20_responses: Vec<CW20Response> = vec![];
for cw20 in cw20_balances {
Expand Down Expand Up @@ -497,7 +497,13 @@ pub fn query_native_entitlements(
) -> StdResult<Binary> {
let address = deps.api.addr_validate(sender.as_ref())?;
let relative_share = get_relative_share(&deps, sender)?;
let natives = paginate_map(deps, &NATIVE_BALANCES, start_at, limit, Order::Descending)?;
let natives = paginate_map(
deps.storage,
&NATIVE_BALANCES,
start_at,
limit,
Order::Descending,
)?;

let mut entitlements: Vec<NativeEntitlementResponse> = vec![];
for (denom, amount) in natives {
Expand Down Expand Up @@ -526,7 +532,13 @@ pub fn query_cw20_entitlements(
let address = deps.api.addr_validate(sender.as_ref())?;
let relative_share = get_relative_share(&deps, sender)?;
let start_at = start_at.map(|h| deps.api.addr_validate(&h)).transpose()?;
let cw20s = paginate_map(deps, &CW20_BALANCES, start_at, limit, Order::Descending)?;
let cw20s = paginate_map(
deps.storage,
&CW20_BALANCES,
start_at,
limit,
Order::Descending,
)?;

let mut entitlements: Vec<CW20EntitlementResponse> = vec![];
for (token, amount) in cw20s {
Expand Down
10 changes: 5 additions & 5 deletions contracts/external/cw-token-swap/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_binary, Addr, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, Uint128,
to_binary, Addr, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, Storage, Uint128,
};
use cw2::set_contract_version;
use cw_storage_plus::Item;
Expand Down Expand Up @@ -232,13 +232,13 @@ pub fn execute_withdraw(deps: DepsMut, info: MessageInfo) -> Result<Response, Co
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::Status {} => query_status(deps),
QueryMsg::Status {} => query_status(deps.storage),
}
}

pub fn query_status(deps: Deps) -> StdResult<Binary> {
let counterparty_one = COUNTERPARTY_ONE.load(deps.storage)?;
let counterparty_two = COUNTERPARTY_TWO.load(deps.storage)?;
pub fn query_status(storage: &dyn Storage) -> StdResult<Binary> {
let counterparty_one = COUNTERPARTY_ONE.load(storage)?;
let counterparty_two = COUNTERPARTY_TWO.load(storage)?;

to_binary(&StatusResponse {
counterparty_one,
Expand Down
6 changes: 3 additions & 3 deletions contracts/external/cw-tokenfactory-issuer/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ pub fn sudo(
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps<TokenFactoryQuery>, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::IsFrozen {} => to_binary(&queries::query_is_frozen(deps)?),
QueryMsg::Denom {} => to_binary(&queries::query_denom(deps)?),
QueryMsg::Owner {} => to_binary(&queries::query_owner(deps)?),
QueryMsg::IsFrozen {} => to_binary(&queries::query_is_frozen(deps.storage)?),
QueryMsg::Denom {} => to_binary(&queries::query_denom(deps.storage)?),
QueryMsg::Owner {} => to_binary(&queries::query_owner(deps.storage)?),
QueryMsg::BurnAllowance { address } => {
to_binary(&queries::query_burn_allowance(deps, address)?)
}
Expand Down
14 changes: 7 additions & 7 deletions contracts/external/cw-tokenfactory-issuer/src/queries.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{Addr, Deps, Order, StdResult, Uint128};
use cosmwasm_std::{Addr, Deps, Order, StdResult, Storage, Uint128};
use cw_storage_plus::{Bound, Map};
use token_bindings::TokenFactoryQuery;

Expand All @@ -16,18 +16,18 @@ use crate::state::{
const MAX_LIMIT: u32 = 30;
const DEFAULT_LIMIT: u32 = 10;

pub fn query_denom(deps: Deps<TokenFactoryQuery>) -> StdResult<DenomResponse> {
let denom = DENOM.load(deps.storage)?;
pub fn query_denom(storage: &dyn Storage) -> StdResult<DenomResponse> {
let denom = DENOM.load(storage)?;
Ok(DenomResponse { denom })
}

pub fn query_is_frozen(deps: Deps<TokenFactoryQuery>) -> StdResult<IsFrozenResponse> {
let is_frozen = IS_FROZEN.load(deps.storage)?;
pub fn query_is_frozen(storage: &dyn Storage) -> StdResult<IsFrozenResponse> {
let is_frozen = IS_FROZEN.load(storage)?;
Ok(IsFrozenResponse { is_frozen })
}

pub fn query_owner(deps: Deps<TokenFactoryQuery>) -> StdResult<OwnerResponse> {
let owner = OWNER.load(deps.storage)?;
pub fn query_owner(storage: &dyn Storage) -> StdResult<OwnerResponse> {
let owner = OWNER.load(storage)?;
Ok(OwnerResponse {
address: owner.into_string(),
})
Expand Down
Loading
Loading