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

Burn functionality #4573

Merged
merged 30 commits into from
Mar 12, 2024
Merged

Conversation

hoffmannjan
Copy link
Contributor

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optimistic approval assuming asked for changes are made.

Copy link
Collaborator

@mpapierski mpapierski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, few tweaks

execution_engine/src/core/runtime/mint_internal.rs Outdated Show resolved Hide resolved
execution_engine/src/core/runtime_context/mod.rs Outdated Show resolved Hide resolved
execution_engine/src/shared/system_config/mint_costs.rs Outdated Show resolved Hide resolved
execution_engine/src/system/mint.rs Outdated Show resolved Hide resolved
Comment on lines 75 to 80
let data =
unsafe { Vec::from_raw_parts(data_non_null_ptr.as_ptr(), arg_size, arg_size) };
if ret != 0 {
return None;
}
data
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found an existing method that does the same thing in other test contracts, perhaps you can just copy and paste it from there:

fn get_named_arg_if_exists<T: FromBytes>(name: &str) -> Option<T> {
let arg_size = {
let mut arg_size: usize = 0;
let ret = unsafe {
ext_ffi::casper_get_named_arg_size(
name.as_bytes().as_ptr(),
name.len(),
&mut arg_size as *mut usize,
)
};
match api_error::result_from(ret) {
Ok(_) => Some(arg_size),
Err(ApiError::MissingArgument) => None,
Err(e) => runtime::revert(e),
}
}?;
let arg_bytes = if arg_size > 0 {
let res = {
let data_non_null_ptr = contract_api::alloc_bytes(arg_size);
let ret = unsafe {
ext_ffi::casper_get_named_arg(
name.as_bytes().as_ptr(),
name.len(),
data_non_null_ptr.as_ptr(),
arg_size,
)
};
let data =
unsafe { Vec::from_raw_parts(data_non_null_ptr.as_ptr(), arg_size, arg_size) };
api_error::result_from(ret).map(|_| data)
};
// Assumed to be safe as `get_named_arg_size` checks the argument already
res.unwrap_or_revert()
} else {
// Avoids allocation with 0 bytes and a call to get_named_arg
Vec::new()
};
let value = bytesrepr::deserialize(arg_bytes).unwrap_or_revert_with(ApiError::InvalidArgument);
Some(value)
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes...that's the one i was looking for a couple of weeks ago...couldn't remember which contract it was in

we should just add this to contract api...it's come up various times.

execution_engine/src/core/runtime/mint_internal.rs Outdated Show resolved Hide resolved
execution_engine/src/core/runtime/mod.rs Outdated Show resolved Hide resolved
@hoffmannjan hoffmannjan changed the base branch from dev to feat-1.6 March 5, 2024 15:41
Copy link
Collaborator

@mpapierski mpapierski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@marc-casperlabs
Copy link
Contributor

The networking related changes LGTM, too.

@hoffmannjan hoffmannjan merged commit 16bb5ef into casper-network:feat-1.6 Mar 12, 2024
2 checks passed
@hoffmannjan hoffmannjan deleted the feat-burning branch March 12, 2024 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants