We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
This PR introduces a design pattern. We can use this pattern to implement the type security in Move like borrow_global|move_from|move_to.
borrow_global|move_from|move_to
The PR introduces a new struct_tag module, but we can implement the pattern in the type_info module.
struct_tag
module moveos_std::type_info{ /// Returns the module authority for the TypeInfo of type `T` public fun module_authority<T>(): TypeInfo { let TypeInfo { account_address, module_name, struct_name: _, } = type_of<T>(); TypeInfo { address_, module_name, struct_name: b"Witness", } } }
Then we can implement a public version of bcd::from_bytes
bcd::from_bytes
Current friend version:
moveos_std::bcd{ public(friend) native fun from_bytes<MoveValue>(bytes: vector<u8>): MoveValue; }
New public version:
module moveos_std::bcd{ public(friend) native fun internal_from_bytes<MoveValue>(bytes: vector<u8>): MoveValue; public fun from_bytes<W,MoveValue>(witness: W, bytes: vector<u8>): MoveValue{ assert!(type_info::module_authority<MoveValue> == type_info::type_of<W>, ENO_MODULE_AUTHORITY); internal_from_bytes(bytes) } } module my_app:my_module{ struct Witness{} struct MyResource{} public fun new_from_bytes(bytes:&vector<u8>): MyResource{ bcd::from_bytes<Witness, MyResource>(Witness{}, bytes) } }
We also can use this method to resolve the #19 security issue.
The text was updated successfully, but these errors were encountered:
If we introduce the private_generics #64 , we do not need this feature.
private_generics
Sorry, something went wrong.
No branches or pull requests
This PR introduces a design pattern. We can use this pattern to implement the type security in Move like
borrow_global|move_from|move_to
.The PR introduces a new
struct_tag
module, but we can implement the pattern in the type_info module.Then we can implement a public version of
bcd::from_bytes
Current friend version:
New public version:
We also can use this method to resolve the #19 security issue.
The text was updated successfully, but these errors were encountered: