Skip to content
This repository has been archived by the owner on Aug 14, 2023. It is now read-only.

Commit

Permalink
svm_layer_info
Browse files Browse the repository at this point in the history
  • Loading branch information
neysofu committed Nov 8, 2021
1 parent 0b9a2ff commit 811baf8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
13 changes: 9 additions & 4 deletions crates/runtime-ffi/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,15 +475,20 @@ pub unsafe extern "C" fn svm_call(
)
}

/// Writes the current state root hash at `hash`.
/// Writes the current state root hash at `hash` and the current layer at `layer`.
#[must_use]
#[no_mangle]
unsafe fn svm_state_hash(runtime_ptr: *mut c_void, hash: *mut u8) -> svm_result_t {
pub unsafe fn svm_layer_info(
runtime_ptr: *mut c_void,
hash: *mut u8,
layer: *mut u64,
) -> svm_result_t {
catch_unwind_or_fail(|| {
let runtime = get_runtime(runtime_ptr);
let root_hash = runtime.current_layer();
let (layer_id, state_hash) = runtime.current_layer();
let slice = slice::from_raw_parts_mut(hash, State::N);
slice.clone_from_slice(&root_hash.0);
slice.clone_from_slice(&state_hash.0);
*layer = layer_id.0;

svm_result_t::OK
})
Expand Down
7 changes: 3 additions & 4 deletions crates/runtime/src/runtime/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,9 @@ impl Runtime {
}
}

/// Returns the state root hash of the last layer.
pub fn current_layer(&mut self) -> State {
let (_layer, state) = self.gs.current_layer().unwrap();
state
/// Returns the state root hash and layer ID of the last layer.
pub fn current_layer(&mut self) -> (Layer, State) {
self.gs.current_layer().unwrap()
}

/// Increases the balance by a given amount associated with `account_addr`.
Expand Down

0 comments on commit 811baf8

Please sign in to comment.