Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle the return value of exports::storage_remove() #712

Merged
merged 5 commits into from
Mar 20, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions engine-sdk/src/near_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,20 @@ impl Runtime {
// Use register 0 as the destination for the promise.
let promise_id = exports::promise_batch_create(u64::MAX as _, 0);
// Remove code from storage and store it in register 1.
exports::storage_remove(code_key.len() as _, code_key.as_ptr() as _, 1);
exports::promise_batch_action_deploy_contract(promise_id, u64::MAX, 1);
Self::promise_batch_action_function_call(
promise_id,
b"state_migration",
&[],
0,
Self::GAS_FOR_STATE_MIGRATION.as_u64(),
)
// if the code_key exists call `promise_batch_action_deploy_contract`, otherwise panic with error.
match exports::storage_remove(code_key.len() as _, code_key.as_ptr() as _, 1) {
1 => {
exports::promise_batch_action_deploy_contract(promise_id, u64::MAX, 1);
Self::promise_batch_action_function_call(
promise_id,
b"state_migration",
&[],
0,
Self::GAS_FOR_STATE_MIGRATION.as_u64(),
)
}
_ => panic!("ERR_NO_CODE_STAGED"),
};
}
}

Expand Down