Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9b70424

Browse files
committedApr 15, 2022
Cleanup migration
1 parent 5ccd48e commit 9b70424

File tree

1 file changed

+3
-85
lines changed

1 file changed

+3
-85
lines changed
 

‎contracts/mixnet/src/contract.rs

+3-85
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@ use crate::rewards::queries::{
3030
};
3131
use crate::rewards::storage as rewards_storage;
3232
use cosmwasm_std::{
33-
entry_point, to_binary, Addr, Deps, DepsMut, Env, MessageInfo, QueryResponse, Response,
34-
Storage, Uint128,
33+
entry_point, to_binary, Addr, Deps, DepsMut, Env, MessageInfo, QueryResponse, Response, Uint128,
3534
};
36-
use cw_storage_plus::PrimaryKey;
3735
use mixnet_contract_common::{
38-
ContractStateParams, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, SphinxKey,
36+
ContractStateParams, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg,
3937
};
4038
use time::OffsetDateTime;
4139

@@ -386,87 +384,7 @@ pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> Result<QueryResponse, C
386384
}
387385

388386
#[entry_point]
389-
pub fn migrate(deps: DepsMut<'_>, _env: Env, _msg: MigrateMsg) -> Result<Response, ContractError> {
390-
use crate::mixnodes::storage::StoredMixnodeBond;
391-
use cw_storage_plus::{Index, IndexList, IndexedSnapshotMap, Strategy, UniqueIndex};
392-
use mixnet_contract_common::{Addr, IdentityKeyRef};
393-
394-
const MIXNODES_PK_NAMESPACE: &str = "mn";
395-
const MIXNODES_PK_CHECKPOINTS: &str = "mn__check";
396-
const MIXNODES_PK_CHANGELOG: &str = "mn__change";
397-
const MIXNODES_OWNER_IDX_NAMESPACE: &str = "mno";
398-
const MIXNODES_SPHINX_IDX_NAMESPACE: &str = "mns";
399-
400-
pub(crate) struct MixnodeBondIndex<'a> {
401-
pub(crate) owner: UniqueIndex<'a, Addr, StoredMixnodeBond>,
402-
}
403-
404-
impl<'a> IndexList<StoredMixnodeBond> for MixnodeBondIndex<'a> {
405-
fn get_indexes(
406-
&'_ self,
407-
) -> Box<dyn Iterator<Item = &'_ dyn Index<StoredMixnodeBond>> + '_> {
408-
let v: Vec<&dyn Index<StoredMixnodeBond>> = vec![&self.owner];
409-
Box::new(v.into_iter())
410-
}
411-
}
412-
413-
pub(crate) fn old_mixnodes<'a>(
414-
) -> IndexedSnapshotMap<'a, IdentityKeyRef<'a>, StoredMixnodeBond, MixnodeBondIndex<'a>> {
415-
let indexes = MixnodeBondIndex {
416-
owner: UniqueIndex::new(|d| d.owner.clone(), MIXNODES_OWNER_IDX_NAMESPACE),
417-
};
418-
IndexedSnapshotMap::new(
419-
MIXNODES_PK_NAMESPACE,
420-
MIXNODES_PK_CHECKPOINTS,
421-
MIXNODES_PK_CHANGELOG,
422-
Strategy::Never,
423-
indexes,
424-
)
425-
}
426-
427-
const PAGE_SIZE: usize = 50;
428-
429-
fn migrate_page(
430-
store: &mut dyn Storage,
431-
start_after: Option<String>,
432-
index: &mut UniqueIndex<'_, SphinxKey, StoredMixnodeBond>,
433-
) -> Option<String> {
434-
let start = start_after
435-
.as_deref()
436-
.map(cw_storage_plus::Bound::exclusive);
437-
438-
let page: Vec<_> = old_mixnodes()
439-
.range(store, start, None, cosmwasm_std::Order::Ascending)
440-
.map(|v| v.expect("failed to deserialize stored mixnode"))
441-
.collect();
442-
443-
let last_pk = if page.len() == PAGE_SIZE {
444-
Some(page.last().unwrap().0.clone())
445-
} else {
446-
None
447-
};
448-
449-
for (pk, mix) in page {
450-
index
451-
.save(store, &pk.joined_key(), &mix)
452-
.expect("failed to save new index information");
453-
}
454-
455-
last_pk
456-
}
457-
458-
// attempt to just add indices, see how it works out
459-
let mut sphinx_index: UniqueIndex<'_, SphinxKey, StoredMixnodeBond> = UniqueIndex::new(
460-
|d| d.mix_node.sphinx_key.clone(),
461-
MIXNODES_SPHINX_IDX_NAMESPACE,
462-
);
463-
464-
let mut start_after = None;
465-
466-
while let Some(new_start) = migrate_page(deps.storage, start_after.clone(), &mut sphinx_index) {
467-
start_after = Some(new_start)
468-
}
469-
387+
pub fn migrate(_deps: DepsMut<'_>, _env: Env, _msg: MigrateMsg) -> Result<Response, ContractError> {
470388
Ok(Default::default())
471389
}
472390

0 commit comments

Comments
 (0)
Please sign in to comment.