Build reverse allowances map during migration
#[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,
};
@@ -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";
@@ -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())
}
