-
Notifications
You must be signed in to change notification settings - Fork 141
Open
Labels
enhancementNew feature or requestNew feature or request
Description
🚀 Feature Request
Motivation
Currently, Move's structs use implicit visibility, e.g.
struct Foo{
f1: u64,
}is equivalent to.
public struct Foo{
private f1: u64,
}Also, an implicit global storage access restriction is used to ensure that a struct can only be borrowed in the module in which it is defined.
This is actually equivalent to a conditional visibility constraint and has the same effect as adding a private visibility constraint to the struct.
private struct Foo has key{
}So I propose to introduce the visibility of structs. This leaves it up to the smart contract developer to decide on access control for the global storage and the struct fields.
For example.
module MyModule {
public struct Foo has key{
public f1:u64,
}
private struct Bar has key{
f1:u64,
}
public fun do_some(){
let foo = borrow_global<Foo>();
let bar = borrow_global<Bar>();
// Both of these work
}
}
module XXX {
use MyModule::Foo;
public fun so_some(){
let foo = borrow_global<Foo>();
let f1 = foo.f1
let bar = borrow_global<Bar>();
// the first one will succeed, the second one will fail
}
}Of course, compatibility is a bigger problem, this is just an idea. If it works, I can do more work on it.
tnowacki and zekun000
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request