Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions packages/std/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ extern "C" {

fn ed25519_sign(messages_ptr: u32, private_key_ptr: u32) -> u64;

fn check_gas() -> u64;

fn gas_evaporate(evaporate: u32) -> u32;
}

Expand Down Expand Up @@ -410,6 +412,15 @@ impl Api for ExternalApi {
}
}

fn check_gas(&self) -> StdResult<u64> {
let result = unsafe { check_gas() };
if result == 0 {
return Err(StdError::generic_err("check_gas error"));
}

Ok(result)
}

fn gas_evaporate(&self, evaporate: u32) -> StdResult<()> {
let result = unsafe { gas_evaporate(evaporate) };
if result != 0 {
Expand Down
4 changes: 4 additions & 0 deletions packages/std/src/testing/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ impl Api for MockApi {
Ok(cosmwasm_crypto::ed25519_sign(message, private_key)?)
}

fn check_gas(&self) -> StdResult<u64> {
Ok(0)
}

fn gas_evaporate(&self, _evaporate: u32) -> StdResult<()> {
Ok(())
}
Expand Down
9 changes: 7 additions & 2 deletions packages/std/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,15 @@ pub trait Api {
/// - private key: Raw ED25519 private key (32 bytes)
fn ed25519_sign(&self, message: &[u8], private_key: &[u8]) -> Result<Vec<u8>, SigningError>;

/// Check Gas.
///
/// This function will return the amount of gas currently used by the contract.
fn check_gas(&self) -> StdResult<u64>;

/// Gas evaporation.
///
///
/// This function will burn a evaporate a precise and reproducible amount of sdk gas.
///
///
/// - evaporate: Amount of SDK gas to evaporate.
fn gas_evaporate(&self, evaporate: u32) -> StdResult<()>;
}
Expand Down