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 Name | Type | Description |
---|---|---|
_user | address | The address of the current owner of the _identity who is removing the metadata. |
_nonce | uint256 | The owner's (_user ) nonce specific to the MNS contract (mateNameServiceNonce ) for this removeCustomMetadata action's replay protection. |
_identity | string | The registered identity (e.g., username) from which the custom metadata will be removed. |
_key | uint256 | The index (zero-based) of the specific custom metadata entry to be removed from the identity's list. |
_priorityFeeForFisher | uint256 | Optional fee (in MATE) paid by the owner (_user ) to the msg.sender (staker executor) via the EVVM contract for prioritized processing of this transaction. |
_signature | bytes | The EIP-191 signature from the owner (_user ) authorizing this remove metadata action (signing _identity , _key , _nonce ). |
_nonce_Evvm | uint256 | Required. The owner's (_user ) nonce for the EVVM payMateStaker call used to pay the Metadata Removal Fee + Priority Fee. |
_priority_Evvm | bool | Required. Priority flag (sync/async) for the EVVM payMateStaker call paying the fees. |
_signature_Evvm | bytes | Required. The owner's (_user ) signature authorizing the EVVM payMateStaker call paying the Metadata Removal Fee + Priority Fee. |
- 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:
- The user sends the payment request to the fishing spot
- The fisher captures the transaction and validates all parameters
- The fisher submits the transaction to the contract for processing
Direct Execution
When the executor is the user or a service:
- 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.
-
Identity Ownership Verification: Checks if the provided
_user
address is the registered owner of the_identity
. Reverts if_user
is not the owner. -
MNS Nonce Verification: Checks if the provided
_nonce
is unused for the_user
(the owner) using theverifyIfNonceIsAvailable
modifier. Reverts if the nonce is already used. -
Executor Staker Verification: Verifies that the
msg.sender
(the executor submitting the transaction) is an sMATE staker by callingisMateStaker()
on the associated EVVM contract. Reverts ifmsg.sender
is not a staker. -
Remove Custom Metadata Signature Validation: Verifies the
_signature
provided by_user
(the owner) against the reconstructed message hash usingverifyMessageSignedForRemoveCustomMetadata
. Reverts if the signature is invalid according to the Remove Custom Metadata Signature Structure. -
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. -
Payment execution: Calls
makePay
to transfer the payment of 10 times of the mate reward using thegetPriceToAddCustomMetadata
function and_priorityFee
of MATE tokens from_user
to the service via the EVVM contract. Reverts if the payment fails. -
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 tocount - 2
. - In each iteration, copies the metadata entry from index
i + 1
to indexi
(identityCustomMetadata[_identity][i] = identityCustomMetadata[_identity][i + 1]
).
- Iterates from
- 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
.
- Retrieves the current count:
-
Check Position: It checks if the
_key
to remove is equal to the current metadata count (customMetadataMaxSlots
). -
Handle Removal:
- If
_key == customMetadataMaxSlots
(Case 1): Directlydelete
the metadata entry atidentityCustomMetadata[_identity][_key]
. - Else (
_key < customMetadataMaxSlots
) (Case 2):- Shift Left: Loop from
i = _key
up tocustomMetadataMaxSlots - 1
. Move the element from indexi + 1
to indexi
. This overwrites the element at_key
and shifts subsequent elements one position left. - Clean Last Slot:
delete
the element at indexcustomMetadataMaxSlots
(clearing the original data from the slot that was effectively moved).
- Shift Left: Loop from
- If
-
Decrement Count: Decrease
identityDetails[_identity].customMetadataMaxSlots
by 1 to reflect the removal. -
Reward Distribution (to Executor): Calls an internal helper function (e.g.,
makeCaPay
) to distribute rewards in MATE tokens directly tomsg.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.
- A base MATE reward share derived from the metadata fee ( 5 *
-
Nonce Management: Marks the MNS
_nonce
(provided as an input parameter for this transaction) as used for the_user
address within themateNameServiceNonce
mapping.