From 8ae0dfe5292a065385d8317363b50efaf762ffba Mon Sep 17 00:00:00 2001 From: bout3fiddy <11488427+bout3fiddy@users.noreply.github.com> Date: Wed, 20 Mar 2024 10:17:46 +0100 Subject: [PATCH] added update_id method --- contracts/AddressProviderNG.vy | 52 +++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/contracts/AddressProviderNG.vy b/contracts/AddressProviderNG.vy index df0550f..af9d453 100644 --- a/contracts/AddressProviderNG.vy +++ b/contracts/AddressProviderNG.vy @@ -138,15 +138,15 @@ def add_new_tags(_new_tags: DynArray[String[64], 20]): @external def add_new_id( - _address: address, _id: uint256, + _address: address, _tags: DynArray[String[64], 20], _description: String[64], ): """ @notice Enter a new registry item - @param _address Address assigned to the _id @param _id Address assigned to the input _id + @param _address Address assigned to the _id @param _tags tags defining the entry. e.g. ['StableSwap', 'Factory'] Entry can have a maximum of 20 tags. Tags need to be added to the AddressProvider via `add_new_tags` before id can be added. @@ -181,6 +181,50 @@ def add_new_id( log NewEntry(_id, _address, _description) +@external +def update_id( + _id: uint256, + _new_address: address, + _new_tags: DynArray[String[64], 20], + _new_description: String[64], +): + """ + @notice Update entries at an ID + @param _id Address assigned to the input _id + @param _new_address Address assigned to the _id + @param _new_tags tags defining the entry. e.g. ['StableSwap', 'Factory'] + Entry can have a maximum of 20 tags. Tags need to be + added to the AddressProvider via `add_new_tags` before id can be added. + @param _new_description Human-readable description of the identifier + """ + assert msg.sender == self.admin # dev: admin-only function + assert self.check_id_exists[_id] # dev: id does not exist + assert len(_new_tags) > 0 # dev: entry needs at least one tag + + # Update entry at _id: + self.get_id_info[_id].addr = _new_address + self.get_id_info[_id].description = _new_description + + # Update id > tag mapping + _old_tags: DynArray[String[64], 20] = self.get_id_info[_id].tags + for _tag in _new_tags: + assert self.check_tag_exists[_tag] # dev: unauthorised tag + key: bytes32 = keccak256(concat(uint2str(_id), _tag)) + if not self.id_tag_mapping[key]: + self.id_tag_mapping[key] = True + + # Remove mapping if tag was removed: + for _tag in _old_tags: + key: bytes32 = keccak256(concat(uint2str(_id), _tag)) + self.id_tag_mapping[key] = False + + # Update tags: + self.get_id_info[_id].tags = _new_tags + + # Update metadata (version, update time): + self._update_entry_metadata(_id) + + @external def update_address(_id: uint256, _address: address): """ @@ -289,6 +333,7 @@ def remove_tags(_tags_to_remove: DynArray[String[64], 20]): e.g. ['StableSwap', 'CryptoSwap', ...] """ + # Remove tags from mapping and invalidate each tag: for _tag in _tags_to_remove: # Check if tag is valid @@ -363,5 +408,4 @@ def revert_transfer_ownership() -> bool: return True -# TODO: Add update_id that consolidates all updates into a single method. -# TODO: Separate tags away from AddressInfo \ No newline at end of file +# TODO: Separate tags away from AddressInfo