Skip to content

Commit 4f67b09

Browse files
chore(*): clean up iota-names packages (#450)
* clean up auction module * clean up coupons module * clean up payments module * clean up subnames module * clean up iota-names constants * clean up iota-names deny list * clean up iota-names name_registration * clean up iota-names name * clean up iota-names registry * clean up iota-names validation * clean up iota-names sales * don't mention internal functions in function docs * sssss * review suggestions Co-authored-by: DaughterOfMars <chloedaughterofmars@gmail.com> * review suggestions Co-authored-by: DaughterOfMars <chloedaughterofmars@gmail.com> * reorder --------- Co-authored-by: DaughterOfMars <chloedaughterofmars@gmail.com>
1 parent 2beb002 commit 4f67b09

File tree

14 files changed

+152
-127
lines changed

14 files changed

+152
-127
lines changed

packages/auction/sources/auction.move

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Modifications Copyright (c) 2025 IOTA Stiftung
33
// SPDX-License-Identifier: Apache-2.0
44

5-
/// Implementation of auction module.
65
module iota_names_auction::auction;
76

87
use iota::balance::{Self, Balance};
@@ -29,6 +28,7 @@ const AUCTION_BIDDING_PERIOD_MS: u64 = 60 * 60 * 1000;
2928
const AUCTION_MIN_QUIET_PERIOD_MS: u64 = 10 * 60 * 1000;
3029
/// The overbid must be at least of 1 IOTA, which is 10^9 NANOs
3130
const AUCTION_MIN_OVERBID_VALUE_IOTA: u64 = 1_000_000_000;
31+
3232
// === Abort codes ===
3333

3434
#[error]
@@ -51,14 +51,14 @@ const ENoProfits: vector<u8> = b"There are no profits to withdraw.";
5151
/// Authorization witness to call protected functions of `iota_names`.
5252
public struct AuctionAuth has drop {}
5353

54-
/// The AuctionHouse application.
54+
/// The `AuctionHouse` application.
5555
public struct AuctionHouse has key, store {
5656
id: UID,
5757
balance: Balance<IOTA>,
5858
auctions: LinkedTable<Name, Auction>,
5959
}
6060

61-
/// The Auction application.
61+
/// The `Auction` application.
6262
#[allow(lint(coin_field))]
6363
public struct Auction has store {
6464
name: Name,
@@ -77,7 +77,8 @@ fun init(ctx: &mut TxContext) {
7777
});
7878
}
7979

80-
/// Start an auction if it's not started yet; and make the first bid.
80+
/// Start an auction for a name by placing the first bid.
81+
/// This will fail if the name is not available or already being auctioned.
8182
public fun start_auction_and_place_bid(
8283
self: &mut AuctionHouse,
8384
iota_names: &mut IotaNames,
@@ -121,13 +122,14 @@ public fun start_auction_and_place_bid(
121122
self.auctions.push_front(name, auction)
122123
}
123124

124-
/// #### Notice
125125
/// Bidders use this function to place a new bid.
126126
///
127-
/// Panics
128-
/// Panics if `name` is invalid
129-
/// or there isn't an auction for `name`
130-
/// or `bid` is too low,
127+
/// ### Panics
128+
///
129+
/// Panics if:
130+
/// - the name is invalid
131+
/// - there is no auction for the name
132+
/// - the bid is too low
131133
public fun place_bid(
132134
self: &mut AuctionHouse,
133135
name: String,
@@ -201,11 +203,11 @@ public fun place_bid(
201203
self.auctions.push_front(name, auction);
202204
}
203205

204-
/// #### Notice
205-
/// Auction winner can come and claim the NFT
206+
/// Auction winners can use this function to claim the NFT associated with the name.
206207
///
207-
/// Panics
208-
/// sender is not the winner
208+
/// ### Panics
209+
///
210+
/// Panics if the sender is not the winner.
209211
public fun claim(
210212
self: &mut AuctionHouse,
211213
name: String,
@@ -245,11 +247,7 @@ public fun claim(
245247

246248
// === Public Functions ===
247249

248-
/// #### Notice
249-
/// Get metadata of an auction
250-
///
251-
/// #### Params
252-
/// The name being auctioned.
250+
/// Get metadata of an auction.
253251
///
254252
/// #### Return
255253
/// (`start_timestamp_ms`, `end_timestamp_ms`, `current_bidder`, `highest_amount`)
@@ -290,6 +288,11 @@ public fun collect_winning_auction_fund(
290288

291289
// === Admin Functions ===
292290

291+
/// Admin functionality used to withdraw all funds from the auction house.
292+
///
293+
/// ### Panics
294+
///
295+
/// Panics if the auction house has no profits.
293296
public fun admin_withdraw_funds(
294297
_: &AdminCap,
295298
self: &mut AuctionHouse,

packages/coupons/sources/coupons.move

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,9 @@ public struct Coupons has store {
2525
coupons: Table<vector<u8>, Coupon>,
2626
}
2727

28-
public(package) fun new(ctx: &mut TxContext): Coupons {
29-
Coupons {
30-
coupons: table::new(ctx),
31-
}
32-
}
28+
// === Public functions ===
3329

34-
// Add percentaged based coupon.
30+
/// Adds percentaged based coupon.
3531
public fun add_percentage_coupon(
3632
self: &mut Coupons,
3733
hash: String,
@@ -41,7 +37,7 @@ public fun add_percentage_coupon(
4137
self.save_coupon(hash, coupon::new_percentage(percentage, rules));
4238
}
4339

44-
// Add fixed amount coupon.
40+
/// Adds fixed amount coupon.
4541
public fun add_fixed_coupon(
4642
self: &mut Coupons,
4743
hash: String,
@@ -51,25 +47,35 @@ public fun add_fixed_coupon(
5147
self.save_coupon(hash, coupon::new_fixed(amount, rules));
5248
}
5349

54-
// A function to remove a coupon from the system.
50+
// === Internal functions ===
51+
52+
/// Creates the `Coupons` struct.
53+
public(package) fun new(ctx: &mut TxContext): Coupons {
54+
Coupons {
55+
coupons: table::new(ctx),
56+
}
57+
}
58+
59+
/// Removes a coupon from the system.
5560
public(package) fun remove_coupon(self: &mut Coupons, hash: String) {
5661
let hash = hex::decode(hash.into_bytes());
5762
assert!(self.coupons.contains(hash), ECouponDoesNotExist);
5863
let _: Coupon = self.coupons.remove(hash);
5964
}
6065

61-
/// Private internal functions
62-
/// An internal function to save the coupon in the shared object's config.
66+
/// Saves the coupon in the shared object's config.
6367
public(package) fun save_coupon(self: &mut Coupons, hash: String, coupon: Coupon) {
6468
let hash = hex::decode(hash.into_bytes());
6569
assert!(!self.coupons.contains(hash), ECouponAlreadyExists);
6670
self.coupons.add(hash, coupon);
6771
}
6872

73+
/// Returns a reference to the coupon table.
6974
public(package) fun coupons(self: &Coupons): &Table<vector<u8>, Coupon> {
7075
&self.coupons
7176
}
7277

78+
/// Returns a mutable reference to the coupon table.
7379
public(package) fun coupons_mut(self: &mut Coupons): &mut Table<vector<u8>, Coupon> {
7480
&mut self.coupons
7581
}

packages/iota-names/sources/constants.move

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,18 @@ use std::string::String;
1515
const IOTA_TLN: vector<u8> = b"iota";
1616
/// The amount of milliseconds in a year.
1717
const YEAR_MS: u64 = 365 * 24 * 60 * 60 * 1000;
18-
/// 30 day Grace period in milliseconds.
18+
/// 30 day grace period in milliseconds.
1919
const GRACE_PERIOD_MS: u64 = 30 * 24 * 60 * 60 * 1000;
2020

2121
/// A leaf record doesn't expire. Expiration is retrieved by the parent's
2222
/// expiration.
2323
const LEAF_EXPIRATION_TIMESTAMP: u64 = 0;
2424

25-
/// Subname constants
26-
///
27-
/// These constants are the core of the subname functionality.
28-
/// Even if we decide to change the subname module, these can
29-
/// be re-used. They're added as metadata on NameRecord.
30-
///
25+
// === Subname constants ===
26+
// These constants are the core of the subname functionality.
27+
// Even if we decide to change the subname module, these can
28+
// be re-used. They're added as metadata on `NameRecord`.
29+
3130
/// Whether a parent name can create child names. (name -> subname)
3231
const ALLOW_CREATION: vector<u8> = b"S_AC";
3332
/// Whether a child-name can auto-renew (if the parent hasn't changed).
@@ -44,7 +43,6 @@ public fun year_ms(): u64 { YEAR_MS }
4443
/// Grace period in milliseconds after which the name expires.
4544
public fun grace_period_ms(): u64 { GRACE_PERIOD_MS }
4645

47-
/// Subname constants
4846
/// The NameRecord key that a subname can create child names.
4947
public fun subname_allow_creation_key(): String { ALLOW_CREATION.to_string() }
5048

packages/iota-names/sources/controller.move

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public fun set_target_address(
4747
registry.set_target_address(name, new_target);
4848
}
4949

50-
/// Set the reverse lookup address for the name
50+
/// Sets the reverse lookup address for the name.
5151
public fun set_reverse_lookup(
5252
iota_names: &mut IotaNames,
5353
name: String,

packages/iota-names/sources/deny_list.move

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public struct DenyList has store {
2323
/// Authorization witness to call protected functions of `iota_names`.
2424
public struct DenyListAuth has drop {}
2525

26+
/// Sets up the deny list as admin.
2627
public fun setup(iota_names: &mut IotaNames, cap: &AdminCap, ctx: &mut TxContext) {
2728
iota_names::add_registry(
2829
cap,
@@ -34,7 +35,7 @@ public fun setup(iota_names: &mut IotaNames, cap: &AdminCap, ctx: &mut TxContext
3435
);
3536
}
3637

37-
/// Check for a reserved name.
38+
/// Checks for a reserved name.
3839
public fun is_reserved_name(iota_names: &IotaNames, name: &Name): bool {
3940
let len = name.number_of_levels();
4041
let mut index = 1;
@@ -64,39 +65,39 @@ public fun is_blocked_name(iota_names: &IotaNames, name: &Name): bool {
6465
false
6566
}
6667

67-
/// Add a list of reserved labels to the list as admin.
68+
/// Adds a list of reserved labels to the list as admin.
6869
public fun add_reserved_labels(iota_names: &mut IotaNames, _: &AdminCap, labels: vector<String>) {
6970
internal_add_labels_to_list(
7071
&mut deny_list_mut(iota_names).reserved,
7172
labels,
7273
);
7374
}
7475

75-
/// Add a list of blocked labels to the list as admin.
76+
/// Adds a list of blocked labels to the list as admin.
7677
public fun add_blocked_labels(iota_names: &mut IotaNames, _: &AdminCap, labels: vector<String>) {
7778
internal_add_labels_to_list(
7879
&mut deny_list_mut(iota_names).blocked,
7980
labels,
8081
);
8182
}
8283

83-
/// Remove a list of labels from the reserved list as admin.
84+
/// Removes a list of labels from the reserved list as admin.
8485
public fun remove_reserved_labels(iota_names: &mut IotaNames, _: &AdminCap, labels: vector<String>) {
8586
internal_remove_labels_from_list(
8687
&mut deny_list_mut(iota_names).reserved,
8788
labels,
8889
);
8990
}
9091

91-
/// Remove a list of labels from the blocked list as admin.
92+
/// Removes a list of labels from the blocked list as admin.
9293
public fun remove_blocked_names(iota_names: &mut IotaNames, _: &AdminCap, labels: vector<String>) {
9394
internal_remove_labels_from_list(
9495
&mut deny_list_mut(iota_names).blocked,
9596
labels,
9697
);
9798
}
9899

99-
/// Get immutable access to the registry.
100+
/// Gets immutable access to the registry.
100101
fun deny_list(iota_names: &IotaNames): &DenyList {
101102
iota_names.registry()
102103
}

packages/iota-names/sources/name.move

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
/// Defines the `Name` type and helper functions.
66
///
7-
/// Names are structured similar to web2 domains and the rules
8-
/// determining what a valid name is can be found here:
7+
/// Names are structured similar to web2 domains, and the rules
8+
/// determining what constitutes a valid name can be found here:
99
/// https://en.wikipedia.org/wiki/Domain_name#Domain_name_syntax
1010
module iota_names::name;
1111

@@ -32,7 +32,7 @@ public struct Name has copy, drop, store {
3232
labels: vector<String>,
3333
}
3434

35-
// Construct a `Name` by parsing and validating the provided string
35+
// Constructs a `Name` by parsing and validating the provided string.
3636
public fun new(name: String): Name {
3737
assert!(name.length() <= MAX_NAME_LENGTH, EInvalidName);
3838

@@ -79,27 +79,36 @@ public fun label(self: &Name, level: u64): &String {
7979

8080
/// Returns the TLN (Top-Level Name) of a `Name`.
8181
///
82-
/// "name.iota" -> "iota"
82+
/// e.g. `name.iota` -> `iota`
8383
public fun tln(self: &Name): &String {
8484
label(self, 0)
8585
}
8686

8787
/// Returns the SLN (Second-Level Name) of a `Name`.
8888
///
89-
/// "name.iota" -> "iota"
89+
/// e.g. `name.iota` -> `name`
9090
public fun sln(self: &Name): &String {
9191
label(self, 1)
9292
}
9393

94+
/// Returns the number of labels of a `Name` (TLN included).
95+
///
96+
/// e.g. `name.iota` -> 2
9497
public fun number_of_levels(self: &Name): u64 {
9598
self.labels.length()
9699
}
97100

101+
/// Returns whether the name is a subname.
102+
///
103+
/// e.g.
104+
/// `name.iota` -> `false`,
105+
/// `subname.name.iota` -> `true`
98106
public fun is_subname(name: &Name): bool {
99107
number_of_levels(name) > 2
100108
}
101109

102-
/// Derive the parent of a subname.
110+
/// Derives the parent of a subname.
111+
///
103112
/// e.g. `subname.example.iota` -> `example.iota`
104113
public fun parent(name: &Name): Option<Name> {
105114
if (is_subname(name)) {
@@ -115,7 +124,9 @@ public fun parent(name: &Name): Option<Name> {
115124
}
116125
}
117126

118-
/// Checks if `parent` name is a valid parent for `child`.
127+
/// Checks if the given `parent` name is valid for the given `child` name.
128+
///
129+
/// e.g. (`example.iota`, `subname.example.iota`) -> `true`
119130
public fun is_parent_of(parent: &Name, child: &Name): bool {
120131
if (number_of_levels(parent) < number_of_levels(child)) {
121132
let mut maybe_parent = parent(child);

packages/iota-names/sources/name_registration.move

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,8 @@
33
// SPDX-License-Identifier: Apache-2.0
44

55
/// Handles creation of the `NameRegistration`s. Separates the logic of
6-
/// creating
7-
/// a `NameRegistration`. New `NameRegistration`s can be created only by the
8-
/// `registry` and this module is tightly coupled with it.
9-
///
10-
/// When reviewing the module, make sure that:
11-
///
12-
/// - mutable functions can't be called directly by the owner
13-
/// - all getters are public and take an immutable reference
14-
///
6+
/// creating a `NameRegistration`. New `NameRegistration`s can be created
7+
/// only by the `registry` and this module is tightly coupled with it.
158
module iota_names::name_registration;
169

1710
use iota::clock::{timestamp_ms, Clock};
@@ -98,7 +91,7 @@ public fun expiration_timestamp_ms(self: &NameRegistration): u64 {
9891
self.expiration_timestamp_ms
9992
}
10093

101-
// get a read-only `uid` field of `NameRegistration`.
94+
// Returns a read-only `uid` field of `NameRegistration`.
10295
public fun uid(self: &NameRegistration): &UID { &self.id }
10396

10497
/// Get the mutable `id` field of the `NameRegistration`.

0 commit comments

Comments
 (0)