Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
feat: remove storage migration from Motoko to Rust (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpeterparker authored Nov 4, 2022
1 parent 6f03efb commit 6c155fa
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 159 deletions.
3 changes: 0 additions & 3 deletions canisters/src/storage/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,3 @@ pub static ADMIN: [&str; 2] = [
];

pub static MANAGER: [&str; 1] = ["kulzz-yaaaa-aaaal-aai3a-cai"];

// TODO: TODO: to be deleted
pub static MIGRATE_MOTOKO_STATE: bool = true;
54 changes: 0 additions & 54 deletions canisters/src/storage/src/impls_mo.rs

This file was deleted.

39 changes: 3 additions & 36 deletions canisters/src/storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@ mod constants;
mod env;
mod http;
mod impls;
mod impls_mo;
mod store;
mod types;
mod types_mo;
mod utils;

use candid::{decode_args, Principal};
use candid::Principal;
use ic_cdk::api::management_canister::main::{deposit_cycles, CanisterIdRecord};
use ic_cdk::api::{caller, canister_balance128, trap};
use ic_cdk::export::candid::{candid_method, export_service};
use ic_cdk::{api, storage};
use ic_cdk::storage;
use ic_cdk_macros::{init, post_upgrade, pre_upgrade, query, update};
use std::cell::RefCell;
use std::collections::HashMap;

use crate::cert::update_certified_data;
use crate::env::MIGRATE_MOTOKO_STATE;
use crate::http::{build_headers, create_token, streaming_strategy};
use crate::store::{
commit_batch, create_batch, create_chunk, delete_asset, get_asset, get_asset_for_url, get_keys,
Expand All @@ -29,9 +26,8 @@ use crate::types::http::{
HttpRequest, HttpResponse, StreamingCallbackHttpResponse, StreamingCallbackToken,
};
use crate::types::interface::{CommitBatch, Del, InitUpload, UploadChunk};
use crate::types::state::{Assets, RuntimeState, StableState, State};
use crate::types::state::{RuntimeState, StableState, State};
use crate::types::store::{Asset, AssetKey, Chunk};
use crate::types_mo::mo::state::MoState;
use crate::utils::{is_manager, principal_not_equal};

thread_local! {
Expand Down Expand Up @@ -82,35 +78,6 @@ fn post_upgrade() {
}

fn stable_state_to_upgrade() -> StableState {
if MIGRATE_MOTOKO_STATE {
// TODO: delete after migration from Motoko to Rust
// By senior.joinu - not all heroes wear capes
let mut stable_length_buf = [0u8; std::mem::size_of::<u32>()];
api::stable::stable_read(0, &mut stable_length_buf);
let stable_length = u32::from_le_bytes(stable_length_buf); // maybe use from_be_bytes, I don't remember what endianess is candid

let mut buf = vec![0u8; stable_length as usize];
api::stable::stable_read(std::mem::size_of::<u32>() as u32, &mut buf);

let (mo_state,): (MoState,) = decode_args(&buf).unwrap();

let user: Option<Principal> = mo_state.user.clone();

fn migrate_assets(MoState { entries, user: _ }: MoState) -> Assets {
match entries {
None => HashMap::new(),
Some(e) => e
.iter()
.map(|(key, mo_asset)| (key.clone(), Asset::from(mo_asset)))
.collect(),
}
}

let assets: Assets = migrate_assets(mo_state);

return StableState { user, assets };
}

let (stable,): (StableState,) = storage::stable_restore().unwrap();
stable
}
Expand Down
66 changes: 0 additions & 66 deletions canisters/src/storage/src/types_mo.rs

This file was deleted.

0 comments on commit 6c155fa

Please sign in to comment.