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

[ans] set subdomain renew policy #53

Merged
merged 3 commits into from
Aug 8, 2023
Merged

Conversation

angieyth
Copy link
Contributor

@angieyth angieyth commented Aug 7, 2023

  1. use enum instead of boolean for subdomain renewal policy
  2. add the validation function to check if the renewal policy is correct
  3. change the test names with prefix test_

@angieyth angieyth changed the title set subdomain renew policy [ans] set subdomain renew policy Aug 7, 2023
@@ -31,6 +31,10 @@ module aptos_names_v2::domains {
const AUTO_RENEWAL_EXPIRATION_CUTOFF_SEC: u64 = 1709855999;
const SECONDS_PER_YEAR: u64 = 60 * 60 * 24 * 365;

/// enums for subdomain expiration policy
const SUBDOMAIN_POLICY_LOOKUP_DOMAIN_EXPIRATION: u8 = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

is this the right default? I feel like SUBDOMAIN_POLICY_LOOKUP_DOMAIN_EXPIRATION is a non-default policy because if we follow the way domain expiration works, manual expiration is the expected expiration policy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to change this as a param passing in after this PR. no default behavior anymore

Copy link
Contributor

Choose a reason for hiding this comment

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

nit I personally prefer if we have SUBDOMAIN_POLICY_MANUAL_SET_EXPIRATION = 0 because that was the original behavior in v1

}

fun validate_subdomain_expiration_policy(
use_domain_expiration_sec: u8,
Copy link
Contributor

Choose a reason for hiding this comment

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

rename: subdomain_expiration_policy

test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 1, vector::empty<u8>());

// Register a subdomain!
test_helper::register_name(user, option::some(test_helper::subdomain_name()), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_subdomain_name(), 1, vector::empty<u8>());
Copy link
Contributor

Choose a reason for hiding this comment

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

assert the default policy before change as well

@@ -679,7 +685,7 @@ module aptos_names_v2::domains {
let record = get_record_mut(domain_name, option::some(subdomain_name));
assert!(option::is_some(&record.subdomain_ext), error::invalid_state(ENOT_A_SUBDOMAIN));
let subdomain_ext = option::borrow(&record.subdomain_ext);
if (subdomain_ext.use_domain_expiration_sec) {
if (subdomain_ext.subdomain_expiration_policy == SUBDOMAIN_POLICY_LOOKUP_DOMAIN_EXPIRATION) {
assert!(false, error::invalid_state(ESUBDOMAIN_IS_AUTO_RENEW));
Copy link
Contributor

Choose a reason for hiding this comment

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

should we allow set, even if the policy doesn't use the expiration?

What if the domain owner wants to change the expiration before they turn off the auto-renew flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if auto-renew flag is on and user wants to set the expiration date, we can either

  1. let them set and implicitly switch the flag back
  2. throw error because the flag is on

I like the second one better because there's no extra action implied. I don't feel strong on either one though

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't feel strongly either. I think let's just do 2. for now and we can always upgrade the contract later if we need to change the behavior.

@@ -31,6 +31,10 @@ module aptos_names_v2::domains {
const AUTO_RENEWAL_EXPIRATION_CUTOFF_SEC: u64 = 1709855999;
const SECONDS_PER_YEAR: u64 = 60 * 60 * 24 * 365;

/// enums for subdomain expiration policy
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add a comment to update validate_subdomain_expiration_policy if adding a new enum?

Maybe also good idea to have // const SUBDOMAIN_POLICY_NEXT_ENUM = 2 comment so that we keep track of what the next number should be.

@angieyth angieyth merged commit 06df035 into bl/rew Aug 8, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants