Skip to content

Commit

Permalink
Merge pull request #169 from aptos-labs/j/set-subdomain-target-addres…
Browse files Browse the repository at this point in the history
…s-to-sender-by-default

set name target address to sender by default
  • Loading branch information
0xaptosj authored Sep 22, 2023
2 parents 46875ec + bb3769b commit 75450cf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
36 changes: 22 additions & 14 deletions router/sources/router.move
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,22 @@ module router::router {
};

// Common operations that handle modes via the router
if (option::is_some(&target_addr)) {
set_target_addr(
user,
domain_name,
option::none(),
*option::borrow(&target_addr)
);
let target_addr_with_default = if (option::is_some(&target_addr)) {
*option::borrow(&target_addr)
} else {
signer::address_of(user)
};
set_target_addr(
user,
domain_name,
option::none(),
target_addr_with_default
);
if (option::is_some(&to_addr)) {
transfer_name(user, domain_name, option::none(), *option::borrow(&to_addr));
};

// This will set primary name and target address
set_primary_name_when_register(
user,
target_addr,
Expand Down Expand Up @@ -287,14 +291,17 @@ module router::router {
};

// Common operations that handle modes via the router
if (option::is_some(&target_addr)) {
set_target_addr(
user,
domain_name,
option::some(subdomain_name),
*option::borrow(&target_addr)
);
let target_addr_with_default = if (option::is_some(&target_addr)) {
*option::borrow(&target_addr)
} else {
signer::address_of(user)
};
set_target_addr(
user,
domain_name,
option::some(subdomain_name),
target_addr_with_default
);
if (option::is_some(&to_addr)) {
transfer_name(user, domain_name, option::some(subdomain_name), *option::borrow(&to_addr));
};
Expand All @@ -308,6 +315,7 @@ module router::router {
);
};

// This will set primary name and target address
set_primary_name_when_register(
user,
target_addr,
Expand Down
3 changes: 1 addition & 2 deletions router/sources/tests/target_address_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,9 @@ module router::target_address_tests {
let target_address = get_v1_target_addr(domain_name, option::none());
assert!(*option::borrow(&target_address) == user_addr, 1);
};
// Subdomain target address should be none, because we don't auto set target address in v1
{
let target_address = get_v1_target_addr(domain_name, subdomain_name_opt);
assert!(option::is_none(&target_address), 2);
assert!(*option::borrow(&target_address) == user_addr, 2);
};

// Set domain target address to user2_addr
Expand Down

0 comments on commit 75450cf

Please sign in to comment.