contract SmartLockerRegistrar {

    // forward registrar
    mapping(address=>bytes32) registrar;

    // reverse registrar
    mapping(bytes32=>address) reverseRegistrar;

    // fallback function (external non-payable)
    function() external {}

    // events
    event SmartLockerCreated(bytes32 name, address smartLockerAddress);

    // create new smart locker with given name and keyname (external payable)
    function createSmartLocker(bytes32 name, bytes32 keyname) external payable
        returns (address) {

        // require name not null
        require(name != bytes32(0));

        // require name not already exist
        require(reverseRegistrar[name] == address(0));

        // require keyname not null
        require(keyname != bytes32(0));

        // deploy a new smart locker and send all value
        SmartLocker smartLocker = (new SmartLocker).value(msg.value)(msg.sender, keyname);

        // register the smart locker address with the given name
        address smartLockerAddress = address(smartLocker);
        registrar[smartLockerAddress] = name;

        // add corresponding entry to the reverse registrar
        reverseRegistrar[name] = smartLockerAddress;

        // emit event
        emit SmartLockerCreated(name, smartLockerAddress);

        // return the smart locker address
        return smartLockerAddress;
    }

    // get the name of the smart locker with given address (external view)
    function getName(address smartLockerAddress) external view
        returns (bytes32) {

        return registrar[smartLockerAddress];
    }

    // get the address of the smart locker with given name (external view)
    function getAddress(bytes32 name) external view
        returns (address) {

        return reverseRegistrar[name];
    }
}
function createSmartLocker(bytes32 name, bytes32 keyname) external payable
    returns (address) {

    // require name not null
    require(name != bytes32(0));

    // require name not already exist
    require(reverseRegistrar[name] == address(0));

    // require keyname not null
    require(keyname != bytes32(0));

    // deploy a new smart locker and send all value
    SmartLocker smartLocker = (new SmartLocker).value(msg.value)(msg.sender, keyname);

    // register the smart locker address with the given name
    address smartLockerAddress = address(smartLocker);
    registrar[smartLockerAddress] = name;

    // add corresponding entry to the reverse registrar
    reverseRegistrar[name] = smartLockerAddress;

    // emit event
    emit SmartLockerCreated(name, smartLockerAddress);

    // return the smart locker address
    return smartLockerAddress;
}

// create new smart locker with given name and keyname (external payable)