是否可以将私有变量存储在基板存储中,特别是以下形式并在私有函数中访问它们?
#[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(())
}
}