Skip to content

Commit

Permalink
feat: add plasa view
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoAcosta committed Nov 5, 2024
1 parent 4d45ca4 commit fc43c29
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/plasa/Plasa.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.20;
// Importing necessary contracts and interfaces
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { INames } from "../names/INames.sol";
import { IPlasa } from "./interfaces/IPlasa.sol";
import { IPlasa, IPlasaView } from "./interfaces/IPlasa.sol";

/**
* @title Plasa Contract
Expand Down Expand Up @@ -84,4 +84,13 @@ contract Plasa is Ownable, IPlasa {
}
return usernameData;
}

/// @inheritdoc IPlasaView
function getPlasaView() external view returns (PlasaView memory) {
return
PlasaView({
data: PlasaData({ contractAddress: address(this), namesContract: address(names) }),
user: PlasaUser({ isRegistered: isRegistered(msg.sender), username: getUsername(msg.sender) })
});
}
}
3 changes: 2 additions & 1 deletion src/plasa/interfaces/IPlasa.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
pragma solidity ^0.8.20;

import { INames } from "../../names/INames.sol";
import { IPlasaView } from "./IPlasaView.sol";

/// @title IPlasa Interface
/// @dev This interface defines the functions for user registration and username retrieval in the Plasa system.
interface IPlasa {
interface IPlasa is IPlasaView {
/// @notice Struct to hold username data.
/// @param user The address of the user.
/// @param name The username of the user.
Expand Down
34 changes: 34 additions & 0 deletions src/plasa/interfaces/IPlasaView.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

/// @title IPlasaView Interface
/// @dev This interface defines the functions for viewing Plasa data.
interface IPlasaView {
/// @notice Struct to hold Plasa data.
/// @param contractAddress The address of the Plasa contract.
/// @param namesContract The address of the Names contract.
struct PlasaData {
address contractAddress;
address namesContract;
}

/// @notice Struct to hold Plasa user data.
/// @param isRegistered Whether the user is registered.
/// @param username The username of the user.
struct PlasaUser {
bool isRegistered;
string username;
}

/// @notice Struct to hold Plasa view data.
/// @param data The Plasa data.
/// @param user The Plasa user data.
struct PlasaView {
PlasaData data;
PlasaUser user;
}

/// @notice Retrieves the Plasa view data.
/// @return PlasaView The Plasa view data.
function getPlasaView() external view returns (PlasaView memory);
}

0 comments on commit fc43c29

Please sign in to comment.