forked from pinknetworkx/atomicassets-contract
-
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 5 - Changing Collection Authors #6
Open
on-a-t-break
wants to merge
2
commits into
wax-office-of-inspector-general:master
Choose a base branch
from
on-a-t-break:dev-feature-5
base: master
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.
+114
−1
Open
Changes from 1 commit
Commits
Show all changes
2 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
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
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 |
---|---|---|
|
@@ -327,6 +327,102 @@ ACTION atomicassets::forbidnotify( | |
}); | ||
} | ||
|
||
/** | ||
* Creates a swap offer for a collection | ||
* Acceptance functionality depends on the authorization being 'owner' or 'active' (7 days gate) | ||
*/ | ||
|
||
ACTION atomicassets::createauswap( | ||
name collection_name, | ||
name new_author, | ||
name permission | ||
) { | ||
auto collection_itr = collections.require_find(collection_name.value, | ||
"No collection with this name exists"); | ||
|
||
if (permission == name("owner")){ | ||
require_auth(permission_level{collection_itr->author, name("owner")}); | ||
} else { | ||
check(permission == name("active"), | ||
"Only 'owner' or 'active' permissions can create an author swap"); | ||
require_auth(permission_level{collection_itr->author, name("active")}); | ||
} | ||
|
||
check(authorswaps.find(collection_name.value) == authorswaps.end(), | ||
"Can't swap author's while an authorswap is underway for this collection"); | ||
|
||
authorswaps.emplace(collection_itr->author, [&](auto &_author_swaps) { | ||
_author_swaps.collection_name = collection_name; | ||
_author_swaps.current_author = collection_itr->author; | ||
_author_swaps.new_author = new_author; | ||
_author_swaps.permission = permission; | ||
_author_swaps.swap_date = eosio::current_time_point().sec_since_epoch(); | ||
}); | ||
} | ||
|
||
/** | ||
* Accepts an author swap, with time constraints based on 'owner' or 'active' permissions used when creating the author swap | ||
* With default parameters, author swaps created by 'active' permissions can only be accepted after 1 week has passed | ||
* With default parameters, author swaps remain valid for up to 3 weeks | ||
*/ | ||
|
||
ACTION atomicassets::acceptauswap( | ||
name collection_name | ||
) { | ||
auto collection_itr = collections.require_find(collection_name.value, | ||
"No collection with this name exists"); | ||
|
||
auto author_swaps_itr = authorswaps.require_find(collection_name.value, | ||
"No author swaps for this collection found"); | ||
|
||
// Just in case** | ||
check(collection_itr->author == author_swaps_itr->current_author, | ||
"Current author mismatch"); | ||
|
||
uint32_t now = eosio::current_time_point().sec_since_epoch(); | ||
|
||
if (author_swaps_itr->permission == name("owner")){ | ||
require_auth(permission_level{author_swaps_itr->new_author, name("owner")}); | ||
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. It doesn't make sense to me that the new author also has to be the owner permission |
||
} else { | ||
check (author_swaps_itr->swap_date + AUTHOR_SWAP_TIME_DELTA < now, | ||
("Active permission can only accept an author swap after " + to_string(AUTHOR_SWAP_TIME_DELTA) + " seconds have passed. [ " + | ||
to_string(now - author_swaps_itr->swap_date + AUTHOR_SWAP_TIME_DELTA) + " ] seconds remaining").c_str()); | ||
|
||
require_auth(permission_level{collection_itr->author, name("active")}); | ||
} | ||
|
||
check (now < author_swaps_itr->swap_date + (AUTHOR_SWAP_TIME_DELTA * 3), "Author swap for this collection has expired"); | ||
|
||
collections.modify(collection_itr, author_swaps_itr->new_author, [&](auto &_collection){ | ||
_collection.author = author_swaps_itr->new_author; | ||
}); | ||
|
||
authorswaps.erase(author_swaps_itr); | ||
} | ||
|
||
/** | ||
* Rejects author swaps | ||
* Can be used by either the current author or by the new author | ||
*/ | ||
|
||
ACTION atomicassets::rejectauswap( | ||
name collection_name | ||
) { | ||
auto collection_itr = collections.require_find(collection_name.value, | ||
"No collection with this name exists"); | ||
|
||
auto author_swaps_itr = authorswaps.require_find(collection_name.value, | ||
"No author swaps for this collection found"); | ||
|
||
// Just in case** | ||
check(collection_itr->author == author_swaps_itr->current_author, | ||
"Current author mismatch"); | ||
|
||
check(has_auth(author_swaps_itr->current_author) || has_auth(author_swaps_itr->new_author), | ||
"Missing required authorizations"); | ||
|
||
authorswaps.erase(author_swaps_itr); | ||
} | ||
|
||
/** | ||
* Creates a new schema | ||
|
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.
Just personal preference, but I would prefer if this was written out as 60 * 60 * 24 * 7 so that its immediately clear what this means and that it's correct.