spacemeshos / svm

SVM - Spacemesh Virtual Machine
https://spacemesh.io
MIT License
85 stars 14 forks source link

Extend SDK to expose `Host::transaction` #444

Open YaronWittenstein opened 2 years ago

YaronWittenstein commented 2 years ago

Depends on: #437

So, once we've got the svm_tx_range up and running, we need to expose it in a nice manner in the SDK.

Here is an example of how it could look like:

let tx: &'static [u8] = Host::transaction();

The steps to implement this PR:

  1. Add to the Host trait under sdk-host the following:
pub trait Host {
    fn transaction(&self) -> &'static [u8]

    // ...
}

This is very similar to the currently existing calldata method: https://github.com/spacemeshos/svm/blob/6edb73de199fafce0953f82af061ca1090ff911c/crates/sdk-host/src/lib.rs#L13

  1. Extend the MockHost under the svm-host-mock crate to have both set_raw_tx (very similar to the set_raw_calldata). Seems we don't need to have a set_tx similar to the set_calldata

  2. Extend the svm-host-ffi crate to have:

#[link(wasm_import_module = "svm")]
extern "C" {
  fn svm_tx_offset() -> u32;

  fn svm_tx_len() -> u32;
}

Note that the declaration should match the ones used when implementing the host functions at #437 So if we ended up support only a single host function returning (u32, u32) then the svm-host-ffi should match that.