here is my state:
pub struct State {
pub chunk_count: u128,
#[serde(skip, default = "init_chunk_stable_data")]
pub chunks: StableBTreeMap<u128, Chunk, StableMemory>,
pub asset_count: u128,
#[serde(skip, default = "init_asset_stable_data")]
pub assets: StableBTreeMap<u128, Asset, StableMemory>,
}
#[update]
#[candid_method(update)]
pub fn insert_chunk(){
STATE.with(|state|{
let mut state = state.borrow_mut();
for id in 0..100{
let chunk = Chunk{
content: [0; 2000].to_vec(),
order: 1,
owner: ic_cdk::id(),
created_at: ic_cdk::api::time(),
checksum: 200,
id: 10
};
state.chunks.insert(id, chunk);
}
})
}
#[update]
#[candid_method(update)]
pub fn insert_asset(){
STATE.with(|state|{
let mut state = state.borrow_mut();
for id in 0..100{
let asset = Asset{
content: [0; 4000].to_vec(),
file_name: "".into(),
owner: Principal::anonymous(),
content_encoding: ContentEncoding::GZIP,
url: "".to_string(),
id: 100,
content_type: "".into()
};
state.assets.insert(id, asset);
}
})
}
I’m only able to call one of them.
if I try to call both: I get the following error:
Call was rejected:
Request ID: 5d5009333fb8f2ef2934c896ea710f5125049452dbb145c44e339ebd50306125
Reject code: 5
Reject text: Canister bkyz2-fmaaa-aaaaa-qaaaq-cai trapped explicitly: Panicked at 'MemoryId(2): grow failed', /Users/pramitgaha/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ic-stable-structures-0.5.6/src/memory_manager.rs:351:17
I also had another function:
#[query]
#[candid_method(query)]
pub fn chunk_availability_check(ids: Vec<u128>) -> bool {
STATE.with(|state| {
let state = state.borrow();
for id in ids.iter() {
if let None = state.chunks.get(id){
return false
}
}
true
})
}
this function fails with error:
"IC0522: Canister bkyz2-fmaaa-aaaaa-qaaaq-cai exceeded the instruction limit for single message execution."