Skip to content

Commit

Permalink
Little optimize (#164)
Browse files Browse the repository at this point in the history
* add `AddLine` evnt

* add more interface

* fix

* add `URI` event

* upgrade lib ormp

* update
  • Loading branch information
hujw77 authored Nov 3, 2023
1 parent 0e49a20 commit 0ed4058
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/ORMP
Submodule ORMP updated from 4bd8fe to 8c6361
13 changes: 13 additions & 0 deletions src/LineRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,33 @@ import "./interfaces/ILineMetadata.sol";
/// @notice LineRegistry will be deployed on each chain.
/// It is the registry of messageLine and can be used to verify whether the line has been registered.
contract LineRegistry is Ownable2Step {
event AddLine(string name, address line);

string[] private _names;
// lineName => lineAddress
mapping(string => address) private _lineLookup;

constructor(address dao) {
_transferOwnership(dao);
}

function count() public view returns (uint256) {
return _names.length;
}

function list() public view returns (string[] memory) {
return _names;
}

function getLine(string calldata name) external view returns (address) {
return _lineLookup[name];
}

function addLine(address line) external onlyOwner {
string memory name = ILineMetadata(line).name();
require(_lineLookup[name] == address(0), "Line name already exists");
_names.push(name);
_lineLookup[name] = line;
emit AddLine(name, line);
}
}
2 changes: 2 additions & 0 deletions src/interfaces/ILineMetadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
pragma solidity ^0.8.0;

interface ILineMetadata {
event URI(string uri);

/// @notice Get the line name, it's globally unique and immutable.
/// @return The MessageLine name.
function name() external view returns (string memory);
Expand Down
4 changes: 2 additions & 2 deletions src/lines/ORMPLine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import "ORMP/src/interfaces/IORMP.sol";
import "ORMP/src/user/Application.sol";
import "@openzeppelin/contracts/access/Ownable2Step.sol";

contract ORMPLine is BaseMessageLine, Application, LineLookup, Ownable2Step {
constructor(address dao, address ormp, string memory name) BaseMessageLine(name) Application(ormp) {
contract ORMPLine is Ownable2Step, Application, BaseMessageLine, LineLookup {
constructor(address dao, address ormp, string memory name) Application(ormp) BaseMessageLine(name) {
_transferOwnership(dao);
}

Expand Down
1 change: 1 addition & 0 deletions src/lines/base/LineMetadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ contract LineMetadata is ILineMetadata {

function _setURI(string memory uri_) internal virtual {
_uri = uri_;
emit URI(uri_);
}

function name() public view virtual returns (string memory) {
Expand Down

0 comments on commit 0ed4058

Please sign in to comment.