2

プライベート変数をサブストレート ストレージに、具体的には次の形式で格納し、プライベート関数でそれらにアクセスすることは可能ですか?

#[derive(Encode, Decode, Default, Clone, PartialEq, Debug)]
pub struct MyStruct {
  id: Hash, // the `id` is public 
  // 1. Can this be a private variable not returned by API / to client?
  private_var: u64, 
}

decl_storage! {
  trait Store for Module<T: Trait> as MyModule {
    // 2. Can this be private storage used only within module function implementation, but cannot be called by API/client?
    PrivateStorage: u64 = 0; 
    PublicStruct: MyStruct;
  }
}

decl_module! { }

impl<T: Trait> Module<T> {
  fn _private_function() -> Result {
    //can access both private variable/storage
    let var1 = <PrivateStorage<T>>::get();
    let var2 = <MyStruct<T>>::get();
    if var2.private_var == 0 {
      // some more code
    }
    Ok(())
  }
}
4

1 に答える 1