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

Allow setting target address and transfer to address during registration #59

Closed
wants to merge 16 commits into from

Conversation

0xaptosj
Copy link
Contributor

@0xaptosj 0xaptosj commented Aug 9, 2023

Summary

  1. rename set_reverse_lookup to set_name_address_and_reverse_lookup to avoid confusion.
  2. change the logic on when to set_name_address_and_reverse_lookup
previous behavior new behavior
if signer doesn't have a primary name (either due to first time buying a name, or had once but cleared) on top of previous behavior, we check another condition should_set_reverse_lookup_and_target_addres_result, this returns true only when signer set both target address and transfer to address to itself, then we set primary name
    public fun should_set_reverse_lookup_and_target_address(
        signer_address: address,
        target_address: Option<address>,
        transfer_to_address: Option<address>,
    ): bool {
        let transfer_to_address = option::get_with_default(&transfer_to_address, signer_address);
        let target_address = option::get_with_default(&target_address, signer_address);
        if (target_address == signer_address && transfer_to_address == signer_address) {
            true
        } else {
            false
        }
    }
  1. change the logic on when to set target address
previous behavior new behavior
if primary name is set, target address will be set along, or user is registering a domain. in both cases, target address is set to the signer on top of previous behavior, also set target address if it's passed explicitly, in this case even signer is registering a subdomain we still set target address
    public fun should_set_target_address_in_register_name(
        subdomain_name: Option<String>,
        target_address: Option<address>,
    ): bool {
        if (!is_subdomain(subdomain_name)) {
            // If signer is registering a domain, automatically set the name to point to target address, if not set use signer address
            true
        }
        else if (option::is_some(&target_address)) {
            // Else if target address is explicitly provided, set it
            true
        }
        else {
            // Else signer is registering a subdomain and target address not explicitly set, leave it as none
            false
        }
    }

@0xaptosj 0xaptosj changed the base branch from main to bl/rew August 9, 2023 01:09
@0xaptosj 0xaptosj force-pushed the j/pass-target-address-in-register-2 branch from 3cc7885 to d84800e Compare August 9, 2023 01:13
@angieyth
Copy link
Contributor

angieyth commented Aug 9, 2023

do you think we should add an unit test for transfer and another one for target address? (I sound like brian :P)

@0xaptosj
Copy link
Contributor Author

0xaptosj commented Aug 9, 2023

do you think we should add an unit test for transfer and another one for target address? (I sound like brian :P)

I should, im figuring out how, your are right unit test is the most painful thing

@0xaptosj 0xaptosj changed the title pass target address and transfer to address during registration Allow setting target address and transfer to address during registration Aug 9, 2023
core_v2/sources/test_helper.move Outdated Show resolved Hide resolved
core_v2/sources/domains.move Outdated Show resolved Hide resolved
core_v2/sources/domains.move Outdated Show resolved Hide resolved
@0xaptosj 0xaptosj force-pushed the j/pass-target-address-in-register-2 branch from 0e4efee to 1adef50 Compare August 9, 2023 21:48
@0xaptosj 0xaptosj force-pushed the j/pass-target-address-in-register-2 branch from 70cfca4 to 4310171 Compare August 9, 2023 23:00
// Automatically set the name to point to the sender's address
set_target_address_internal(subdomain_name, domain_name, signer::address_of(sign));
// If the signer has no reverse lookup set and signer is minting for itself, set the user's reverse lookup and target address.
if (result_of_should_set_reverse_lookup_and_target_address) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible to separate the logic of reverse look up and set target address in should_set_reverse_lookup_and_target_address_in_register_name

I see we also have should_set_target_address_in_register_name and it's confusing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's because set reverse lookup will always set target address at the same time, if i break it into 2, i need to break set_target_address_and_reverse_lookup

Copy link
Contributor

Choose a reason for hiding this comment

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

I do think we should break set_target_address_and_reverse_lookup :P
because those are basically two different things. aren't them?
you set primary name when the buyer is the owner
you set target address whenever there's a value passing in?

// Automatically set the name to point to the sender's address
set_target_address_internal(subdomain_name, domain_name, signer::address_of(sign));
// If the signer has no reverse lookup set and signer is minting for itself, set the user's reverse lookup and target address.
if (result_of_should_set_reverse_lookup_and_target_address) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I do think we should break set_target_address_and_reverse_lookup :P
because those are basically two different things. aren't them?
you set primary name when the buyer is the owner
you set target address whenever there's a value passing in?

target_address: Option<address>,
): bool {
if (!is_subdomain(subdomain_name)) {
// If signer is registering a domain, automatically set the name to point to target address, if not set use signer address
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 understand this case, can you elaborate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated the comment, basically when registering a domain, we always set the target address of the new domain

@angieyth angieyth self-requested a review August 10, 2023 23:19
@0xaptosj 0xaptosj closed this Aug 11, 2023
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