-
Notifications
You must be signed in to change notification settings - Fork 0
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 3 + 6 - Mutable Templates & Non-Burnable or Non-transferable XOR condition #8
base: master
Are you sure you want to change the base?
Dev feature 3 + 6 - Mutable Templates & Non-Burnable or Non-transferable XOR condition #8
Conversation
on-a-t-break
commented
Sep 20, 2024
•
edited
Loading
edited
- Adds Mutable Template Table with template_id key and schema_name + serialized_mutable_data fields
- Adds createtempl2 for creating templates with explicit mutable data
- Non-Burnable or Non-transferable XOR condition
include/atomicassets.hpp
Outdated
@@ -370,6 +406,16 @@ CONTRACT atomicassets : public contract { | |||
config_t config = config_t(get_self(), get_self().value); | |||
tokenconfigs_t tokenconfigs = tokenconfigs_t(get_self(), get_self().value); | |||
|
|||
void create_template( | |||
name & authorized_creator, |
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.
I am not a fan of passing names by reference, since they're essentially just 64 bit primitive types. Most likely compiles to exactly the same output anyways, so more of a nitpick than anything else.
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.
Sure, can be set to pass by value. I always do everything by reference when I can if I know that the original isn't going to be mutated.
bool burnable, | ||
uint32_t max_supply, | ||
ATTRIBUTE_MAP & immutable_data, | ||
ATTRIBUTE_MAP mutable_data = {} |
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.
is there a reason not to use a reference for the mutable data when you're using one for the immutable data? I also don't really like the default value, I'd rather see that explicitly when calling the function.
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.
There's no reference for the mutable_data because the original createtempl action does not have a field for mutable_data (only immutable_data). It's only accessed by the new createtempl2 action.
Just looks a bit cleaner this way, as the function doesn't have to create an empty ATTRIBUTE_MAP & pass that over (if it was by reference)
uint64_t primary_key() const { return (uint64_t) template_id; } | ||
}; | ||
|
||
typedef multi_index <name("templatedata"), template_data_s> template_data_t; |
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.
I think calling this templatedata could be confusing, because template data already exists as part of the normal template table. A name that makes it clear this is referring to mutable template data would be better imo.
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.
I agree, wdy think about these:
- templmutable
- mutabletempl
include/atomicassets.hpp
Outdated
@@ -370,6 +406,16 @@ CONTRACT atomicassets : public contract { | |||
config_t config = config_t(get_self(), get_self().value); | |||
tokenconfigs_t tokenconfigs = tokenconfigs_t(get_self(), get_self().value); | |||
|
|||
void create_template( |
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.
I would call this internal_create_template
to be consistent with the other internal functions.
include/atomicassets.hpp
Outdated
ACTION settempldata( | ||
name authorized_editor, | ||
name collection_name, | ||
name schema_name, |
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.
I don't think schema_name should be a part of the action signature, as it can be inferred from the template_id. setassetdata
also doesn't include the schema name
src/atomicassets.cpp
Outdated
make_tuple(collection_name, schema_name, template_id, deserialized_old_data, new_mutable_data) | ||
).send(); | ||
|
||
// If entry doesn't exist, then emplace entry |
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.
This control flow has a problem where you could call it with empty new mutable data, and this empty data would then be emplaced. Doesn't break anything, but I think the following controlflow would be better and also clearer to understand (in pseudocode):
if no template data entry exists {
check new_mutable_data must not be empty
emplace
} else {
if new_mutable_data is empty {
erase
} else {
modify
}
}
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.
Added a condition for emplacing. It's a rather unique scenario & would likely only be executed by accident by users, but this just makes it a bit cleaner internally & more consistent with the entry modification functionality, while still not throwing an error to the user & breaking the transaction.
I'm leaning towards not having a check here to avoid breaking transactions when it's not critical / absolutely necessary.
if (template_data_itr == template_data.end() && new_mutable_data.size() > 0){
template_data.emplace(authorized_editor, [&](auto &_template_data) {
_template_data.template_id = template_id;
_template_data.schema_name = template_itr->schema_name;
_template_data.mutable_serialized_data = serialize(new_mutable_data, schema_itr->format);
});
}
src/atomicassets.cpp
Outdated
int32_t template_id = current_config.template_counter++; | ||
config.set(current_config, get_self()); | ||
|
||
if (transferable == false){ |
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.
I'd prefer
check(burnable || transferable, "A template cannot be both non-transferable and non-burnable")
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.
clean
src/atomicassets.cpp
Outdated
permission_level{get_self(), name("active")}, | ||
get_self(), | ||
name("logsetdatatl"), | ||
make_tuple(collection_name, schema_name, template_id, mutable_data, mutable_data) |
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.
old data in the log should be empty, not the mutable data as well.
Incorporated all comments above, still need to decide the templatedata table name, otherwise ready for merging into CPU optimizations. |