Skip to content

Commit

Permalink
feat: username data
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoAcosta committed Nov 5, 2024
1 parent e953b0b commit c44a3df
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/plasa/Plasa.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,39 @@ contract Plasa is Ownable, IPlasa {
function getUsername(address user) public view returns (string memory) {
return names.userToName(user);
}

/**
* @dev Retrieves the usernames associated with an array of user addresses.
* @param users The addresses of the users whose usernames are to be retrieved.
* @return string[] memory An array of usernames corresponding to the input addresses.
*/
function getUsernames(address[] memory users) public view returns (string[] memory) {
string[] memory usernames = new string[](users.length);
for (uint256 i = 0; i < users.length; i++) {
usernames[i] = getUsername(users[i]);
}
return usernames;
}

/**
* @dev Retrieves the username data associated with a given user address.
* @param user The address of the user whose username data is to be retrieved.
* @return UsernameData memory The username data of the user.
*/
function getUsernameData(address user) public view returns (UsernameData memory) {
return UsernameData({ user: user, name: getUsername(user) });
}

/**
* @dev Retrieves the username data associated with an array of user addresses.
* @param users The addresses of the users whose username data is to be retrieved.
* @return UsernameData[] memory An array of UsernameData structures corresponding to the input addresses.
*/
function getUsernamesData(address[] memory users) public view returns (UsernameData[] memory) {
UsernameData[] memory usernameData = new UsernameData[](users.length);
for (uint256 i = 0; i < users.length; i++) {
usernameData[i] = getUsernameData(users[i]);
}
return usernameData;
}
}
18 changes: 18 additions & 0 deletions src/plasa/interfaces/IPlasa.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import { INames } from "../../names/INames.sol";
/// @title IPlasa Interface
/// @dev This interface defines the functions for user registration and username retrieval in the Plasa system.
interface IPlasa {
/// @notice Struct to hold username data.
/// @param user The address of the user.
/// @param name The username of the user.
struct UsernameData {
address user;
string name;
}

/// @notice Checks if a user is registered in the Plasa system.
/// @param user The address of the user to check.
/// @return bool Returns true if the user is registered, false otherwise.
Expand All @@ -23,4 +31,14 @@ interface IPlasa {
/// @notice The names contract interface.
/// @return INames Returns the names contract.
function names() external view returns (INames);

/// @notice Retrieves the username data associated with an array of user addresses.
/// @param user The address of the user whose username is to be retrieved.
/// @return UsernameData The username data of the user.
function getUsernameData(address user) external view returns (UsernameData memory);

/// @notice Retrieves the usernames associated with an array of user addresses.
/// @param users The addresses of the users whose usernames are to be retrieved.
/// @return UsernameData[] memory An array of UsernameData structures corresponding to the input addresses.
function getUsernamesData(address[] memory users) external view returns (UsernameData[] memory);
}

0 comments on commit c44a3df

Please sign in to comment.