spacemeshos / svm

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

Extend SDK Storage to support 32-byte and 64-byte variables #440

Open YaronWittenstein opened 2 years ago

YaronWittenstein commented 2 years ago

Depends on: #438

  1. Extend the Storage trait here: https://github.com/spacemeshos/svm/blob/master/crates/sdk-storage/src/lib.rs to have load256 / store256 and load512 / store512

  2. Implement under lib.rs:

pub fn load256<S: Storage>(var_id: u32) -> svm_sdk_types::Blob32 { ... }
pub fn load512<S: Storage>(var_id: u32) -> svm_sdk_types::Blob64 { ... }

pub fn store256<S: Storage>(var_id: u32, slice: &[u8]) { ... }
pub fn store512<S: Storage>(var_id: u32, slice: &[u8]) { ... }
  1. Re-expose new getters and setters under the svm-sdk crate: https://github.com/spacemeshos/svm/blob/6edb73de199fafce0953f82af061ca1090ff911c/crates/sdk/src/lib.rs#L351

  2. Extend the sdk-storage-mock crate to support the new functionality.

  3. Extend the sdk-storage-ffi crate to support the new functionality.

  4. Add to svm-macros crate: https://github.com/spacemeshos/svm/blob/6edb73de199fafce0953f82af061ca1090ff911c/crates/sdk-macros/src/struct/storage.rs#L152

match ty.as_str() {
  "Blob32" => ...,
  "Blob64" => ...,
}

And also extend this method: https://github.com/spacemeshos/svm/blob/6edb73de199fafce0953f82af061ca1090ff911c/crates/sdk-macros/src/struct/storage.rs#L267

with the following:

match ty.as_str() {
  "Blob32" => ...,
  "Blob64" => ...,
}
  1. Extend the field_byte_count https://github.com/spacemeshos/svm/blob/6edb73de199fafce0953f82af061ca1090ff911c/crates/sdk-macros/src/struct/storage.rs#L411
fn field_byte_count(ty: &PrimType) -> usize {
    match ty.as_str() {
      "svm_sdk :: Blob32" => 32,
      "svm_sdk :: Blob64" => 64
   }