Skip to content
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

Dev Feature 2 - Delete Unused Templates #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion include/atomicassets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,18 @@ CONTRACT atomicassets : public contract {
ATTRIBUTE_MAP immutable_data
);

ACTION deltemplate(
name authorized_editor,
name collection_name,
int32_t template_id
);

ACTION locktemplate(
name authorized_editor,
name collection_name,
int32_t template_id
);


ACTION mintasset(
name authorized_minter,
name collection_name,
Expand Down
30 changes: 29 additions & 1 deletion src/atomicassets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,35 @@ ACTION atomicassets::createtempl(
).send();
}

/**
* Deletes a template if the issued supply is zero
* @required_auth authorized_editor, who is within the authorized_accounts list of the collection
**/
ACTION atomicassets::deltemplate(
name authorized_editor,
name collection_name,
int32_t template_id
) {
require_auth(authorized_editor);

auto collection_itr = collections.require_find(collection_name.value,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is already done in check_has_collection_auth

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, ty. check_has_collection_auth will be slightly reworked after all of these merges to implement the CPU optimizations.

"No collection with this name exists");

check_has_collection_auth(
authorized_editor,
collection_name,
"The editor is not authorized within the collection"
);

templates_t collection_templates = get_templates(collection_name);
auto template_itr = collection_templates.require_find(template_id,
"No template with the specified id exists for the specified collection");

check(template_itr->issued_supply == 0,
"Can't delete a template that has any assets issued");

collection_templates.erase(template_itr);
}

/**
* Sets the max supply of the template to the issued supply
Expand Down Expand Up @@ -502,7 +531,6 @@ ACTION atomicassets::locktemplate(
});
}


/**
* Creates a new asset
* Doesn't work if the template has a specified max_supply that has already been reached
Expand Down