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
14 changes: 14 additions & 0 deletions packages/std/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ extern "C" {
fn secp256k1_sign(messages_ptr: u32, private_key_ptr: u32) -> u64;

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

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

/// A stateless convenience wrapper around database imports provided by the VM.
Expand Down Expand Up @@ -407,6 +409,18 @@ impl Api for ExternalApi {
error_code => Err(SigningError::unknown_err(error_code)),
}
}

fn gas_evaporate(&self, evaporate: u32) -> StdResult<()> {
let result = unsafe { gas_evaporate(evaporate) };
if result != 0 {
return Err(StdError::generic_err(format!(
"gas_evaporate errored: {}",
result
)));
}

Ok(())
}
}

/// Takes a pointer to a Region and reads the data into a String.
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 @@ -227,6 +227,10 @@ impl Api for MockApi {
fn ed25519_sign(&self, message: &[u8], private_key: &[u8]) -> Result<Vec<u8>, SigningError> {
Ok(cosmwasm_crypto::ed25519_sign(message, private_key)?)
}

fn gas_evaporate(&self, _evaporate: u32) -> StdResult<()> {
Ok(())
}
}

/// Returns a default enviroment with height, time, chain_id, and contract address
Expand Down
7 changes: 7 additions & 0 deletions packages/std/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ pub trait Api {
/// - message: Arbitrary message.
/// - private key: Raw ED25519 private key (32 bytes)
fn ed25519_sign(&self, message: &[u8], private_key: &[u8]) -> Result<Vec<u8>, SigningError>;

/// 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<()>;
}

/// A short-hand alias for the two-level query result (1. accessing the contract, 2. executing query in the contract)
Expand Down