-
Notifications
You must be signed in to change notification settings - Fork 1
Labels
dev-toolsIssues related to the Developer Tools TeamIssues related to the Developer Tools TeamenhancementNew feature or requestNew feature or requestiota-namespackagesIssues/PRs related to smart contract packagesIssues/PRs related to smart contract packages
Description
Description
Add public fun lookup_address(self: &Registry, name: Name, clock: &Clock): Option<Address> {
and public fun reverse_lookup(self: &Registry, address: address, clock: &Clock): Option<Name> {
, maybe with _verified
suffix to distinguish with the functions in registry.move.
Motivation
Currently, callers need to manually call the checks if they want to be sure that something is not expired:
/// Different custom error messages.
#[error]
const ENameNotFound: vector<u8> = b"Name not found.";
#[error]
const ENameNotPointingToAddress: vector<u8> = b"Name not pointing to an address.";
#[error]
const ENameExpired: vector<u8> = b"Name expired.";
/// A function to transfer an object of any type T to a name (for instance `example.iota`)
public fun send_to_name<T: key + store>(iota_names: &IotaNames, obj: T, name: String, clock: &Clock) {
// Look up the name on the registry.
let mut optional = iota_names.registry<Registry>().lookup(name::new(name));
// Check that the name indeed exists.
assert!(optional.is_some(), ENameNotFound);
let name_record = optional.extract();
// Check that name has not expired.
// This check is optional, but it's recommended you perform the verification.
assert!(!name_record.has_expired(clock), ENameExpired);
// Check that the name has a target address set.
assert!(name_record.target_address().is_some(), ENameNotPointingToAddress);
// Transfer the object to that name.
transfer::public_transfer(obj, name_record.target_address().extract())
}
Having high level methods that do these checks internally makes it easier to use without doing something wrong
Requirements
Add the two new functions
Open questions (optional)
Are other names better? Should they return an Option or just error instead?
Metadata
Metadata
Assignees
Labels
dev-toolsIssues related to the Developer Tools TeamIssues related to the Developer Tools TeamenhancementNew feature or requestNew feature or requestiota-namespackagesIssues/PRs related to smart contract packagesIssues/PRs related to smart contract packages