Skip to content

Commit

Permalink
Build reverse allowances map during migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauro Lacy committed Jul 25, 2022
1 parent 30e4a97 commit 5cdbbe9
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions contracts/cw20-base/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::Order::Ascending;
use cosmwasm_std::{
to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, Uint128,
};
Expand All @@ -17,7 +18,10 @@ use crate::allowances::{
use crate::enumerable::{query_all_accounts, query_owner_allowances, query_spender_allowances};
use crate::error::ContractError;
use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
use crate::state::{MinterData, TokenInfo, BALANCES, LOGO, MARKETING_INFO, TOKEN_INFO};
use crate::state::{
MinterData, TokenInfo, ALLOWANCES, ALLOWANCES_SPENDER, BALANCES, LOGO, MARKETING_INFO,
TOKEN_INFO,
};

// version info for migration info
const CONTRACT_NAME: &str = "crates.io:cw20-base";
Expand Down Expand Up @@ -598,7 +602,14 @@ pub fn query_download_logo(deps: Deps) -> StdResult<DownloadLogoResponse> {
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, ContractError> {
pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, ContractError> {
// Build reverse map of allowances per spender
let data = ALLOWANCES
.range(deps.storage, None, None, Ascending)
.collect::<StdResult<Vec<_>>>()?;
for ((owner, spender), allowance) in data {
ALLOWANCES_SPENDER.save(deps.storage, (&spender, &owner), &allowance)?;
}
Ok(Response::default())
}

Expand Down

0 comments on commit 5cdbbe9

Please sign in to comment.