跳到主要内容

_namehash

Contract: JBProjectHandles​‌

Returns a namehash for an ENS name.

See https://eips.ethereum.org/EIPS/eip-137.

Definition

function _namehash(string[] memory _ensNameParts) internal pure returns (bytes32 namehash) { ... }
  • Arguments:
    • _ensNameParts is the parts of an ENS name to hash.
  • The view function can be accessed externally by anyone.
  • The view function does not alter state on the blockchain.
  • The function returns the namehash for an ENS name parts.

Body

  1. Encode the trailing "eth" into the hash.

    // Hash the trailing "eth" suffix.
    namehash = keccak256(abi.encodePacked(namehash, keccak256(abi.encodePacked('eth'))));
  2. Get the number of parts there are to iterate over.

    // Get a reference to the number of parts are in the ENS name.
    uint256 _nameLength = _ensNameParts.length;
  3. Loop through each part, encoding them each into the hash in sequential order from the base name through each subdomain.

    // Hash each part.
    for (uint256 _i = 0; _i < _nameLength; ) {
    namehash = keccak256(
    abi.encodePacked(namehash, keccak256(abi.encodePacked(_ensNameParts[_i])))
    );
    unchecked {
    ++_i;
    }
    }