Commit 5ad62a7e authored by smartcontracts's avatar smartcontracts Committed by GitHub

cleanup: Minor cleanup to address manager (#372)

Co-authored-by: default avatarMaurelian <maurelian@protonmail.ch>
parent b42fe20c
...@@ -18,9 +18,10 @@ contract Lib_AddressManager is Ownable { ...@@ -18,9 +18,10 @@ contract Lib_AddressManager is Ownable {
address _newAddress address _newAddress
); );
/*******************************************
* Contract Variables: Internal Accounting * /*************
*******************************************/ * Variables *
*************/
mapping (bytes32 => address) private addresses; mapping (bytes32 => address) private addresses;
...@@ -29,6 +30,11 @@ contract Lib_AddressManager is Ownable { ...@@ -29,6 +30,11 @@ contract Lib_AddressManager is Ownable {
* Public Functions * * Public Functions *
********************/ ********************/
/**
* Changes the address associated with a particular name.
* @param _name String name to associate an address with.
* @param _address Address to associate with the name.
*/
function setAddress( function setAddress(
string memory _name, string memory _name,
address _address address _address
...@@ -36,16 +42,27 @@ contract Lib_AddressManager is Ownable { ...@@ -36,16 +42,27 @@ contract Lib_AddressManager is Ownable {
public public
onlyOwner onlyOwner
{ {
emit AddressSet(_name, _address);
addresses[_getNameHash(_name)] = _address; addresses[_getNameHash(_name)] = _address;
emit AddressSet(
_name,
_address
);
} }
/**
* Retrieves the address associated with a given name.
* @param _name Name to retrieve an address for.
* @return Address associated with the given name.
*/
function getAddress( function getAddress(
string memory _name string memory _name
) )
public public
view view
returns (address) returns (
address
)
{ {
return addresses[_getNameHash(_name)]; return addresses[_getNameHash(_name)];
} }
...@@ -55,13 +72,18 @@ contract Lib_AddressManager is Ownable { ...@@ -55,13 +72,18 @@ contract Lib_AddressManager is Ownable {
* Internal Functions * * Internal Functions *
**********************/ **********************/
/**
* Computes the hash of a name.
* @param _name Name to compute a hash for.
* @return Hash of the given name.
*/
function _getNameHash( function _getNameHash(
string memory _name string memory _name
) )
internal internal
pure pure
returns ( returns (
bytes32 _hash bytes32
) )
{ {
return keccak256(abi.encodePacked(_name)); return keccak256(abi.encodePacked(_name));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment