forked from aptos-labs/aptos-core
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
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
[DON'T MERGE] Supra_container #113
Open
axiongsupra
wants to merge
5
commits into
vm_upgrade_branch
Choose a base branch
from
supra_container
base: vm_upgrade_branch
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
aptos-move/framework/supra-framework/sources/container.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
module supra_framework::container { | ||
|
||
use std::vector; | ||
use aptos_std::simple_map; | ||
use aptos_std::simple_map::SimpleMap; | ||
use aptos_std::table::Table; | ||
use supra_framework::system_addresses; | ||
|
||
struct AddressToContainerMap has key, store { | ||
address_container_map: SimpleMap<address, vector<u64>>, | ||
id_containerMetaData_map: Table<u64, ContainerMetadata> | ||
} | ||
|
||
//TODO: Add more fields for container metadata if needed | ||
//TODO: Group discussion: charging metrics | ||
struct ContainerMetadata has copy, drop, store { | ||
container_owner: address, | ||
//TODO enforce uniqueness of container_indentifier | ||
/// The unique identifier of the supra container | ||
container_indentifier: u64, | ||
/// The addresses of modules in the container | ||
Module_adresses: vector<address>, | ||
/// Pending proposal module address, | ||
pending_proposal: SimpleMap<u64, vector<u8>>, | ||
//TODO type information for the coin | ||
/// The address of the customer asset reciver | ||
customer_asset_receiver: address, | ||
/// The address of the supra coin reciver | ||
supra_coin_receiver: address | ||
} | ||
|
||
/// Initialize the container metadata storage | ||
public fun initialize(supra_framework: &signer) { | ||
system_addresses::assert_supra_framework(supra_framework); | ||
if (!exists<AddressToContainerMap>(@supra_framework)) { | ||
move_to<AddressToContainerMap>( | ||
supra_framework, | ||
AddressToContainerMap { | ||
address_container_map: simple_map::new(), | ||
} | ||
); | ||
} | ||
} | ||
|
||
/// Create a new container | ||
public fun create_container(supra_framework: &signer, address: address, container_metadata: ContainerMetadata) acquires AddressToContainerMap { | ||
system_addresses::assert_supra_framework(supra_framework); | ||
let container = borrow_global_mut<AddressToContainerMap>(@supra_framework); | ||
simple_map::upsert(&mut container.address_container_map, address, container_metadata); | ||
} | ||
|
||
//TODO design choice: 1) Supraframework create container 2) every one can create container, there would be a charge | ||
// the charge would go to some beneficiary address, the beneficiary address would be set and change by the supraframework | ||
|
||
//TODO API to view and modify the metadata and requires the container owner's signer | ||
|
||
//TODO Task for Aosen: how this will be published and how can we get the address back | ||
|
||
/// Add one module address to the container | ||
public fun add_module_to_container(supra_framework: &signer, address: address, module_address: address) acquires AddressToContainerMap { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe creation of module should be up to container owner only. So |
||
system_addresses::assert_supra_framework(supra_framework); | ||
assert(exists<AddressToContainerMap>(@supra_framework), 1); | ||
let container = borrow_global_mut<AddressToContainerMap>(@supra_framework); | ||
let container_metadata = simple_map::borrow_mut(&mut container.address_container_map, &address); | ||
vector::insert(container_metadata.Module_adresses, module_address); | ||
} | ||
|
||
#[view] | ||
public fun get_container_metadata(supra_framework: &signer, address: address): ContainerMetadata acquires AddressToContainerMap { | ||
system_addresses::assert_supra_framework(supra_framework); | ||
assert(exists<AddressToContainerMap>(address), 1); | ||
let container = borrow_global<AddressToContainerMap>(@supra_framework); | ||
*simple_map::borrow(&container.address_container_map, &address) | ||
} | ||
|
||
public fun UpdateContainerMetadata(supra_framework: &signer, address: address, container_metadata: ContainerMetadata) acquires ContainerMetadata { | ||
system_addresses::assert_supra_framework(supra_framework); | ||
let container_metadata = borrow_global_mut<ContainerMetadata>(address); | ||
//DO IT in a nicer way | ||
*container_metadata = container_metadata; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why this is a map from
address
tovector<u64>
, it is supposed to be from module address to container id. Assuming container id to be a unique sequence number, this can be a mapaddress -> u64
, or rather it can beTable<address,u64>
.