From 2cde621df3d29d9972b719856aa8206b3ad44848 Mon Sep 17 00:00:00 2001 From: mr-t Date: Sat, 9 Sep 2023 16:19:14 +0200 Subject: [PATCH] use storage instead of deps --- contracts/dao-dao-core/src/contract.rs | 100 ++++++++++-------- .../cw-fund-distributor/src/contract.rs | 44 +++++--- .../external/cw-token-swap/src/contract.rs | 10 +- .../cw-tokenfactory-issuer/src/contract.rs | 6 +- .../cw-tokenfactory-issuer/src/queries.rs | 14 +-- .../dao-proposal-multiple/src/contract.rs | 46 ++++---- .../dao-proposal-single/src/contract.rs | 46 ++++---- .../src/contract.rs | 18 ++-- contracts/staking/cw20-stake/src/contract.rs | 14 +-- .../dao-voting-cw20-staked/src/contract.rs | 26 ++--- .../voting/dao-voting-cw4/src/contract.rs | 10 +- .../dao-voting-cw721-roles/src/contract.rs | 22 ++-- .../dao-voting-cw721-staked/src/contract.rs | 20 ++-- .../dao-voting-native-staked/src/contract.rs | 22 ++-- .../src/contract.rs | 26 ++--- packages/cw-hooks/src/lib.rs | 10 +- packages/cw-paginate-storage/README.md | 4 +- packages/cw-paginate-storage/src/lib.rs | 24 ++--- packages/dao-pre-propose-base/src/execute.rs | 2 +- .../dao-proposal-sudo/src/contract.rs | 20 ++-- .../dao-voting-cw20-balance/src/contract.rs | 22 ++-- 21 files changed, 262 insertions(+), 244 deletions(-) diff --git a/contracts/dao-dao-core/src/contract.rs b/contracts/dao-dao-core/src/contract.rs index 97f3a7d3e..ecc266fea 100644 --- a/contracts/dao-dao-core/src/contract.rs +++ b/contracts/dao-dao-core/src/contract.rs @@ -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}; @@ -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 } => { @@ -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 { - let config = CONFIG.load(deps.storage)?; +pub fn execute_receive_cw20( + storage: &mut dyn Storage, + sender: Addr, +) -> Result { + 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 { - let config = CONFIG.load(deps.storage)?; +pub fn execute_receive_cw721( + storage: &mut dyn Storage, + sender: Addr, +) -> Result { + 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)) @@ -543,9 +549,9 @@ pub fn execute_receive_cw721(deps: DepsMut, sender: Addr) -> Result StdResult { 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) @@ -553,17 +559,17 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { 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) } @@ -573,27 +579,27 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { 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 { - let admin = ADMIN.load(deps.storage)?; +pub fn query_admin(storage: &dyn Storage) -> StdResult { + let admin = ADMIN.load(storage)?; to_binary(&admin) } -pub fn query_admin_nomination(deps: Deps) -> StdResult { - let nomination = NOMINATED_ADMIN.may_load(deps.storage)?; +pub fn query_admin_nomination(storage: &dyn Storage) -> StdResult { + let nomination = NOMINATED_ADMIN.may_load(storage)?; to_binary(&AdminNominationResponse { nomination }) } -pub fn query_config(deps: Deps) -> StdResult { - let config = CONFIG.load(deps.storage)?; +pub fn query_config(storage: &dyn Storage) -> StdResult { + let config = CONFIG.load(storage)?; to_binary(&config) } -pub fn query_voting_module(deps: Deps) -> StdResult { - let voting_module = VOTING_MODULE.load(deps.storage)?; +pub fn query_voting_module(storage: &dyn Storage) -> StdResult { + let voting_module = VOTING_MODULE.load(storage)?; to_binary(&voting_module) } @@ -654,8 +660,8 @@ pub fn query_active_proposal_modules( ) } -fn get_pause_info(deps: Deps, env: Env) -> StdResult { - Ok(match PAUSED.may_load(deps.storage)? { +fn get_pause_info(storage: &dyn Storage, env: Env) -> StdResult { + Ok(match PAUSED.may_load(storage)? { Some(expiration) => { if expiration.is_expired(&env.block) { PauseInfoResponse::Unpaused {} @@ -667,22 +673,22 @@ fn get_pause_info(deps: Deps, env: Env) -> StdResult { }) } -pub fn query_paused(deps: Deps, env: Env) -> StdResult { - to_binary(&get_pause_info(deps, env)?) +pub fn query_paused(storage: &dyn Storage, env: Env) -> StdResult { + to_binary(&get_pause_info(storage, env)?) } -pub fn query_dump_state(deps: Deps, env: Env) -> StdResult { - 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 { + 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::>>()?; - 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, @@ -716,13 +722,13 @@ pub fn query_total_power_at_height(deps: Deps, height: Option) -> StdResult to_binary(&total_power) } -pub fn query_get_item(deps: Deps, item: String) -> StdResult { - let item = ITEMS.may_load(deps.storage, item)?; +pub fn query_get_item(storage: &dyn Storage, item: String) -> StdResult { + let item = ITEMS.may_load(storage, item)?; to_binary(&GetItemResponse { item }) } -pub fn query_info(deps: Deps) -> StdResult { - let info = cw2::get_contract_version(deps.storage)?; +pub fn query_info(storage: &dyn Storage) -> StdResult { + let info = cw2::get_contract_version(storage)?; to_binary(&dao_interface::voting::InfoResponse { info }) } @@ -732,7 +738,7 @@ pub fn query_list_items( limit: Option, ) -> StdResult { to_binary(&paginate_map( - deps, + deps.storage, &ITEMS, start_after, limit, @@ -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, @@ -833,8 +839,8 @@ pub fn query_list_sub_daos( to_binary(&subdaos) } -pub fn query_dao_uri(deps: Deps) -> StdResult { - let config = CONFIG.load(deps.storage)?; +pub fn query_dao_uri(storage: &dyn Storage) -> StdResult { + let config = CONFIG.load(storage)?; to_binary(&DaoURIResponse { dao_uri: config.dao_uri, }) diff --git a/contracts/external/cw-fund-distributor/src/contract.rs b/contracts/external/cw-fund-distributor/src/contract.rs index 2e5d4b2d1..1d3ed82d4 100644 --- a/contracts/external/cw-fund-distributor/src/contract.rs +++ b/contracts/external/cw-fund-distributor/src/contract.rs @@ -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; @@ -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 { 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) } @@ -403,22 +403,22 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { } } -pub fn query_voting_contract(deps: Deps) -> StdResult { - let contract = VOTING_CONTRACT.load(deps.storage)?; - let distribution_height = DISTRIBUTION_HEIGHT.load(deps.storage)?; +pub fn query_voting_contract(storage: &dyn Storage) -> StdResult { + 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 { - let total_power: Uint128 = TOTAL_POWER.may_load(deps.storage)?.unwrap_or_default(); +pub fn query_total_power(storage: &dyn Storage) -> StdResult { + 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 { - let native_balances = NATIVE_BALANCES.range(deps.storage, None, None, Order::Ascending); +pub fn query_native_denoms(storage: &dyn Storage) -> StdResult { + let native_balances = NATIVE_BALANCES.range(storage, None, None, Order::Ascending); let mut denom_responses: Vec = vec![]; for entry in native_balances { @@ -432,8 +432,8 @@ pub fn query_native_denoms(deps: Deps) -> StdResult { to_binary(&denom_responses) } -pub fn query_cw20_tokens(deps: Deps) -> StdResult { - let cw20_balances = CW20_BALANCES.range(deps.storage, None, None, Order::Ascending); +pub fn query_cw20_tokens(storage: &dyn Storage) -> StdResult { + let cw20_balances = CW20_BALANCES.range(storage, None, None, Order::Ascending); let mut cw20_responses: Vec = vec![]; for cw20 in cw20_balances { @@ -497,7 +497,13 @@ pub fn query_native_entitlements( ) -> StdResult { 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 = vec![]; for (denom, amount) in natives { @@ -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 = vec![]; for (token, amount) in cw20s { diff --git a/contracts/external/cw-token-swap/src/contract.rs b/contracts/external/cw-token-swap/src/contract.rs index 283ea5ac0..0da63ad34 100644 --- a/contracts/external/cw-token-swap/src/contract.rs +++ b/contracts/external/cw-token-swap/src/contract.rs @@ -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; @@ -232,13 +232,13 @@ pub fn execute_withdraw(deps: DepsMut, info: MessageInfo) -> Result StdResult { match msg { - QueryMsg::Status {} => query_status(deps), + QueryMsg::Status {} => query_status(deps.storage), } } -pub fn query_status(deps: Deps) -> StdResult { - let counterparty_one = COUNTERPARTY_ONE.load(deps.storage)?; - let counterparty_two = COUNTERPARTY_TWO.load(deps.storage)?; +pub fn query_status(storage: &dyn Storage) -> StdResult { + let counterparty_one = COUNTERPARTY_ONE.load(storage)?; + let counterparty_two = COUNTERPARTY_TWO.load(storage)?; to_binary(&StatusResponse { counterparty_one, diff --git a/contracts/external/cw-tokenfactory-issuer/src/contract.rs b/contracts/external/cw-tokenfactory-issuer/src/contract.rs index 144486cb2..4c774e08b 100644 --- a/contracts/external/cw-tokenfactory-issuer/src/contract.rs +++ b/contracts/external/cw-tokenfactory-issuer/src/contract.rs @@ -145,9 +145,9 @@ pub fn sudo( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { 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)?) } diff --git a/contracts/external/cw-tokenfactory-issuer/src/queries.rs b/contracts/external/cw-tokenfactory-issuer/src/queries.rs index be3d4f14f..60607148f 100644 --- a/contracts/external/cw-tokenfactory-issuer/src/queries.rs +++ b/contracts/external/cw-tokenfactory-issuer/src/queries.rs @@ -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; @@ -16,18 +16,18 @@ use crate::state::{ const MAX_LIMIT: u32 = 30; const DEFAULT_LIMIT: u32 = 10; -pub fn query_denom(deps: Deps) -> StdResult { - let denom = DENOM.load(deps.storage)?; +pub fn query_denom(storage: &dyn Storage) -> StdResult { + let denom = DENOM.load(storage)?; Ok(DenomResponse { denom }) } -pub fn query_is_frozen(deps: Deps) -> StdResult { - let is_frozen = IS_FROZEN.load(deps.storage)?; +pub fn query_is_frozen(storage: &dyn Storage) -> StdResult { + let is_frozen = IS_FROZEN.load(storage)?; Ok(IsFrozenResponse { is_frozen }) } -pub fn query_owner(deps: Deps) -> StdResult { - let owner = OWNER.load(deps.storage)?; +pub fn query_owner(storage: &dyn Storage) -> StdResult { + let owner = OWNER.load(storage)?; Ok(OwnerResponse { address: owner.into_string(), }) diff --git a/contracts/proposal/dao-proposal-multiple/src/contract.rs b/contracts/proposal/dao-proposal-multiple/src/contract.rs index 35465ab50..12404096d 100644 --- a/contracts/proposal/dao-proposal-multiple/src/contract.rs +++ b/contracts/proposal/dao-proposal-multiple/src/contract.rs @@ -727,48 +727,48 @@ pub fn advance_proposal_id(store: &mut dyn Storage) -> StdResult { #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::Config {} => query_config(deps), - QueryMsg::Proposal { proposal_id } => query_proposal(deps, env, proposal_id), + QueryMsg::Config {} => query_config(deps.storage), + QueryMsg::Proposal { proposal_id } => query_proposal(deps.storage, env, proposal_id), QueryMsg::ListProposals { start_after, limit } => { query_list_proposals(deps, env, start_after, limit) } - QueryMsg::NextProposalId {} => query_next_proposal_id(deps), - QueryMsg::ProposalCount {} => query_proposal_count(deps), + QueryMsg::NextProposalId {} => query_next_proposal_id(deps.storage), + QueryMsg::ProposalCount {} => query_proposal_count(deps.storage), QueryMsg::GetVote { proposal_id, voter } => query_vote(deps, proposal_id, voter), QueryMsg::ListVotes { proposal_id, start_after, limit, } => query_list_votes(deps, proposal_id, start_after, limit), - QueryMsg::Info {} => query_info(deps), + QueryMsg::Info {} => query_info(deps.storage), QueryMsg::ReverseProposals { start_before, limit, } => query_reverse_proposals(deps, env, start_before, limit), - QueryMsg::ProposalCreationPolicy {} => query_creation_policy(deps), - QueryMsg::ProposalHooks {} => to_binary(&PROPOSAL_HOOKS.query_hooks(deps)?), - QueryMsg::VoteHooks {} => to_binary(&VOTE_HOOKS.query_hooks(deps)?), - QueryMsg::Dao {} => query_dao(deps), + QueryMsg::ProposalCreationPolicy {} => query_creation_policy(deps.storage), + QueryMsg::ProposalHooks {} => to_binary(&PROPOSAL_HOOKS.query_hooks(deps.storage)?), + QueryMsg::VoteHooks {} => to_binary(&VOTE_HOOKS.query_hooks(deps.storage)?), + QueryMsg::Dao {} => query_dao(deps.storage), } } -pub fn query_config(deps: Deps) -> StdResult { - let config = CONFIG.load(deps.storage)?; +pub fn query_config(storage: &dyn Storage) -> StdResult { + let config = CONFIG.load(storage)?; to_binary(&config) } -pub fn query_dao(deps: Deps) -> StdResult { - let config = CONFIG.load(deps.storage)?; +pub fn query_dao(storage: &dyn Storage) -> StdResult { + let config = CONFIG.load(storage)?; to_binary(&config.dao) } -pub fn query_proposal(deps: Deps, env: Env, id: u64) -> StdResult { - let proposal = PROPOSALS.load(deps.storage, id)?; +pub fn query_proposal(storage: &dyn Storage, env: Env, id: u64) -> StdResult { + let proposal = PROPOSALS.load(storage, id)?; to_binary(&proposal.into_response(&env.block, id)?) } -pub fn query_creation_policy(deps: Deps) -> StdResult { - let policy = CREATION_POLICY.load(deps.storage)?; +pub fn query_creation_policy(storage: &dyn Storage) -> StdResult { + let policy = CREATION_POLICY.load(storage)?; to_binary(&policy) } @@ -810,12 +810,12 @@ pub fn query_reverse_proposals( to_binary(&ProposalListResponse { proposals: props }) } -pub fn query_next_proposal_id(deps: Deps) -> StdResult { - to_binary(&next_proposal_id(deps.storage)?) +pub fn query_next_proposal_id(storage: &dyn Storage) -> StdResult { + to_binary(&next_proposal_id(storage)?) } -pub fn query_proposal_count(deps: Deps) -> StdResult { - let proposal_count = PROPOSAL_COUNT.load(deps.storage)?; +pub fn query_proposal_count(storage: &dyn Storage) -> StdResult { + let proposal_count = PROPOSAL_COUNT.load(storage)?; to_binary(&proposal_count) } @@ -861,8 +861,8 @@ pub fn query_list_votes( to_binary(&VoteListResponse { votes }) } -pub fn query_info(deps: Deps) -> StdResult { - let info = cw2::get_contract_version(deps.storage)?; +pub fn query_info(storage: &dyn Storage) -> StdResult { + let info = cw2::get_contract_version(storage)?; to_binary(&dao_interface::voting::InfoResponse { info }) } diff --git a/contracts/proposal/dao-proposal-single/src/contract.rs b/contracts/proposal/dao-proposal-single/src/contract.rs index 5f30030f5..2b821e059 100644 --- a/contracts/proposal/dao-proposal-single/src/contract.rs +++ b/contracts/proposal/dao-proposal-single/src/contract.rs @@ -710,48 +710,48 @@ pub fn execute_remove_vote_hook( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::Config {} => query_config(deps), - QueryMsg::Dao {} => query_dao(deps), - QueryMsg::Proposal { proposal_id } => query_proposal(deps, env, proposal_id), + QueryMsg::Config {} => query_config(deps.storage), + QueryMsg::Dao {} => query_dao(deps.storage), + QueryMsg::Proposal { proposal_id } => query_proposal(deps.storage, env, proposal_id), QueryMsg::ListProposals { start_after, limit } => { query_list_proposals(deps, env, start_after, limit) } - QueryMsg::NextProposalId {} => query_next_proposal_id(deps), - QueryMsg::ProposalCount {} => query_proposal_count(deps), + QueryMsg::NextProposalId {} => query_next_proposal_id(deps.storage), + QueryMsg::ProposalCount {} => query_proposal_count(deps.storage), QueryMsg::GetVote { proposal_id, voter } => query_vote(deps, proposal_id, voter), QueryMsg::ListVotes { proposal_id, start_after, limit, } => query_list_votes(deps, proposal_id, start_after, limit), - QueryMsg::Info {} => query_info(deps), + QueryMsg::Info {} => query_info(deps.storage), QueryMsg::ReverseProposals { start_before, limit, } => query_reverse_proposals(deps, env, start_before, limit), - QueryMsg::ProposalCreationPolicy {} => query_creation_policy(deps), - QueryMsg::ProposalHooks {} => to_binary(&PROPOSAL_HOOKS.query_hooks(deps)?), - QueryMsg::VoteHooks {} => to_binary(&VOTE_HOOKS.query_hooks(deps)?), + QueryMsg::ProposalCreationPolicy {} => query_creation_policy(deps.storage), + QueryMsg::ProposalHooks {} => to_binary(&PROPOSAL_HOOKS.query_hooks(deps.storage)?), + QueryMsg::VoteHooks {} => to_binary(&VOTE_HOOKS.query_hooks(deps.storage)?), } } -pub fn query_config(deps: Deps) -> StdResult { - let config = CONFIG.load(deps.storage)?; +pub fn query_config(storage: &dyn Storage) -> StdResult { + let config = CONFIG.load(storage)?; to_binary(&config) } -pub fn query_dao(deps: Deps) -> StdResult { - let config = CONFIG.load(deps.storage)?; +pub fn query_dao(storage: &dyn Storage) -> StdResult { + let config = CONFIG.load(storage)?; to_binary(&config.dao) } -pub fn query_proposal(deps: Deps, env: Env, id: u64) -> StdResult { - let proposal = PROPOSALS.load(deps.storage, id)?; +pub fn query_proposal(storage: &dyn Storage, env: Env, id: u64) -> StdResult { + let proposal = PROPOSALS.load(storage, id)?; to_binary(&proposal.into_response(&env.block, id)) } -pub fn query_creation_policy(deps: Deps) -> StdResult { - let policy = CREATION_POLICY.load(deps.storage)?; +pub fn query_creation_policy(storage: &dyn Storage) -> StdResult { + let policy = CREATION_POLICY.load(storage)?; to_binary(&policy) } @@ -793,13 +793,13 @@ pub fn query_reverse_proposals( to_binary(&ProposalListResponse { proposals: props }) } -pub fn query_proposal_count(deps: Deps) -> StdResult { - let proposal_count = PROPOSAL_COUNT.load(deps.storage)?; +pub fn query_proposal_count(storage: &dyn Storage) -> StdResult { + let proposal_count = PROPOSAL_COUNT.load(storage)?; to_binary(&proposal_count) } -pub fn query_next_proposal_id(deps: Deps) -> StdResult { - to_binary(&next_proposal_id(deps.storage)?) +pub fn query_next_proposal_id(storage: &dyn Storage) -> StdResult { + to_binary(&next_proposal_id(storage)?) } pub fn query_vote(deps: Deps, proposal_id: u64, voter: String) -> StdResult { @@ -844,8 +844,8 @@ pub fn query_list_votes( to_binary(&VoteListResponse { votes }) } -pub fn query_info(deps: Deps) -> StdResult { - let info = cw2::get_contract_version(deps.storage)?; +pub fn query_info(storage: &dyn Storage) -> StdResult { + let info = cw2::get_contract_version(storage)?; to_binary(&dao_interface::voting::InfoResponse { info }) } diff --git a/contracts/staking/cw20-stake-external-rewards/src/contract.rs b/contracts/staking/cw20-stake-external-rewards/src/contract.rs index a2a50412d..669f79807 100644 --- a/contracts/staking/cw20-stake-external-rewards/src/contract.rs +++ b/contracts/staking/cw20-stake-external-rewards/src/contract.rs @@ -15,7 +15,7 @@ use cosmwasm_std::entry_point; use cosmwasm_std::{ from_binary, to_binary, Addr, BankMsg, Binary, Coin, CosmosMsg, Deps, DepsMut, Empty, Env, - MessageInfo, Response, StdError, StdResult, Uint128, Uint256, WasmMsg, + MessageInfo, Response, StdError, StdResult, Storage, Uint128, Uint256, WasmMsg, }; use cw2::{get_contract_version, set_contract_version, ContractVersion}; use cw20::{Cw20ReceiveMsg, Denom}; @@ -311,7 +311,7 @@ pub fn update_rewards(deps: &mut DepsMut, env: &Env, addr: &Addr) -> StdResult<( })?; USER_REWARD_PER_TOKEN.save(deps.storage, addr.clone(), &reward_per_token)?; - let last_time_reward_applicable = get_last_time_reward_applicable(deps.as_ref(), env)?; + let last_time_reward_applicable = get_last_time_reward_applicable(deps.storage, env)?; LAST_UPDATE_BLOCK.save(deps.storage, &last_time_reward_applicable)?; Ok(()) } @@ -319,7 +319,7 @@ pub fn update_rewards(deps: &mut DepsMut, env: &Env, addr: &Addr) -> StdResult<( pub fn get_reward_per_token(deps: Deps, env: &Env, staking_contract: &Addr) -> StdResult { let reward_config = REWARD_CONFIG.load(deps.storage)?; let total_staked = get_total_staked(deps, staking_contract)?; - let last_time_reward_applicable = get_last_time_reward_applicable(deps, env)?; + let last_time_reward_applicable = get_last_time_reward_applicable(deps.storage, env)?; let last_update_block = LAST_UPDATE_BLOCK.load(deps.storage).unwrap_or_default(); let prev_reward_per_token = REWARD_PER_TOKEN.load(deps.storage).unwrap_or_default(); let additional_reward_per_token = if total_staked == Uint128::zero() { @@ -359,8 +359,8 @@ pub fn get_rewards_earned( .try_into()?) } -fn get_last_time_reward_applicable(deps: Deps, env: &Env) -> StdResult { - let reward_config = REWARD_CONFIG.load(deps.storage)?; +fn get_last_time_reward_applicable(storage: &dyn Storage, env: &Env) -> StdResult { + let reward_config = REWARD_CONFIG.load(storage)?; Ok(min(env.block.height, reward_config.period_finish)) } @@ -414,7 +414,7 @@ fn scale_factor() -> Uint256 { #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::Info {} => Ok(to_binary(&query_info(deps, env)?)?), + QueryMsg::Info {} => Ok(to_binary(&query_info(deps.storage, env)?)?), QueryMsg::GetPendingRewards { address } => { Ok(to_binary(&query_pending_rewards(deps, env, address)?)?) } @@ -422,9 +422,9 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { } } -pub fn query_info(deps: Deps, _env: Env) -> StdResult { - let config = CONFIG.load(deps.storage)?; - let reward = REWARD_CONFIG.load(deps.storage)?; +pub fn query_info(storage: &dyn Storage, _env: Env) -> StdResult { + let config = CONFIG.load(storage)?; + let reward = REWARD_CONFIG.load(storage)?; Ok(InfoResponse { config, reward }) } diff --git a/contracts/staking/cw20-stake/src/contract.rs b/contracts/staking/cw20-stake/src/contract.rs index d25417f87..b0fb16615 100644 --- a/contracts/staking/cw20-stake/src/contract.rs +++ b/contracts/staking/cw20-stake/src/contract.rs @@ -3,7 +3,7 @@ use cosmwasm_std::entry_point; use cosmwasm_std::{ from_binary, to_binary, Addr, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response, - StdError, StdResult, Uint128, + StdError, StdResult, Storage, Uint128, }; use cw20::{Cw20ReceiveMsg, TokenInfoResponse}; @@ -354,7 +354,7 @@ pub fn execute_update_owner( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::GetConfig {} => to_binary(&query_config(deps)?), + QueryMsg::GetConfig {} => to_binary(&query_config(deps.storage)?), QueryMsg::StakedBalanceAtHeight { address, height } => { to_binary(&query_staked_balance_at_height(deps, env, address, height)?) } @@ -362,7 +362,7 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { to_binary(&query_total_staked_at_height(deps, env, height)?) } QueryMsg::StakedValue { address } => to_binary(&query_staked_value(deps, env, address)?), - QueryMsg::TotalValue {} => to_binary(&query_total_value(deps, env)?), + QueryMsg::TotalValue {} => to_binary(&query_total_value(deps.storage, env)?), QueryMsg::Claims { address } => to_binary(&query_claims(deps, address)?), QueryMsg::GetHooks {} => to_binary(&query_hooks(deps)?), QueryMsg::ListStakers { start_after, limit } => { @@ -423,13 +423,13 @@ pub fn query_staked_value( } } -pub fn query_total_value(deps: Deps, _env: Env) -> StdResult { - let balance = BALANCE.load(deps.storage)?; +pub fn query_total_value(storage: &dyn Storage, _env: Env) -> StdResult { + let balance = BALANCE.load(storage)?; Ok(TotalValueResponse { total: balance }) } -pub fn query_config(deps: Deps) -> StdResult { - let config = CONFIG.load(deps.storage)?; +pub fn query_config(storage: &dyn Storage) -> StdResult { + let config = CONFIG.load(storage)?; Ok(config) } diff --git a/contracts/voting/dao-voting-cw20-staked/src/contract.rs b/contracts/voting/dao-voting-cw20-staked/src/contract.rs index 4033d5247..2f1ec86d6 100644 --- a/contracts/voting/dao-voting-cw20-staked/src/contract.rs +++ b/contracts/voting/dao-voting-cw20-staked/src/contract.rs @@ -2,7 +2,7 @@ use cosmwasm_std::entry_point; use cosmwasm_std::{ to_binary, Addr, Binary, Decimal, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult, - SubMsg, Uint128, Uint256, WasmMsg, + Storage, SubMsg, Uint128, Uint256, WasmMsg, }; use cw2::set_contract_version; use cw20::{Cw20Coin, TokenInfoResponse}; @@ -230,26 +230,26 @@ pub fn execute_update_active_threshold( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::TokenContract {} => query_token_contract(deps), - QueryMsg::StakingContract {} => query_staking_contract(deps), + QueryMsg::TokenContract {} => query_token_contract(deps.storage), + QueryMsg::StakingContract {} => query_staking_contract(deps.storage), QueryMsg::VotingPowerAtHeight { address, height } => { query_voting_power_at_height(deps, env, address, height) } QueryMsg::TotalPowerAtHeight { height } => query_total_power_at_height(deps, env, height), - QueryMsg::Info {} => query_info(deps), - QueryMsg::Dao {} => query_dao(deps), + QueryMsg::Info {} => query_info(deps.storage), + QueryMsg::Dao {} => query_dao(deps.storage), QueryMsg::IsActive {} => query_is_active(deps), QueryMsg::ActiveThreshold {} => query_active_threshold(deps), } } -pub fn query_token_contract(deps: Deps) -> StdResult { - let token = TOKEN.load(deps.storage)?; +pub fn query_token_contract(storage: &dyn Storage) -> StdResult { + let token = TOKEN.load(storage)?; to_binary(&token) } -pub fn query_staking_contract(deps: Deps) -> StdResult { - let staking_contract = STAKING_CONTRACT.load(deps.storage)?; +pub fn query_staking_contract(storage: &dyn Storage) -> StdResult { + let staking_contract = STAKING_CONTRACT.load(storage)?; to_binary(&staking_contract) } @@ -290,13 +290,13 @@ pub fn query_total_power_at_height( }) } -pub fn query_info(deps: Deps) -> StdResult { - let info = cw2::get_contract_version(deps.storage)?; +pub fn query_info(storage: &dyn Storage) -> StdResult { + let info = cw2::get_contract_version(storage)?; to_binary(&dao_interface::voting::InfoResponse { info }) } -pub fn query_dao(deps: Deps) -> StdResult { - let dao = DAO.load(deps.storage)?; +pub fn query_dao(storage: &dyn Storage) -> StdResult { + let dao = DAO.load(storage)?; to_binary(&dao) } diff --git a/contracts/voting/dao-voting-cw4/src/contract.rs b/contracts/voting/dao-voting-cw4/src/contract.rs index efa311007..c761cb9ef 100644 --- a/contracts/voting/dao-voting-cw4/src/contract.rs +++ b/contracts/voting/dao-voting-cw4/src/contract.rs @@ -1,8 +1,8 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult, SubMsg, - Uint128, WasmMsg, + to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult, Storage, + SubMsg, Uint128, WasmMsg, }; use cw2::set_contract_version; use cw4::{MemberListResponse, MemberResponse, TotalWeightResponse}; @@ -121,7 +121,7 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { query_voting_power_at_height(deps, env, address, height) } QueryMsg::TotalPowerAtHeight { height } => query_total_power_at_height(deps, env, height), - QueryMsg::Info {} => query_info(deps), + QueryMsg::Info {} => query_info(deps.storage), QueryMsg::GroupContract {} => to_binary(&GROUP_CONTRACT.load(deps.storage)?), QueryMsg::Dao {} => to_binary(&DAO.load(deps.storage)?), } @@ -161,8 +161,8 @@ pub fn query_total_power_at_height(deps: Deps, env: Env, height: Option) -> }) } -pub fn query_info(deps: Deps) -> StdResult { - let info = cw2::get_contract_version(deps.storage)?; +pub fn query_info(storage: &dyn Storage) -> StdResult { + let info = cw2::get_contract_version(storage)?; to_binary(&dao_interface::voting::InfoResponse { info }) } diff --git a/contracts/voting/dao-voting-cw721-roles/src/contract.rs b/contracts/voting/dao-voting-cw721-roles/src/contract.rs index 62d6ba185..7dbdf7deb 100644 --- a/contracts/voting/dao-voting-cw721-roles/src/contract.rs +++ b/contracts/voting/dao-voting-cw721-roles/src/contract.rs @@ -1,8 +1,8 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Reply, Response, StdResult, SubMsg, - WasmMsg, + to_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Reply, Response, StdResult, Storage, + SubMsg, WasmMsg, }; use cw2::set_contract_version; use cw4::{MemberResponse, TotalWeightResponse}; @@ -94,13 +94,13 @@ pub fn execute( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::Config {} => query_config(deps), - QueryMsg::Dao {} => query_dao(deps), + QueryMsg::Config {} => query_config(deps.storage), + QueryMsg::Dao {} => query_dao(deps.storage), QueryMsg::VotingPowerAtHeight { address, height } => { query_voting_power_at_height(deps, env, address, height) } QueryMsg::TotalPowerAtHeight { height } => query_total_power_at_height(deps, env, height), - QueryMsg::Info {} => query_info(deps), + QueryMsg::Info {} => query_info(deps.storage), } } @@ -146,18 +146,18 @@ pub fn query_total_power_at_height( }) } -pub fn query_config(deps: Deps) -> StdResult { - let config = CONFIG.load(deps.storage)?; +pub fn query_config(storage: &dyn Storage) -> StdResult { + let config = CONFIG.load(storage)?; to_binary(&config) } -pub fn query_dao(deps: Deps) -> StdResult { - let dao = DAO.load(deps.storage)?; +pub fn query_dao(storage: &dyn Storage) -> StdResult { + let dao = DAO.load(storage)?; to_binary(&dao) } -pub fn query_info(deps: Deps) -> StdResult { - let info = cw2::get_contract_version(deps.storage)?; +pub fn query_info(storage: &dyn Storage) -> StdResult { + let info = cw2::get_contract_version(storage)?; to_binary(&dao_interface::voting::InfoResponse { info }) } diff --git a/contracts/voting/dao-voting-cw721-staked/src/contract.rs b/contracts/voting/dao-voting-cw721-staked/src/contract.rs index 613edc917..d997f5f53 100644 --- a/contracts/voting/dao-voting-cw721-staked/src/contract.rs +++ b/contracts/voting/dao-voting-cw721-staked/src/contract.rs @@ -10,7 +10,7 @@ use cosmwasm_schema::cw_serde; use cosmwasm_std::entry_point; use cosmwasm_std::{ from_binary, to_binary, Addr, Binary, CosmosMsg, Decimal, Deps, DepsMut, Empty, Env, - MessageInfo, Reply, Response, StdError, StdResult, SubMsg, Uint128, Uint256, WasmMsg, + MessageInfo, Reply, Response, StdError, StdResult, Storage, SubMsg, Uint128, Uint256, WasmMsg, }; use cw2::set_contract_version; use cw721::{Cw721ReceiveMsg, NumTokensResponse}; @@ -457,9 +457,9 @@ pub fn execute_update_active_threshold( pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { match msg { QueryMsg::ActiveThreshold {} => query_active_threshold(deps), - QueryMsg::Config {} => query_config(deps), - QueryMsg::Dao {} => query_dao(deps), - QueryMsg::Info {} => query_info(deps), + QueryMsg::Config {} => query_config(deps.storage), + QueryMsg::Dao {} => query_dao(deps.storage), + QueryMsg::Info {} => query_info(deps.storage), QueryMsg::IsActive {} => query_is_active(deps, env), QueryMsg::NftClaims { address } => query_nft_claims(deps, address), QueryMsg::Hooks {} => query_hooks(deps), @@ -572,13 +572,13 @@ pub fn query_total_power_at_height(deps: Deps, env: Env, height: Option) -> to_binary(&dao_interface::voting::TotalPowerAtHeightResponse { power, height }) } -pub fn query_config(deps: Deps) -> StdResult { - let config = CONFIG.load(deps.storage)?; +pub fn query_config(storage: &dyn Storage) -> StdResult { + let config = CONFIG.load(storage)?; to_binary(&config) } -pub fn query_dao(deps: Deps) -> StdResult { - let dao = DAO.load(deps.storage)?; +pub fn query_dao(storage: &dyn Storage) -> StdResult { + let dao = DAO.load(storage)?; to_binary(&dao) } @@ -590,8 +590,8 @@ pub fn query_hooks(deps: Deps) -> StdResult { to_binary(&HOOKS.query_hooks(deps)?) } -pub fn query_info(deps: Deps) -> StdResult { - let info = cw2::get_contract_version(deps.storage)?; +pub fn query_info(storage: &dyn Storage) -> StdResult { + let info = cw2::get_contract_version(storage)?; to_binary(&dao_interface::voting::InfoResponse { info }) } diff --git a/contracts/voting/dao-voting-native-staked/src/contract.rs b/contracts/voting/dao-voting-native-staked/src/contract.rs index 80a413a9f..6c3404b42 100644 --- a/contracts/voting/dao-voting-native-staked/src/contract.rs +++ b/contracts/voting/dao-voting-native-staked/src/contract.rs @@ -2,7 +2,7 @@ use cosmwasm_std::entry_point; use cosmwasm_std::{ coins, to_binary, BankMsg, BankQuery, Binary, Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, - MessageInfo, Response, StdResult, Uint128, Uint256, + MessageInfo, Response, StdResult, Storage, Uint128, Uint256, }; use cw2::set_contract_version; use cw_controllers::ClaimsResponse; @@ -331,14 +331,14 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { QueryMsg::TotalPowerAtHeight { height } => { to_binary(&query_total_power_at_height(deps, env, height)?) } - QueryMsg::Info {} => query_info(deps), - QueryMsg::Dao {} => query_dao(deps), + QueryMsg::Info {} => query_info(deps.storage), + QueryMsg::Dao {} => query_dao(deps.storage), QueryMsg::Claims { address } => to_binary(&query_claims(deps, address)?), QueryMsg::GetConfig {} => to_binary(&CONFIG.load(deps.storage)?), QueryMsg::ListStakers { start_after, limit } => { query_list_stakers(deps, start_after, limit) } - QueryMsg::GetDenom {} => query_denom(deps), + QueryMsg::GetDenom {} => query_denom(deps.storage), QueryMsg::IsActive {} => query_is_active(deps), QueryMsg::ActiveThreshold {} => query_active_threshold(deps), QueryMsg::GetHooks {} => to_binary(&query_hooks(deps)?), @@ -371,18 +371,18 @@ pub fn query_total_power_at_height( Ok(TotalPowerAtHeightResponse { power, height }) } -pub fn query_info(deps: Deps) -> StdResult { - let info = cw2::get_contract_version(deps.storage)?; +pub fn query_info(storage: &dyn Storage) -> StdResult { + let info = cw2::get_contract_version(storage)?; to_binary(&dao_interface::voting::InfoResponse { info }) } -pub fn query_dao(deps: Deps) -> StdResult { - let dao = DAO.load(deps.storage)?; +pub fn query_dao(storage: &dyn Storage) -> StdResult { + let dao = DAO.load(storage)?; to_binary(&dao) } -pub fn query_denom(deps: Deps) -> StdResult { - let config = CONFIG.load(deps.storage)?; +pub fn query_denom(storage: &dyn Storage) -> StdResult { + let config = CONFIG.load(storage)?; to_binary(&DenomResponse { denom: config.denom, }) @@ -490,7 +490,7 @@ pub fn query_active_threshold(deps: Deps) -> StdResult { pub fn query_hooks(deps: Deps) -> StdResult { Ok(GetHooksResponse { - hooks: HOOKS.query_hooks(deps)?.hooks, + hooks: HOOKS.query_hooks(deps.storage)?.hooks, }) } diff --git a/contracts/voting/dao-voting-token-factory-staked/src/contract.rs b/contracts/voting/dao-voting-token-factory-staked/src/contract.rs index 60f8b8cb3..5042dc114 100644 --- a/contracts/voting/dao-voting-token-factory-staked/src/contract.rs +++ b/contracts/voting/dao-voting-token-factory-staked/src/contract.rs @@ -3,7 +3,7 @@ use cosmwasm_std::entry_point; use cosmwasm_std::{ coins, to_binary, BankMsg, BankQuery, Binary, Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, - MessageInfo, Order, Reply, Response, StdResult, SubMsg, Uint128, Uint256, WasmMsg, + MessageInfo, Order, Reply, Response, StdResult, Storage, SubMsg, Uint128, Uint256, WasmMsg, }; use cw2::set_contract_version; use cw_controllers::ClaimsResponse; @@ -397,8 +397,8 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResul QueryMsg::TotalPowerAtHeight { height } => { to_binary(&query_total_power_at_height(deps, env, height)?) } - QueryMsg::Info {} => query_info(deps), - QueryMsg::Dao {} => query_dao(deps), + QueryMsg::Info {} => query_info(deps.storage), + QueryMsg::Dao {} => query_dao(deps.storage), QueryMsg::Claims { address } => to_binary(&query_claims(deps, address)?), QueryMsg::GetConfig {} => to_binary(&CONFIG.load(deps.storage)?), QueryMsg::Denom {} => to_binary(&DenomResponse { @@ -408,8 +408,8 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResul query_list_stakers(deps, start_after, limit) } QueryMsg::IsActive {} => query_is_active(deps), - QueryMsg::ActiveThreshold {} => query_active_threshold(deps), - QueryMsg::GetHooks {} => to_binary(&query_hooks(deps)?), + QueryMsg::ActiveThreshold {} => query_active_threshold(deps.storage), + QueryMsg::GetHooks {} => to_binary(&query_hooks(deps.storage)?), QueryMsg::TokenContract {} => to_binary(&TOKEN_ISSUER_CONTRACT.load(deps.storage)?), } } @@ -440,13 +440,13 @@ pub fn query_total_power_at_height( Ok(TotalPowerAtHeightResponse { power, height }) } -pub fn query_info(deps: Deps) -> StdResult { - let info = cw2::get_contract_version(deps.storage)?; +pub fn query_info(storage: &dyn Storage) -> StdResult { + let info = cw2::get_contract_version(storage)?; to_binary(&dao_interface::voting::InfoResponse { info }) } -pub fn query_dao(deps: Deps) -> StdResult { - let dao = DAO.load(deps.storage)?; +pub fn query_dao(storage: &dyn Storage) -> StdResult { + let dao = DAO.load(storage)?; to_binary(&dao) } @@ -539,15 +539,15 @@ pub fn query_is_active(deps: Deps) -> StdResult { } } -pub fn query_active_threshold(deps: Deps) -> StdResult { +pub fn query_active_threshold(storage: &dyn Storage) -> StdResult { to_binary(&ActiveThresholdResponse { - active_threshold: ACTIVE_THRESHOLD.may_load(deps.storage)?, + active_threshold: ACTIVE_THRESHOLD.may_load(storage)?, }) } -pub fn query_hooks(deps: Deps) -> StdResult { +pub fn query_hooks(storage: &dyn Storage) -> StdResult { Ok(GetHooksResponse { - hooks: HOOKS.query_hooks(deps)?.hooks, + hooks: HOOKS.query_hooks(storage)?.hooks, }) } diff --git a/packages/cw-hooks/src/lib.rs b/packages/cw-hooks/src/lib.rs index fdbf43577..a756f07dd 100644 --- a/packages/cw-hooks/src/lib.rs +++ b/packages/cw-hooks/src/lib.rs @@ -3,7 +3,7 @@ use thiserror::Error; use cosmwasm_schema::cw_serde; -use cosmwasm_std::{Addr, CustomQuery, Deps, StdError, StdResult, Storage, SubMsg}; +use cosmwasm_std::{Addr, StdError, StdResult, Storage, SubMsg}; use cw_storage_plus::Item; #[cw_serde] @@ -97,8 +97,8 @@ impl<'a> Hooks<'a> { Ok(self.0.may_load(storage)?.unwrap_or_default().len() as u32) } - pub fn query_hooks(&self, deps: Deps) -> StdResult { - let hooks = self.0.may_load(deps.storage)?.unwrap_or_default(); + pub fn query_hooks(&self, storage: &dyn Storage) -> StdResult { + let hooks = self.0.may_load(storage)?.unwrap_or_default(); let hooks = hooks.into_iter().map(String::from).collect(); Ok(HooksResponse { hooks }) } @@ -190,14 +190,14 @@ mod tests { ); // Query hooks returns all hooks added - let HooksResponse { hooks: the_hooks } = hooks.query_hooks(deps.as_ref()).unwrap(); + let HooksResponse { hooks: the_hooks } = hooks.query_hooks(&deps.storage).unwrap(); assert_eq!(the_hooks, vec![addr!("meow")]); // Remove last hook hooks.remove_hook(&mut deps.storage, addr!("meow")).unwrap(); // Query hooks returns empty vector if no hooks added - let HooksResponse { hooks: the_hooks } = hooks.query_hooks(deps.as_ref()).unwrap(); + let HooksResponse { hooks: the_hooks } = hooks.query_hooks(&deps.storage).unwrap(); let no_hooks: Vec = vec![]; assert_eq!(the_hooks, no_hooks); } diff --git a/packages/cw-paginate-storage/README.md b/packages/cw-paginate-storage/README.md index 03a9d03eb..6d4736377 100644 --- a/packages/cw-paginate-storage/README.md +++ b/packages/cw-paginate-storage/README.md @@ -20,7 +20,7 @@ You can use this package to write a query to list it's contents like: ```rust use cosmwasm_std::{Deps, Binary, to_binary, StdResult}; use cw_storage_plus::Map; -use cw_paginate_storage::paginate_map; +use cw_paginate_storage::paginate_map; pub const ITEMS: Map = Map::new("items"); @@ -30,7 +30,7 @@ pub fn query_list_items( limit: Option, ) -> StdResult { to_binary(&paginate_map( - deps, + deps.storage, &ITEMS, start_after, limit, diff --git a/packages/cw-paginate-storage/src/lib.rs b/packages/cw-paginate-storage/src/lib.rs index 66a0d046c..005b39fea 100644 --- a/packages/cw-paginate-storage/src/lib.rs +++ b/packages/cw-paginate-storage/src/lib.rs @@ -1,6 +1,6 @@ #![doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/README.md"))] -use cosmwasm_std::{Deps, Order, StdResult}; +use cosmwasm_std::{Deps, Order, StdResult, Storage}; #[allow(unused_imports)] use cw_storage_plus::{Bound, Bounder, KeyDeserialize, Map, SnapshotMap, Strategy}; @@ -8,7 +8,7 @@ use cw_storage_plus::{Bound, Bounder, KeyDeserialize, Map, SnapshotMap, Strategy /// Generic function for paginating a list of (K, V) pairs in a /// CosmWasm Map. pub fn paginate_map<'a, 'b, K, V, R: 'static>( - deps: Deps, + storage: &dyn Storage, map: &Map<'a, K, V>, start_after: Option, limit: Option, @@ -23,7 +23,7 @@ where Order::Descending => (None, start_after.map(Bound::exclusive)), }; - let items = map.range(deps.storage, range_min, range_max, order); + let items = map.range(storage, range_min, range_max, order); match limit { Some(limit) => Ok(items .take(limit.try_into().unwrap()) @@ -156,7 +156,7 @@ mod tests { .unwrap(); } - let items = paginate_map(deps.as_ref(), &map, None, None, Order::Descending).unwrap(); + let items = paginate_map(&deps.storage, &map, None, None, Order::Descending).unwrap(); assert_eq!( items, vec![ @@ -165,7 +165,7 @@ mod tests { ] ); - let items = paginate_map(deps.as_ref(), &map, None, None, Order::Ascending).unwrap(); + let items = paginate_map(&deps.storage, &map, None, None, Order::Ascending).unwrap(); assert_eq!( items, vec![ @@ -175,7 +175,7 @@ mod tests { ); let items = paginate_map( - deps.as_ref(), + &deps.storage, &map, Some("1".to_string()), None, @@ -184,7 +184,7 @@ mod tests { .unwrap(); assert_eq!(items, vec![("2".to_string(), "4".to_string())]); - let items = paginate_map(deps.as_ref(), &map, None, Some(1), Order::Ascending).unwrap(); + let items = paginate_map(&deps.storage, &map, None, Some(1), Order::Ascending).unwrap(); assert_eq!(items, vec![("1".to_string(), "2".to_string())]); } @@ -417,13 +417,13 @@ mod tests { map.save(&mut deps.storage, 4, &66).unwrap(); map.save(&mut deps.storage, 5, &0).unwrap(); - let items = paginate_map(deps.as_ref(), &map, None, None, Order::Descending).unwrap(); + let items = paginate_map(&deps.storage, &map, None, None, Order::Descending).unwrap(); assert_eq!(items, vec![(5, 0), (4, 66), (3, 77), (2, 22), (1, 40)]); - let items = paginate_map(deps.as_ref(), &map, Some(3), None, Order::Descending).unwrap(); + let items = paginate_map(&deps.storage, &map, Some(3), None, Order::Descending).unwrap(); assert_eq!(items, vec![(2, 22), (1, 40)]); - let items = paginate_map(deps.as_ref(), &map, Some(1), None, Order::Descending).unwrap(); + let items = paginate_map(&deps.storage, &map, Some(1), None, Order::Descending).unwrap(); assert_eq!(items, vec![]); } @@ -515,7 +515,7 @@ mod tests { ) .unwrap(); - let items = paginate_map(deps.as_ref(), &map, None, None, Order::Descending).unwrap(); + let items = paginate_map(&deps.storage, &map, None, None, Order::Descending).unwrap(); assert_eq!( items[1], (Addr::unchecked(format!("test_addr{:0>3}", 4)), 66) @@ -527,7 +527,7 @@ mod tests { let addr: Addr = Addr::unchecked(format!("test_addr{:0>3}", 3)); let items = - paginate_map(deps.as_ref(), &map, Some(&addr), Some(2), Order::Ascending).unwrap(); + paginate_map(&deps.storage, &map, Some(&addr), Some(2), Order::Ascending).unwrap(); let test_vec: Vec<(Addr, u32)> = vec![ (Addr::unchecked(format!("test_addr{:0>3}", 4)), 66), (Addr::unchecked(format!("test_addr{:0>3}", 6)), 0), diff --git a/packages/dao-pre-propose-base/src/execute.rs b/packages/dao-pre-propose-base/src/execute.rs index 225a465fe..2d8f021a7 100644 --- a/packages/dao-pre-propose-base/src/execute.rs +++ b/packages/dao-pre-propose-base/src/execute.rs @@ -360,7 +360,7 @@ where }) } QueryMsg::ProposalSubmittedHooks {} => { - to_binary(&self.proposal_submitted_hooks.query_hooks(deps)?) + to_binary(&self.proposal_submitted_hooks.query_hooks(deps.storage)?) } QueryMsg::QueryExtension { .. } => Ok(Binary::default()), } diff --git a/test-contracts/dao-proposal-sudo/src/contract.rs b/test-contracts/dao-proposal-sudo/src/contract.rs index 82df228e3..7f9bae2f2 100644 --- a/test-contracts/dao-proposal-sudo/src/contract.rs +++ b/test-contracts/dao-proposal-sudo/src/contract.rs @@ -2,7 +2,7 @@ use cosmwasm_std::entry_point; use cosmwasm_std::{ to_binary, Addr, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, StdResult, - WasmMsg, + Storage, WasmMsg, }; use cw2::set_contract_version; @@ -71,21 +71,21 @@ pub fn execute_execute( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::Admin {} => query_admin(deps), - QueryMsg::Dao {} => query_dao(deps), - QueryMsg::Info {} => query_info(deps), + QueryMsg::Admin {} => query_admin(deps.storage), + QueryMsg::Dao {} => query_dao(deps.storage), + QueryMsg::Info {} => query_info(deps.storage), } } -pub fn query_admin(deps: Deps) -> StdResult { - to_binary(&ROOT.load(deps.storage)?) +pub fn query_admin(storage: &dyn Storage) -> StdResult { + to_binary(&ROOT.load(storage)?) } -pub fn query_dao(deps: Deps) -> StdResult { - to_binary(&DAO.load(deps.storage)?) +pub fn query_dao(storage: &dyn Storage) -> StdResult { + to_binary(&DAO.load(storage)?) } -pub fn query_info(deps: Deps) -> StdResult { - let info = cw2::get_contract_version(deps.storage)?; +pub fn query_info(storage: &dyn Storage) -> StdResult { + let info = cw2::get_contract_version(storage)?; to_binary(&dao_interface::voting::InfoResponse { info }) } diff --git a/test-contracts/dao-voting-cw20-balance/src/contract.rs b/test-contracts/dao-voting-cw20-balance/src/contract.rs index 9c533568c..18fd8cbad 100644 --- a/test-contracts/dao-voting-cw20-balance/src/contract.rs +++ b/test-contracts/dao-voting-cw20-balance/src/contract.rs @@ -1,8 +1,8 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult, SubMsg, - Uint128, WasmMsg, + to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult, Storage, + SubMsg, Uint128, WasmMsg, }; use cw2::set_contract_version; use cw_utils::parse_reply_instantiate_data; @@ -92,23 +92,23 @@ pub fn execute( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::TokenContract {} => query_token_contract(deps), + QueryMsg::TokenContract {} => query_token_contract(deps.storage), QueryMsg::VotingPowerAtHeight { address, height: _ } => { query_voting_power_at_height(deps, env, address) } QueryMsg::TotalPowerAtHeight { height: _ } => query_total_power_at_height(deps, env), - QueryMsg::Info {} => query_info(deps), - QueryMsg::Dao {} => query_dao(deps), + QueryMsg::Info {} => query_info(deps.storage), + QueryMsg::Dao {} => query_dao(deps.storage), } } -pub fn query_dao(deps: Deps) -> StdResult { - let dao = DAO.load(deps.storage)?; +pub fn query_dao(storage: &dyn Storage) -> StdResult { + let dao = DAO.load(storage)?; to_binary(&dao) } -pub fn query_token_contract(deps: Deps) -> StdResult { - let token = TOKEN.load(deps.storage)?; +pub fn query_token_contract(storage: &dyn Storage) -> StdResult { + let token = TOKEN.load(storage)?; to_binary(&token) } @@ -138,8 +138,8 @@ pub fn query_total_power_at_height(deps: Deps, env: Env) -> StdResult { }) } -pub fn query_info(deps: Deps) -> StdResult { - let info = cw2::get_contract_version(deps.storage)?; +pub fn query_info(storage: &dyn Storage) -> StdResult { + let info = cw2::get_contract_version(storage)?; to_binary(&dao_interface::voting::InfoResponse { info }) }