Skip to main content

Remove Custom Metadata Function

This section details the removeCustomMetadata function within the MNS service. This function allows the current owner (_user) of a registered identity (_identity, typically a username) to remove a specific custom metadata entry identified by its index (_key).

To remove custom metadata, the identity owner must authorize the action with a signature and pay a fee (typically 10 times the base MATE reward, determined by a function like getPriceToRemoveCustomMetadata()) via the EVVM contract. An optional priority fee can also be paid to the executor. This function must be executed by an sMATE staker (msg.sender).

Function Type: external
Function Signature: removeCustomMetadata(address,uint256,string,uint256,uint256,bytes,uint256,bool,bytes)
Function Selector: 0x8001a999

Parameters

Parameter NameTypeDescription
_useraddressThe address of the current owner of the _identity who is removing the metadata.
_nonceuint256The owner's (_user) nonce specific to the MNS contract (mateNameServiceNonce) for this removeCustomMetadata action's replay protection.
_identitystringThe registered identity (e.g., username) from which the custom metadata will be removed.
_keyuint256The index (zero-based) of the specific custom metadata entry to be removed from the identity's list.
_priorityFeeForFisheruint256Optional fee (in MATE) paid by the owner (_user) to the msg.sender (staker executor) via the EVVM contract for prioritized processing of this transaction.
_signaturebytesThe EIP-191 signature from the owner (_user) authorizing this remove metadata action (signing _identity, _key, _nonce).
_nonce_Evvmuint256Required. The owner's (_user) nonce for the EVVM payMateStaker call used to pay the Metadata Removal Fee + Priority Fee.
_priority_EvvmboolRequired. Priority flag (sync/async) for the EVVM payMateStaker call paying the fees.
_signature_EvvmbytesRequired. The owner's (_user) signature authorizing the EVVM payMateStaker call paying the Metadata Removal Fee + Priority Fee.
note
  • The EVVM payment signature (_signature_Evvm) covers the total amount (calculated Metadata Fee + _priorityFeeForFisher) and is paid by the identity owner (_user). It uses the Single Payment Signature Structure. Since a metadata fee is always required, these EVVM parameters are mandatory.
  • The MNS add custom metadata signature (_signature) must be generated by the current owner (_user) and follows the Remove Custom Metadata Signature Structure.

Execution Methods

This function must be executed by an address (msg.sender) that is an sMATE staker.

Fisher Execution

When the executor is the fisher:

  1. The user sends the payment request to the fishing spot
  2. The fisher captures the transaction and validates all parameters
  3. The fisher submits the transaction to the contract for processing

Direct Execution

When the executor is the user or a service:

  1. The user/service submits their transaction directly to the contract

Workflow

Failure at validation steps typically reverts the transaction. The steps execute in the specified order.

  1. Identity Ownership Verification: Checks if the provided _user address is the registered owner of the _identity. Reverts if _user is not the owner.

  2. MNS Nonce Verification: Checks if the provided _nonce is unused for the _user (the owner) using the verifyIfNonceIsAvailable modifier. Reverts if the nonce is already used.

  3. Executor Staker Verification: Verifies that the msg.sender (the executor submitting the transaction) is an sMATE staker by calling isMateStaker() on the associated EVVM contract. Reverts if msg.sender is not a staker.

  4. Remove Custom Metadata Signature Validation: Verifies the _signature provided by _user (the owner) against the reconstructed message hash using verifyMessageSignedForRemoveCustomMetadata. Reverts if the signature is invalid according to the Remove Custom Metadata Signature Structure.

  5. Custom Metadata Index Validation: Checks that the provided _key (index) is valid, meaning it is less than the current number of metadata entries for the _identity (_key < identityDetails[_identity].customMetadataMaxSlots). Reverts if the index is out of bounds.

  6. Payment execution: Calls makePay to transfer the payment of 10 times of the mate reward using the getPriceToAddCustomMetadata function and _priorityFee of MATE tokens from _user to the service via the EVVM contract. Reverts if the payment fails.

  7. Custom Metadata Removal: Removes the metadata entry at the specified _key index for the _identity. This involves shifting subsequent elements left to fill the gap if the removed element was not the last one:

    • Retrieves the current count: count = identityDetails[_identity].customMetadataMaxSlots.
    • If _key < count - 1 (Not the last element):
      • Iterates from i = _key up to count - 2.
      • In each iteration, copies the metadata entry from index i + 1 to index i (identityCustomMetadata[_identity][i] = identityCustomMetadata[_identity][i + 1]).
    • Delete Last Slot: Deletes the entry at the now-last occupied index (identityCustomMetadata[_identity][count - 1]) to clear the duplicated data or the original last element.
    • Decrement Count: Decreases the metadata count: identityDetails[_identity].customMetadataMaxSlots = count - 1.
  8. Check Position: It checks if the _key to remove is equal to the current metadata count (customMetadataMaxSlots).

  9. Handle Removal:

    • If _key == customMetadataMaxSlots (Case 1): Directly delete the metadata entry at identityCustomMetadata[_identity][_key].
    • Else (_key < customMetadataMaxSlots) (Case 2):
      • Shift Left: Loop from i = _key up to customMetadataMaxSlots - 1. Move the element from index i + 1 to index i. This overwrites the element at _key and shifts subsequent elements one position left.
      • Clean Last Slot: delete the element at index customMetadataMaxSlots (clearing the original data from the slot that was effectively moved).
  10. Decrement Count: Decrease identityDetails[_identity].customMetadataMaxSlots by 1 to reflect the removal.

  11. Reward Distribution (to Executor): Calls an internal helper function (e.g., makeCaPay) to distribute rewards in MATE tokens directly to msg.sender (the executor). The rewards typically consist of:

    • A base MATE reward share derived from the metadata fee ( 5 * seeMateReward()). (Note: This implies 50% of the standard 10x fee goes to the executor as reward, verify exact distribution).
    • The full _priorityFeeForFisher, if it was greater than zero and successfully paid in Step 6.
  12. Nonce Management: Marks the MNS _nonce (provided as an input parameter for this transaction) as used for the _user address within the mateNameServiceNonce mapping.