spacemeshos / svm

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

Extend SDK to expose `SigData` #453

Open YaronWittenstein opened 2 years ago

YaronWittenstein commented 2 years ago

Depends on: #441

So, once we've got the svm_tx_sigdata_range we need to expose it in the SDK. In practice we'll probably end up having two functions: svm_sigdata_offset and svm_sigdata_len (the rest of this issue description assumes that).

Here is an example of how it could look like:

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

The steps to implement this PR:

  1. Add to the Host trait under sdk-host the following:
pub trait Host {
    fn sigdata(&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_sigdata (very similar to the set_raw_calldata).

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

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

  fn svm_sigdata_len() -> u32;
}

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