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

Implement seal_rent_status #798

Merged
merged 5 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 6 additions & 2 deletions crates/env/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,19 @@ where

/// Returns information about the required deposit and resulting rent.
///
/// # Parameters
///
/// - `at_refcount`: The refcount assumed for the returned `custom_refcount_*` fields.
athei marked this conversation as resolved.
Show resolved Hide resolved
///
/// # Errors
///
/// If the returned value cannot be properly decoded.
pub fn rent_status<T>() -> Result<RentStatus<T>>
pub fn rent_status<T>(at_refcount: Option<u32>) -> Result<RentStatus<T>>
where
T: Environment,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnvBackend::rent_status::<T>(instance)
TypedEnvBackend::rent_status::<T>(instance, at_refcount)
})
}

Expand Down
5 changes: 4 additions & 1 deletion crates/env/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@ pub trait TypedEnvBackend: EnvBackend {
/// # Note
///
/// For more details visit: [`RentStatus`][`crate::RentStatus`]
fn rent_status<T: Environment>(&mut self) -> Result<RentStatus<T>>;
fn rent_status<T: Environment>(
&mut self,
at_refcount: Option<u32>,
) -> Result<RentStatus<T>>;

/// Returns the current block number.
///
Expand Down
2 changes: 1 addition & 1 deletion crates/env/src/engine/experimental_off_chain/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ impl TypedEnvBackend for EnvInstance {
unimplemented!("off-chain environment does not support rent params")
}

fn rent_status<T>(&mut self) -> Result<RentStatus<T>>
fn rent_status<T>(&mut self, _at_refcount: Option<u32>) -> Result<RentStatus<T>>
where
T: Environment,
{
Expand Down
2 changes: 1 addition & 1 deletion crates/env/src/engine/off_chain/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ impl TypedEnvBackend for EnvInstance {
})
}

fn rent_status<T>(&mut self) -> Result<RentStatus<T>>
fn rent_status<T>(&mut self, _at_refcount: Option<u32>) -> Result<RentStatus<T>>
where
T: Environment,
{
Expand Down
4 changes: 3 additions & 1 deletion crates/env/src/engine/on_chain/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ mod sys {
);

pub fn seal_rent_status(
at_refcount: Option<u32>,
output_ptr: Ptr32Mut<[u8]>,
output_len_ptr: Ptr32Mut<u32>,
);
Expand Down Expand Up @@ -615,11 +616,12 @@ pub fn rent_params(output: &mut &mut [u8]) {
extract_from_slice(output, output_len as usize);
}

pub fn rent_status(output: &mut &mut [u8]) {
pub fn rent_status(at_refcount: Option<u32>, output: &mut &mut [u8]) {
athei marked this conversation as resolved.
Show resolved Hide resolved
let mut output_len = output.len() as u32;
{
unsafe {
sys::seal_rent_status(
at_refcount.unwrap_or(0),
Ptr32Mut::from_slice(output),
Ptr32Mut::from_ref(&mut output_len),
)
Expand Down
6 changes: 4 additions & 2 deletions crates/env/src/engine/on_chain/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,13 @@ impl TypedEnvBackend for EnvInstance {
self.get_property::<RentParams<T>>(ext::rent_params)
}

fn rent_status<T>(&mut self) -> Result<RentStatus<T>>
fn rent_status<T>(&mut self, at_refcount: Option<u32>) -> Result<RentStatus<T>>
where
T: Environment,
{
self.get_property::<RentStatus<T>>(ext::rent_status)
let output = &mut self.scoped_buffer().take_rest();
ext::rent_status(at_refcount, output);
scale::Decode::decode(&mut &output[..]).map_err(Into::into)
}

fn invoke_contract<T, Args>(
Expand Down
9 changes: 7 additions & 2 deletions crates/lang/src/env_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,16 @@ where

/// Returns information about the required deposit and resulting rent.
///
/// # Parameters
///
/// - `at_refcount`: The refcount assumed for the returned `custom_refcount_*` fields.
///
/// # Note
///
/// For more details visit: [`ink_env::RentStatus`]
pub fn rent_status(self) -> RentStatus<T> {
ink_env::rent_status::<T>().expect("couldn't decode contract rent params")
pub fn rent_status(self, at_refcount: Option<u32>) -> RentStatus<T> {
ink_env::rent_status::<T>(at_refcount)
.expect("couldn't decode contract rent params")
}

/// Returns the current block number.
Expand Down