Fix TransferSingle mint

Fix TransferSingle mint

import "./ERC1155.sol";
import "../interfaces/INFTFuseWrapper.sol";
import "../interfaces/ENS.sol";
import "../interfaces/BaseRegistrar.sol";
import "../interfaces/Resolver.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "./BytesUtil.sol";
import "hardhat/console.sol";

contract NFTFuseWrapper is ERC1155, INFTFuseWrapper {
    using BytesUtils for bytes;
    ENS public ens;
    BaseRegistrar public registrar;
    bytes4 public constant ERC721_RECEIVED = 0x150b7a02;

    bytes32 public constant ETH_NODE =
        0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae;
    bytes32 public constant ROOT_NODE =
        0x0000000000000000000000000000000000000000000000000000000000000000;

    constructor(ENS _ens, BaseRegistrar _registrar) {
        ens = _ens;
        registrar = _registrar;

        /* Burn CANNOT_REPLACE_SUBDOMAIN and CANNOT_UNWRAP fuses for ROOT_NODE and ETH_NODE */

        setData(
            uint256(ETH_NODE),
            address(0x0),
            uint96(CANNOT_REPLACE_SUBDOMAIN | CANNOT_UNWRAP)
        );
        setData(
            uint256(ROOT_NODE),
            address(0x0),
            uint96(CANNOT_REPLACE_SUBDOMAIN | CANNOT_UNWRAP)
        );
    }

    /**
     * @notice Checks if msg.sender is the owner or approved by the owner of a name
     * @param node namehash of the name to check
     */

    modifier ownerOnly(bytes32 node) {
        require(
            isOwnerOrApproved(node, msg.sender),
            "NFTFuseWrapper: msg.sender is not the owner or approved"
        );
        _;
    }

    /**
     * @notice Checks if owner or approved by owner
     * @param node namehash of the name to check
     * @param addr which address to check permissions for
     * @return whether or not is owner or approved
     */

    function isOwnerOrApproved(bytes32 node, address addr)
        public
        view
        override
        returns (bool)
    {
        return
            ownerOf(uint256(node)) == addr ||
            isApprovedForAll(ownerOf(uint256(node)), addr);
    }

    /**
     * @notice Gets fuse permissions for a specific name
     * @dev Fuses are represented by a uint96 where each permission is represented by 1 bit
     *      The interface has predefined fuses for all registry permissions, but additional
     *      fuses can be added for other use cases
     * @param node namehash of the name to check
     * @return A number that represents the permissions a name has
     */

    function getFuses(bytes32 node) public view returns (uint96) {
        (, uint96 fuses) = getData(uint256(node));
        return fuses;
    }

    /**
     * @notice Check whether a name can be unwrapped
     *
     * @param node namehash of the name to check
     * @return Boolean of whether or not can be wrapped
     */

    function canUnwrap(bytes32 node) public view returns (bool) {
        uint96 fuses = getFuses(node);
        return fuses & CANNOT_UNWRAP == 0;
    }

    /**
     * @notice Check whether a name can burn fuses
     *
     * @param node namehash of the name to check
     * @return Boolean of whether or not can burn fuses
     */

    function canBurnFuses(bytes32 node) public view returns (bool) {
        uint96 fuses = getFuses(node);
        return fuses & CANNOT_BURN_FUSES == 0;
    }

    /**
     * @notice Check whether a name can be transferred
     *
     * @param node namehash of the name to check
     * @return Boolean of whether or not can be transferred
     */

    function canTransfer(bytes32 node) public view returns (bool) {
        uint96 fuses = getFuses(node);
        return fuses & CANNOT_TRANSFER == 0;
    }

    /**
     * @notice Check whether a name can set the resolver
     *
     * @param node namehash of the name to check
     * @return Boolean of whether or not resolver can be set
     */

    function canSetResolver(bytes32 node) public view returns (bool) {
        uint96 fuses = getFuses(node);
        return fuses & CANNOT_SET_RESOLVER == 0;
    }

    /**
     * @notice Check whether a name can set the TTL
     *
     * @param node namehash of the name to check
     * @return Boolean of whether or not TTL can be set
     */

    function canSetTTL(bytes32 node) public view returns (bool) {
        uint96 fuses = getFuses(node);
        return fuses & CANNOT_SET_TTL == 0;
    }

    /**
     * @notice Check whether a name can create a subdomain
     * @dev Creating a subdomain is defined as a subdomain that has a 0x0 owner and a new owner is set
     * @param node namehash of the name to check
     * @return Boolean of whether or not subdomains can be created
     */

    function canCreateSubdomain(bytes32 node) public view returns (bool) {
        uint96 fuses = getFuses(node);
        return fuses & CANNOT_CREATE_SUBDOMAIN == 0;
    }

    /**
     * @notice Check whether a name can replace a subdomain
     * @dev Replacing a subdomain is defined as a subdomain that has an existing owner and is overwritten
     * @param node namehash of the name to check
     * @return Boolean of whether or not TTL can be set
     */

    function canReplaceSubdomain(bytes32 node) public view returns (bool) {
        uint96 fuses = getFuses(node);
        return fuses & CANNOT_REPLACE_SUBDOMAIN == 0;
    }

    /**
     * @notice Check whether a name can call setSubnodeOwner/setSubnodeRecord
     * @dev Checks both canCreateSubdomain and canReplaceSubdomain and whether not they have been burnt
     *      and checks whether the owner of the subdomain is 0x0 for creating or already exists for
     *      replacing a subdomain. If either conditions are true, then it is possible to call
     *      setSubnodeOwner
     * @param node namehash of the name to check
     * @param label labelhash of the name to check
     * @return Boolean of whether or not setSubnodeOwner/setSubnodeRecord can be called
     */

    function canCallSetSubnodeOwner(bytes32 node, bytes32 label)
        public
        view
        returns (bool)
    {
        bytes32 subnode = _makeNode(node, label);
        address owner = ens.owner(subnode);

        return
            (owner == address(0) && canCreateSubdomain(node)) ||
            (owner != address(0) && canReplaceSubdomain(node));
    }

    /**
     * @notice Wraps a .eth domain, creating a new token and sending the original ERC721 token to this *         contract
     * @dev Can be called by the owner of the name in the .eth registrar or an authorised caller on the *      registrar
     * @param label label as a string of the .eth domain to wrap
     * @param _fuses initial fuses to set
     * @param wrappedOwner Owner of the name in this contract
     */

    function wrapETH2LD(
        string calldata label,
        uint96 _fuses,
        address wrappedOwner
    ) public override {
        bytes32 labelhash = keccak256(bytes(label));
        bytes32 node = _makeNode(ETH_NODE, labelhash);
        uint256 tokenId = uint256(labelhash);
        address owner = registrar.ownerOf(tokenId);

        require(
            owner == msg.sender ||
                registrar.isApprovedForAll(owner, msg.sender) ||
                isApprovedForAll(owner, msg.sender),
            "NFTFuseWrapper: Sender is not owner or authorised by the owner or authorised on the .eth registrar"
        );
        // transfer the token from the user to this contract
        address currentOwner = registrar.ownerOf(tokenId);
        registrar.transferFrom(currentOwner, address(this), tokenId);

        // transfer the ens record back to the new owner (this contract)
        _wrapETH2LD(labelhash, node, _fuses, wrappedOwner);
    }

    /**
     * @notice Wraps a non .eth domain, of any kind. Could be a DNSSEC name vitalik.xyz or a subdomain
     * @dev Can be called by the owner in the registry or an authorised caller in the registry
     * @param parentNode parent namehash of the name to wrap e.g. vitalik.xyz would be namehash('xyz')
     * @param label label as a string of the .eth domain to wrap e.g. vitalik.xyz would be 'vitalik'
     * @param _fuses initial fuses to set represented as a number. Check getFuses() for more info
     * @param wrappedOwner Owner of the name in this contract
     */

    function wrap(
        bytes32 parentNode,
        string calldata label,
        uint96 _fuses,
        address wrappedOwner
    ) public override {
        bytes32 labelhash = keccak256(bytes(label));
        bytes32 node = _makeNode(parentNode, labelhash);
        _wrap(parentNode, labelhash, _fuses, wrappedOwner);
        address owner = ens.owner(node);

        require(
            owner == msg.sender ||
                ens.isApprovedForAll(owner, msg.sender) ||
                isApprovedForAll(owner, msg.sender),
            "NFTFuseWrapper: Domain is not owned by the sender"
        );
        ens.setOwner(node, address(this));
        emit Wrap(parentNode, label, _fuses, wrappedOwner);
    }

    /**
     * @notice Unwraps a .eth domain. e.g. vitalik.eth
     * @dev Can be called by the owner in the wrapper or an authorised caller in the wrapper
     * @param label label as a string of the .eth domain to wrap e.g. vitalik.xyz would be 'vitalik'
     * @param newRegistrant sets the owner in the .eth registrar to this address
     * @param newController sets the owner in the registry to this address
     */

    function unwrapETH2LD(
        bytes32 label,
        address newRegistrant,
        address newController
    ) public ownerOnly(_makeNode(ETH_NODE, label)) {
        _unwrap(ETH_NODE, label, newController);
        registrar.transferFrom(address(this), newRegistrant, uint256(label));
    }

    /**
     * @notice Unwraps a non .eth domain, of any kind. Could be a DNSSEC name vitalik.xyz or a subdomain
     * @dev Can be called by the owner in the wrapper or an authorised caller in the wrapper
     * @param parentNode parent namehash of the name to wrap e.g. vitalik.xyz would be namehash('xyz')
     * @param label label as a string of the .eth domain to wrap e.g. vitalik.xyz would be 'vitalik'
     * @param newController sets the owner in the registry to this address
     */

    function unwrap(
        bytes32 parentNode,
        bytes32 label,
        address newController
    ) public override ownerOnly(_makeNode(parentNode, label)) {
        require(
            parentNode != ETH_NODE,
            "NFTFuseWrapper: .eth names must be unwrapped with unwrapETH2LD()"
        );
        _unwrap(parentNode, label, newController);
    }

    /**
     * @notice Burns any fuse passed to this function for a name
     * @dev Fuse burns are always additive and will not unburn already burnt fuses
     * @param parentNode parent namehash of the name. e.g. vitalik.xyz would be namehash('xyz')
     * @param labelhash labelhash of the name. e.g. vitalik.xyz would be labelhash('vitalik')
     * @param _fuses Fuses you want to burn.
     */

    function burnFuses(
        bytes32 parentNode,
        bytes32 labelhash,
        uint96 _fuses
    ) public ownerOnly(_makeNode(parentNode, labelhash)) {
        bytes32 node = _makeNode(parentNode, labelhash);

        require(
            canBurnFuses(node),
            "NFTFuseWrapper: Fuse has been burned for burning fuses"
        );

        require(
            !canReplaceSubdomain(parentNode),
            "NFTFuseWrapper: Parent has not burned CAN_REPLACE_SUBDOMAIN fuse"
        );

        (address owner, uint96 fuses) = getData(uint256(node));

        setData(uint256(node), owner, fuses | _fuses);

        require(
            !canUnwrap(node),
            "NFTFuseWrapper: Domain has not burned unwrap fuse"
        );
    }

    /**
     * @notice Sets records for the subdomain in the ENS Registry
     * @param node namehash of the name
     * @param owner newOwner in the registry
     * @param resolver the resolver contract in the registry
     * @param ttl ttl in the registry
     */

    function setSubnodeRecord(
        bytes32 node,
        bytes32 label,
        address owner,
        address resolver,
        uint64 ttl
    ) public ownerOnly(node) {
        require(
            canCallSetSubnodeOwner(node, label),
            "NFTFuseWrapper: Fuse has been burned for creating or replacing a subdomain"
        );

        return ens.setSubnodeRecord(node, label, owner, resolver, ttl);
    }

    /**
     * @notice Sets the subnode owner in the registry
     * @param node parent namehash of the subnode
     * @param label labelhash of the subnode
     * @param owner newOwner in the registry
     */

    function setSubnodeOwner(
        bytes32 node,
        bytes32 label,
        address owner
    ) public override ownerOnly(node) returns (bytes32) {
        require(
            canCallSetSubnodeOwner(node, label),
            "NFTFuseWrapper: Fuse has been burned for creating or replacing a subdomain"
        );

        ens.setSubnodeOwner(node, label, owner);
    }

    /**
     * @notice Sets the subdomain owner in the registry and then wraps the subdomain
     * @param parentNode parent namehash of the subdomain
     * @param label label of the subdomain as a string
     * @param newOwner newOwner in the registry
     * @param _fuses initial fuses for the wrapped subdomain
     */

    function setSubnodeOwnerAndWrap(
        bytes32 parentNode,
        string calldata label,
        address newOwner,
        uint96 _fuses
    ) public override returns (bytes32) {
        require(
            newOwner != address(this),
            "NFTFuseWrapper: newOwner cannot be the NFTFuseWrapper contract"
        );
        bytes32 labelhash = keccak256(bytes(label));
        setSubnodeOwner(parentNode, labelhash, address(this));
        _wrap(parentNode, labelhash, _fuses, newOwner);
        emit Wrap(parentNode, label, _fuses, newOwner);
    }

    /**
     * @notice Sets the subdomain owner in the registry with records and then wraps the subdomain
     * @param parentNode parent namehash of the subdomain
     * @param label label of the subdomain as a string
     * @param newOwner newOwner in the registry
     * @param resolver resolver contract in the registry
     * @param ttl ttl in the regsitry
     * @param _fuses initial fuses for the wrapped subdomain
     */

    function setSubnodeRecordAndWrap(
        bytes32 parentNode,
        string calldata label,
        address newOwner,
        address resolver,
        uint64 ttl,
        uint96 _fuses
    ) public override returns (bytes32) {
        require(
            newOwner != address(this),
            "NFTFuseWrapper: newOwner cannot be the NFTFuseWrapper contract"
        );
        bytes32 labelhash = keccak256(bytes(label));
        setSubnodeRecord(parentNode, labelhash, address(this), resolver, ttl);
        _wrap(parentNode, labelhash, _fuses, newOwner);
        emit Wrap(parentNode, label, _fuses, newOwner);
    }

    /**
     * @notice Sets records for the name in the ENS Registry
     * @param node namehash of the name to set a record for
     * @param owner newOwner in the registry
     * @param resolver the resolver contract
     * @param ttl ttl in the registry
     */

    function setRecord(
        bytes32 node,
        address owner,
        address resolver,
        uint64 ttl
    ) public ownerOnly(node) {
        require(
            canTransfer(node),
            "NFTFuseWrapper: Fuse is burned for transferring"
        );

        require(
            canSetResolver(node),
            "NFTFuseWrapper: Fuse is burned for setting resolver"
        );

        require(
            canSetTTL(node),
            "NFTFuseWrapper: Fuse is burned for setting TTL"
        );
        ens.setRecord(node, owner, resolver, ttl);
    }

    /**
     * @notice Sets resolver contract in the registry
     * @param node namehash of the name
     * @param resolver the resolver contract
     */

    function setResolver(bytes32 node, address resolver)
        public
        override
        ownerOnly(node)
    {
        require(
            canSetResolver(node),
            "NFTFuseWrapper: Fuse already burned for setting resolver"
        );
        ens.setResolver(node, resolver);
    }

    /**
     * @notice Sets TTL in the registry
     * @param node namehash of the name
     * @param ttl TTL in the registry
     */

    function setTTL(bytes32 node, uint64 ttl) public override ownerOnly(node) {
        require(
            canSetTTL(node),
            "NFTFuseWrapper: Fuse already burned for setting TTL"
        );
        ens.setTTL(node, ttl);
    }

    /**
     * @notice Sets TTL in the registry
     * @dev only callable by the .eth registrar
     * @param operator sender of the tx, either owner or approved caller
     * @param from owner of the token previously
     * @param tokenId namehash of the name
     * @param data data represents the fuses that will be passed when calling transferFrom on the
     *             .eth registrar
     */

    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) public returns (bytes4) {
        //check if it's the eth registrar ERC721
        uint96 fuses = 0;
        require(
            msg.sender == address(registrar),
            "NFTFuseWrapper: Wrapper only supports .eth ERC721 token transfers"
        );

        require(
            data.length == 0 || data.length == 12,
            "NFTFuseWrapper: Data is not of length 0 or 12"
        );

        if (data.length == 12) {
            fuses = data.readUint96(0);
        }

        bytes32 node = _makeNode(ETH_NODE, bytes32(tokenId));
        _wrapETH2LD(bytes32(tokenId), node, fuses, from);
        emit WrapETH2LD(bytes32(tokenId), fuses, from);
        return ERC721_RECEIVED;
    }

    /***** Internal functions */

    function _canTransfer(uint96 fuses) internal override returns (bool) {
        return fuses & CANNOT_TRANSFER == 0;
    }

    function _makeNode(bytes32 node, bytes32 label)
        private
        pure
        returns (bytes32)
    {
        return keccak256(abi.encodePacked(node, label));
    }

    function _mint(
        uint256 tokenId,
        address newOwner,
        uint96 fuses
    ) private {
        address owner = ownerOf(tokenId);
        require(owner == address(0), "ERC1155: mint of existing token");
        require(newOwner != address(0), "ERC1155: mint to the zero address");
        setData(tokenId, newOwner, fuses);
        emit TransferSingle(msg.sender, address(0x0), newOwner, tokenId, 1);
    }

    function _burn(uint256 tokenId) private {
        address owner = ownerOf(tokenId);
        // Clear fuses and set owner to 0
        setData(tokenId, address(0x0), 0);
        emit TransferSingle(msg.sender, owner, address(0x0), tokenId, 1);
    }

    function _wrap(
        bytes32 parentNode,
        bytes32 label,
        uint96 _fuses,
        address wrappedOwner
    ) private {
        require(
            parentNode != ETH_NODE,
            "NFTFuseWrapper: .eth domains need to use the wrapETH2LD"
        );

        bytes32 node = _makeNode(parentNode, label);

        _mint(uint256(node), wrappedOwner, _fuses);

        if (_fuses != CAN_DO_EVERYTHING) {
            require(
                !canReplaceSubdomain(parentNode),
                "NFTFuseWrapper: Cannot burn fuses: parent name can replace subdomain"
            );

            require(
                !canUnwrap(node),
                "NFTFuseWrapper: Cannot burn fuses: domain can be unwrapped"
            );
        }
    }

    function _wrapETH2LD(
        bytes32 label,
        bytes32 node,
        uint96 _fuses,
        address wrappedOwner
    ) private {
        // transfer the ens record back to the new owner (this contract)
        registrar.reclaim(uint256(label), address(this));
        // mint a new ERC1155 token with fuses

        address oldWrappedOwner = ownerOf(uint256(node));
        if (oldWrappedOwner != address(0)) {
            _burn(uint256(node));
        }
        _mint(uint256(node), wrappedOwner, _fuses);

        if (_fuses != CAN_DO_EVERYTHING) {
            require(
                !canUnwrap(node),
                "NFTFuseWrapper: Cannot burn fuses: domain can be unwrapped"
            );
        }

        emit WrapETH2LD(label, _fuses, wrappedOwner);
    }

    function _unwrap(
        bytes32 parentNode,
        bytes32 label,
        address newOwner
    ) private {
        bytes32 node = _makeNode(parentNode, label);
        require(
            newOwner != address(0x0),
            "NFTFuseWrapper: Target owner cannot be 0x0"
        );
        require(
            newOwner != address(this),
            "NFTFuseWrapper: Target owner cannot be the NFTFuseWrapper contract"
        );
        require(canUnwrap(node), "NFTFuseWrapper: Domain is not unwrappable");

        // burn token and fuse data
        _burn(uint256(node));
        ens.setOwner(node, newOwner);
        emit Unwrap(parentNode, label, newOwner);
    }
}

import "./ERC1155.sol";
import "../interfaces/INFTFuseWrapper.sol";
import "../interfaces/ENS.sol";
import "../interfaces/BaseRegistrar.sol";
import "../interfaces/Resolver.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "./BytesUtil.sol";
import "hardhat/console.sol";

contract NFTFuseWrapper is ERC1155, INFTFuseWrapper {
    using BytesUtils for bytes;
    ENS public ens;
    BaseRegistrar public registrar;
    bytes4 public constant ERC721_RECEIVED = 0x150b7a02;

    bytes32 public constant ETH_NODE =
        0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae;
    bytes32 public constant ROOT_NODE =
        0x0000000000000000000000000000000000000000000000000000000000000000;

    constructor(ENS _ens, BaseRegistrar _registrar) {
        ens = _ens;
        registrar = _registrar;

        /* Burn CANNOT_REPLACE_SUBDOMAIN and CANNOT_UNWRAP fuses for ROOT_NODE and ETH_NODE */

        setData(
            uint256(ETH_NODE),
            address(0x0),
            uint96(CANNOT_REPLACE_SUBDOMAIN | CANNOT_UNWRAP)
        );
        setData(
            uint256(ROOT_NODE),
            address(0x0),
            uint96(CANNOT_REPLACE_SUBDOMAIN | CANNOT_UNWRAP)
        );
    }

    /**
     * @notice Checks if msg.sender is the owner or approved by the owner of a name
     * @param node namehash of the name to check
     */

    modifier ownerOnly(bytes32 node) {
        require(
            isOwnerOrApproved(node, msg.sender),
            "NFTFuseWrapper: msg.sender is not the owner or approved"
        );
        _;
    }

    /**
     * @notice Checks if owner or approved by owner
     * @param node namehash of the name to check
     * @param addr which address to check permissions for
     * @return whether or not is owner or approved
     */

    function isOwnerOrApproved(bytes32 node, address addr)
        public
        view
        override
        returns (bool)
    {
        return
            ownerOf(uint256(node)) == addr ||
            isApprovedForAll(ownerOf(uint256(node)), addr);
    }

    /**
     * @notice Gets fuse permissions for a specific name
     * @dev Fuses are represented by a uint96 where each permission is represented by 1 bit
     *      The interface has predefined fuses for all registry permissions, but additional
     *      fuses can be added for other use cases
     * @param node namehash of the name to check
     * @return A number that represents the permissions a name has
     */

    function getFuses(bytes32 node) public view returns (uint96) {
        (, uint96 fuses) = getData(uint256(node));
        return fuses;
    }

    /**
     * @notice Check whether a name can be unwrapped
     *
     * @param node namehash of the name to check
     * @return Boolean of whether or not can be wrapped
     */

    function canUnwrap(bytes32 node) public view returns (bool) {
        uint96 fuses = getFuses(node);
        return fuses & CANNOT_UNWRAP == 0;
    }

    /**
     * @notice Check whether a name can burn fuses
     *
     * @param node namehash of the name to check
     * @return Boolean of whether or not can burn fuses
     */

    function canBurnFuses(bytes32 node) public view returns (bool) {
        uint96 fuses = getFuses(node);
        return fuses & CANNOT_BURN_FUSES == 0;
    }

    /**
     * @notice Check whether a name can be transferred
     *
     * @param node namehash of the name to check
     * @return Boolean of whether or not can be transferred
     */

    function canTransfer(bytes32 node) public view returns (bool) {
        uint96 fuses = getFuses(node);
        return fuses & CANNOT_TRANSFER == 0;
    }

    /**
     * @notice Check whether a name can set the resolver
     *
     * @param node namehash of the name to check
     * @return Boolean of whether or not resolver can be set
     */

    function canSetResolver(bytes32 node) public view returns (bool) {
        uint96 fuses = getFuses(node);
        return fuses & CANNOT_SET_RESOLVER == 0;
    }

    /**
     * @notice Check whether a name can set the TTL
     *
     * @param node namehash of the name to check
     * @return Boolean of whether or not TTL can be set
     */

    function canSetTTL(bytes32 node) public view returns (bool) {
        uint96 fuses = getFuses(node);
        return fuses & CANNOT_SET_TTL == 0;
    }

    /**
     * @notice Check whether a name can create a subdomain
     * @dev Creating a subdomain is defined as a subdomain that has a 0x0 owner and a new owner is set
     * @param node namehash of the name to check
     * @return Boolean of whether or not subdomains can be created
     */

    function canCreateSubdomain(bytes32 node) public view returns (bool) {
        uint96 fuses = getFuses(node);
        return fuses & CANNOT_CREATE_SUBDOMAIN == 0;
    }

    /**
     * @notice Check whether a name can replace a subdomain
     * @dev Replacing a subdomain is defined as a subdomain that has an existing owner and is overwritten
     * @param node namehash of the name to check
     * @return Boolean of whether or not TTL can be set
     */

    function canReplaceSubdomain(bytes32 node) public view returns (bool) {
        uint96 fuses = getFuses(node);
        return fuses & CANNOT_REPLACE_SUBDOMAIN == 0;
    }

    /**
     * @notice Check whether a name can call setSubnodeOwner/setSubnodeRecord
     * @dev Checks both canCreateSubdomain and canReplaceSubdomain and whether not they have been burnt
     *      and checks whether the owner of the subdomain is 0x0 for creating or already exists for
     *      replacing a subdomain. If either conditions are true, then it is possible to call
     *      setSubnodeOwner
     * @param node namehash of the name to check
     * @param label labelhash of the name to check
     * @return Boolean of whether or not setSubnodeOwner/setSubnodeRecord can be called
     */

    function canCallSetSubnodeOwner(bytes32 node, bytes32 label)
        public
        view
        returns (bool)
    {
        bytes32 subnode = _makeNode(node, label);
        address owner = ens.owner(subnode);

        return
            (owner == address(0) && canCreateSubdomain(node)) ||
            (owner != address(0) && canReplaceSubdomain(node));
    }

    /**
     * @notice Wraps a .eth domain, creating a new token and sending the original ERC721 token to this *         contract
     * @dev Can be called by the owner of the name in the .eth registrar or an authorised caller on the *      registrar
     * @param label label as a string of the .eth domain to wrap
     * @param _fuses initial fuses to set
     * @param wrappedOwner Owner of the name in this contract
     */

    function wrapETH2LD(
        string calldata label,
        uint96 _fuses,
        address wrappedOwner
    ) public override {
        bytes32 labelhash = keccak256(bytes(label));
        bytes32 node = _makeNode(ETH_NODE, labelhash);
        uint256 tokenId = uint256(labelhash);
        address owner = registrar.ownerOf(tokenId);

        require(
            owner == msg.sender ||
                registrar.isApprovedForAll(owner, msg.sender) ||
                isApprovedForAll(owner, msg.sender),
            "NFTFuseWrapper: Sender is not owner or authorised by the owner or authorised on the .eth registrar"
        );
        // transfer the token from the user to this contract
        address currentOwner = registrar.ownerOf(tokenId);
        registrar.transferFrom(currentOwner, address(this), tokenId);

        // transfer the ens record back to the new owner (this contract)
        _wrapETH2LD(labelhash, node, _fuses, wrappedOwner);
    }

    /**
     * @notice Wraps a non .eth domain, of any kind. Could be a DNSSEC name vitalik.xyz or a subdomain
     * @dev Can be called by the owner in the registry or an authorised caller in the registry
     * @param parentNode parent namehash of the name to wrap e.g. vitalik.xyz would be namehash('xyz')
     * @param label label as a string of the .eth domain to wrap e.g. vitalik.xyz would be 'vitalik'
     * @param _fuses initial fuses to set represented as a number. Check getFuses() for more info
     * @param wrappedOwner Owner of the name in this contract
     */

    function wrap(
        bytes32 parentNode,
        string calldata label,
        uint96 _fuses,
        address wrappedOwner
    ) public override {
        bytes32 labelhash = keccak256(bytes(label));
        bytes32 node = _makeNode(parentNode, labelhash);
        _wrap(parentNode, labelhash, _fuses, wrappedOwner);
        address owner = ens.owner(node);

        require(
            owner == msg.sender ||
                ens.isApprovedForAll(owner, msg.sender) ||
                isApprovedForAll(owner, msg.sender),
            "NFTFuseWrapper: Domain is not owned by the sender"
        );
        ens.setOwner(node, address(this));
        emit Wrap(parentNode, label, _fuses, wrappedOwner);
    }

    /**
     * @notice Unwraps a .eth domain. e.g. vitalik.eth
     * @dev Can be called by the owner in the wrapper or an authorised caller in the wrapper
     * @param label label as a string of the .eth domain to wrap e.g. vitalik.xyz would be 'vitalik'
     * @param newRegistrant sets the owner in the .eth registrar to this address
     * @param newController sets the owner in the registry to this address
     */

    function unwrapETH2LD(
        bytes32 label,
        address newRegistrant,
        address newController
    ) public ownerOnly(_makeNode(ETH_NODE, label)) {
        _unwrap(ETH_NODE, label, newController);
        registrar.transferFrom(address(this), newRegistrant, uint256(label));
    }

    /**
     * @notice Unwraps a non .eth domain, of any kind. Could be a DNSSEC name vitalik.xyz or a subdomain
     * @dev Can be called by the owner in the wrapper or an authorised caller in the wrapper
     * @param parentNode parent namehash of the name to wrap e.g. vitalik.xyz would be namehash('xyz')
     * @param label label as a string of the .eth domain to wrap e.g. vitalik.xyz would be 'vitalik'
     * @param newController sets the owner in the registry to this address
     */

    function unwrap(
        bytes32 parentNode,
        bytes32 label,
        address newController
    ) public override ownerOnly(_makeNode(parentNode, label)) {
        require(
            parentNode != ETH_NODE,
            "NFTFuseWrapper: .eth names must be unwrapped with unwrapETH2LD()"
        );
        _unwrap(parentNode, label, newController);
    }

    /**
     * @notice Burns any fuse passed to this function for a name
     * @dev Fuse burns are always additive and will not unburn already burnt fuses
     * @param parentNode parent namehash of the name. e.g. vitalik.xyz would be namehash('xyz')
     * @param labelhash labelhash of the name. e.g. vitalik.xyz would be labelhash('vitalik')
     * @param _fuses Fuses you want to burn.
     */

    function burnFuses(
        bytes32 parentNode,
        bytes32 labelhash,
        uint96 _fuses
    ) public ownerOnly(_makeNode(parentNode, labelhash)) {
        bytes32 node = _makeNode(parentNode, labelhash);

        require(
            canBurnFuses(node),
            "NFTFuseWrapper: Fuse has been burned for burning fuses"
        );

        require(
            !canReplaceSubdomain(parentNode),
            "NFTFuseWrapper: Parent has not burned CAN_REPLACE_SUBDOMAIN fuse"
        );

        (address owner, uint96 fuses) = getData(uint256(node));

        setData(uint256(node), owner, fuses | _fuses);

        require(
            !canUnwrap(node),
            "NFTFuseWrapper: Domain has not burned unwrap fuse"
        );
    }

    /**
     * @notice Sets records for the subdomain in the ENS Registry
     * @param node namehash of the name
     * @param owner newOwner in the registry
     * @param resolver the resolver contract in the registry
     * @param ttl ttl in the registry
     */

    function setSubnodeRecord(
        bytes32 node,
        bytes32 label,
        address owner,
        address resolver,
        uint64 ttl
    ) public ownerOnly(node) {
        require(
            canCallSetSubnodeOwner(node, label),
            "NFTFuseWrapper: Fuse has been burned for creating or replacing a subdomain"
        );

        return ens.setSubnodeRecord(node, label, owner, resolver, ttl);
    }

    /**
     * @notice Sets the subnode owner in the registry
     * @param node parent namehash of the subnode
     * @param label labelhash of the subnode
     * @param owner newOwner in the registry
     */

    function setSubnodeOwner(
        bytes32 node,
        bytes32 label,
        address owner
    ) public override ownerOnly(node) returns (bytes32) {
        require(
            canCallSetSubnodeOwner(node, label),
            "NFTFuseWrapper: Fuse has been burned for creating or replacing a subdomain"
        );

        ens.setSubnodeOwner(node, label, owner);
    }

    /**
     * @notice Sets the subdomain owner in the registry and then wraps the subdomain
     * @param parentNode parent namehash of the subdomain
     * @param label label of the subdomain as a string
     * @param newOwner newOwner in the registry
     * @param _fuses initial fuses for the wrapped subdomain
     */

    function setSubnodeOwnerAndWrap(
        bytes32 parentNode,
        string calldata label,
        address newOwner,
        uint96 _fuses
    ) public override returns (bytes32) {
        require(
            newOwner != address(this),
            "NFTFuseWrapper: newOwner cannot be the NFTFuseWrapper contract"
        );
        bytes32 labelhash = keccak256(bytes(label));
        setSubnodeOwner(parentNode, labelhash, address(this));
        _wrap(parentNode, labelhash, _fuses, newOwner);
        emit Wrap(parentNode, label, _fuses, newOwner);
    }

    /**
     * @notice Sets the subdomain owner in the registry with records and then wraps the subdomain
     * @param parentNode parent namehash of the subdomain
     * @param label label of the subdomain as a string
     * @param newOwner newOwner in the registry
     * @param resolver resolver contract in the registry
     * @param ttl ttl in the regsitry
     * @param _fuses initial fuses for the wrapped subdomain
     */

    function setSubnodeRecordAndWrap(
        bytes32 parentNode,
        string calldata label,
        address newOwner,
        address resolver,
        uint64 ttl,
        uint96 _fuses
    ) public override returns (bytes32) {
        require(
            newOwner != address(this),
            "NFTFuseWrapper: newOwner cannot be the NFTFuseWrapper contract"
        );
        bytes32 labelhash = keccak256(bytes(label));
        setSubnodeRecord(parentNode, labelhash, address(this), resolver, ttl);
        _wrap(parentNode, labelhash, _fuses, newOwner);
        emit Wrap(parentNode, label, _fuses, newOwner);
    }

    /**
     * @notice Sets records for the name in the ENS Registry
     * @param node namehash of the name to set a record for
     * @param owner newOwner in the registry
     * @param resolver the resolver contract
     * @param ttl ttl in the registry
     */

    function setRecord(
        bytes32 node,
        address owner,
        address resolver,
        uint64 ttl
    ) public ownerOnly(node) {
        require(
            canTransfer(node),
            "NFTFuseWrapper: Fuse is burned for transferring"
        );

        require(
            canSetResolver(node),
            "NFTFuseWrapper: Fuse is burned for setting resolver"
        );

        require(
            canSetTTL(node),
            "NFTFuseWrapper: Fuse is burned for setting TTL"
        );
        ens.setRecord(node, owner, resolver, ttl);
    }

    /**
     * @notice Sets resolver contract in the registry
     * @param node namehash of the name
     * @param resolver the resolver contract
     */

    function setResolver(bytes32 node, address resolver)
        public
        override
        ownerOnly(node)
    {
        require(
            canSetResolver(node),
            "NFTFuseWrapper: Fuse already burned for setting resolver"
        );
        ens.setResolver(node, resolver);
    }

    /**
     * @notice Sets TTL in the registry
     * @param node namehash of the name
     * @param ttl TTL in the registry
     */

    function setTTL(bytes32 node, uint64 ttl) public override ownerOnly(node) {
        require(
            canSetTTL(node),
            "NFTFuseWrapper: Fuse already burned for setting TTL"
        );
        ens.setTTL(node, ttl);
    }

    /**
     * @notice Sets TTL in the registry
     * @dev only callable by the .eth registrar
     * @param operator sender of the tx, either owner or approved caller
     * @param from owner of the token previously
     * @param tokenId namehash of the name
     * @param data data represents the fuses that will be passed when calling transferFrom on the
     *             .eth registrar
     */

    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) public returns (bytes4) {
        //check if it's the eth registrar ERC721
        uint96 fuses = 0;
        require(
            msg.sender == address(registrar),
            "NFTFuseWrapper: Wrapper only supports .eth ERC721 token transfers"
        );

        require(
            data.length == 0 || data.length == 12,
            "NFTFuseWrapper: Data is not of length 0 or 12"
        );

        if (data.length == 12) {
            fuses = data.readUint96(0);
        }

        bytes32 node = _makeNode(ETH_NODE, bytes32(tokenId));
        _wrapETH2LD(bytes32(tokenId), node, fuses, from);
        emit WrapETH2LD(bytes32(tokenId), fuses, from);
        return ERC721_RECEIVED;
    }

    /***** Internal functions */

    function _canTransfer(uint96 fuses) internal override returns (bool) {
        return fuses & CANNOT_TRANSFER == 0;
    }

    function _makeNode(bytes32 node, bytes32 label)
        private
        pure
        returns (bytes32)
    {
        return keccak256(abi.encodePacked(node, label));
    }

    function _mint(
        uint256 tokenId,
        address newOwner,
        uint96 fuses
    ) private {
        address owner = ownerOf(tokenId);
        require(owner == address(0), "ERC1155: mint of existing token");
        require(newOwner != address(0), "ERC1155: mint to the zero address");
        setData(tokenId, newOwner, fuses);
        emit TransferSingle(msg.sender, owner, address(0x0), tokenId, 1);
    }

    function _burn(uint256 tokenId) private {
        address owner = ownerOf(tokenId);
        // Clear fuses and set owner to 0
        setData(tokenId, address(0x0), 0);
        emit TransferSingle(msg.sender, owner, address(0x0), tokenId, 1);
    }

    function _wrap(
        bytes32 parentNode,
        bytes32 label,
        uint96 _fuses,
        address wrappedOwner
    ) private {
        require(
            parentNode != ETH_NODE,
            "NFTFuseWrapper: .eth domains need to use the wrapETH2LD"
        );

        bytes32 node = _makeNode(parentNode, label);

        _mint(uint256(node), wrappedOwner, _fuses);

        if (_fuses != CAN_DO_EVERYTHING) {
            require(
                !canReplaceSubdomain(parentNode),
                "NFTFuseWrapper: Cannot burn fuses: parent name can replace subdomain"
            );

            require(
                !canUnwrap(node),
                "NFTFuseWrapper: Cannot burn fuses: domain can be unwrapped"
            );
        }
    }

    function _wrapETH2LD(
        bytes32 label,
        bytes32 node,
        uint96 _fuses,
        address wrappedOwner
    ) private {
        // transfer the ens record back to the new owner (this contract)
        registrar.reclaim(uint256(label), address(this));
        // mint a new ERC1155 token with fuses

        address oldWrappedOwner = ownerOf(uint256(node));
        if (oldWrappedOwner != address(0)) {
            _burn(uint256(node));
        }
        _mint(uint256(node), wrappedOwner, _fuses);

        if (_fuses != CAN_DO_EVERYTHING) {
            require(
                !canUnwrap(node),
                "NFTFuseWrapper: Cannot burn fuses: domain can be unwrapped"
            );
        }

        emit WrapETH2LD(label, _fuses, wrappedOwner);
    }

    function _unwrap(
        bytes32 parentNode,
        bytes32 label,
        address newOwner
    ) private {
        bytes32 node = _makeNode(parentNode, label);
        require(
            newOwner != address(0x0),
            "NFTFuseWrapper: Target owner cannot be 0x0"
        );
        require(
            newOwner != address(this),
            "NFTFuseWrapper: Target owner cannot be the NFTFuseWrapper contract"
        );
        require(canUnwrap(node), "NFTFuseWrapper: Domain is not unwrappable");

        // burn token and fuse data
        _burn(uint256(node));
        ens.setOwner(node, newOwner);
        emit Unwrap(parentNode, label, newOwner);
    }
}


BancorBuyer - move cleanups

BancorBuyer - move cleanups

pragma solidity ^0.4.11;
import './TokenHolder.sol';
import './interfaces/ISmartToken.sol';
import './interfaces/IEtherToken.sol';
import './interfaces/ITokenChanger.sol';

/*
    Bancor Changer interface
*/
contract IBancorChanger is ITokenChanger {
    function token() public constant returns (ISmartToken _token) { _token; }
    function getReserveBalance(IERC20Token _reserveToken) public constant returns (uint256 balance);
}

/*
    BancorBuyer v0.2

    The bancor buyer contract is a simple bancor changer wrapper that allows buying smart tokens with ETH

    WARNING: the contract will make the purchase using the current price at transaction mining time
*/
contract BancorBuyer is TokenHolder {
    string public version = '0.2';
    IBancorChanger public tokenChanger; // bancor ETH <-> smart token changer
    IEtherToken public etherToken;      // ether token

    /**
        @dev constructor

        @param _changer     bancor token changer that actually does the purchase
        @param _etherToken  ether token used as a reserve in the token changer
    */
    function BancorBuyer(IBancorChanger _changer, IEtherToken _etherToken)
        validAddress(_changer)
        validAddress(_etherToken)
    {
        tokenChanger = _changer;
        etherToken = _etherToken;

        // ensure that the ether token is used as one of the changer's reserves
        tokenChanger.getReserveBalance(etherToken);
    }

    /**
        @dev buys the smart token with ETH if the return amount meets the minimum requested

        @param _minReturn  if the change results in an amount smaller than the minimum return - it is cancelled, must be nonzero

        @return tokens issued in return
    */
    function buy(uint256 _minReturn) public payable returns (uint256 amount) {
        etherToken.deposit.value(msg.value)(); // deposit ETH in the reserve
        assert(etherToken.approve(tokenChanger, 0)); // need to reset the allowance to 0 before setting a new one
        assert(etherToken.approve(tokenChanger, msg.value)); // approve the changer to use the ETH amount for the purchase

        ISmartToken smartToken = tokenChanger.token();
        uint256 returnAmount = tokenChanger.change(etherToken, smartToken, msg.value, _minReturn); // do the actual change
        assert(smartToken.transfer(msg.sender, returnAmount)); // transfer the tokens to the sender
        return returnAmount;
    }

    /**
        @dev fallback, buys the smart token with ETH
        note that the purchase will use the price at the time of the purchase

        @return tokens issued in return
    */
    function() payable {
        buy(1);
    }
}

pragma solidity ^0.4.11;
import './TokenHolder.sol';
import './interfaces/ISmartToken.sol';
import './interfaces/IEtherToken.sol';
import './interfaces/ITokenChanger.sol';

/*
    Bancor Changer interface
*/
contract IBancorChanger is ITokenChanger {
    function token() public constant returns (ISmartToken _token) { _token; }
    function getReserveBalance(IERC20Token _reserveToken) public constant returns (uint256 balance);
}

/*
    BancorBuyer v0.2

    The bancor buyer contract is a simple bancor changer wrapper that allows buying smart tokens with ETH

    WARNING: the contract will make the purchase using the current price at transaction mining time
*/
contract BancorBuyer is TokenHolder {
    string public version = '0.2';
    IBancorChanger public tokenChanger; // bancor ETH <-> smart token changer
    IEtherToken public etherToken;      // ether token

    /**
        @dev constructor

        @param _changer     bancor token changer that actually does the purchase
        @param _etherToken  ether token used as a reserve in the token changer
    */
    function BancorBuyer(IBancorChanger _changer, IEtherToken _etherToken)
        validAddress(_changer)
        validAddress(_etherToken)
    {
        tokenChanger = _changer;
        etherToken = _etherToken;

        // ensure that the ether token is used as one of the changer's reserves
        tokenChanger.getReserveBalance(etherToken);
    }

    /**
        @dev buys the smart token with ETH
        note that the purchase will use the price at the time of the purchase

        @return tokens issued in return
    */
    function buy() public payable returns (uint256 amount) {
        return buyMin(1);
    }

    /**
        @dev buys the smart token with ETH if the return amount meets the minimum requested

        @param _minReturn  if the change results in an amount smaller than the minimum return - it is cancelled, must be nonzero

        @return tokens issued in return
    */
    function buyMin(uint256 _minReturn) public payable returns (uint256 amount) {
        etherToken.deposit.value(msg.value)(); // deposit ETH in the reserve
        assert(etherToken.approve(tokenChanger, 0)); // need to reset the allowance to 0 before setting a new one
        assert(etherToken.approve(tokenChanger, msg.value)); // approve the changer to use the ETH amount for the purchase

        ISmartToken smartToken = tokenChanger.token();
        uint256 returnAmount = tokenChanger.change(etherToken, smartToken, msg.value, _minReturn); // do the actual change
        assert(smartToken.transfer(msg.sender, returnAmount)); // transfer the tokens to the sender
        return returnAmount;
    }

    // fallback
    function() payable {
        buy();
    }
}


sorry ik was vergeten te committent… wat dom van mij !

contract btuser {

	address owner;

	users[address] public Users;

	mapping (address => User) public users;

	event userAdded(address who, string hash);

	function btuser(){
	    owner = msg.sender;
	}

	function setProfilehash(string _hash) {
		users[msg.sender] = _hash;
		userAdded(msg.sender, _hash);
	}

	function kill() { if (msg.sender == owner) suicide(owner); }
}

error: pathspec 'app/contracts/blocktubeUser.sol' did not match any file(s) known to git


id increments fixed

id increments fixed

pragma solidity ^0.4.0;

contract DebtManager {

    //Company address | name, by company address we will have a name and can chack that company exist
    mapping(address => string) public companies;

    struct Order{
        uint id;
        string details;
        address moneyHolderAccount; // TODO:Name ??
        bool isFinilized;
        address owner;

    }

    struct Debt{

        uint id;
        uint orderId;

        address companyAccount;
        uint amount;
        bool isAgreed;
    }

    uint debtId; // auto increment unique id
    uint orderId; // auto increment unique id

    Order[] orderArr; // array of orders
    Debt[] debtArr;

    //---------------------------------------------------
    // Functions

    //Constructor
    function DebtManager() {

        //TODO: predefine data
    }

    //Create
    function createOrder(string details, address moneyHolderAccount) returns(uint) {
        orderArr.push(Order(orderId, details, moneyHolderAccount, false,msg.sender));

        return orderId++;
    }

    function createDebt(uint orderId, address companyAccountress, uint amount) returns(uint){
        //TODO: check if company in a company list

        //TODO: check if order id in the order list, probably with order index or just with index if we do not delete orders

        debtArr.push(Debt(debtId, orderId, companyAccountress, amount, false));

        return debtId++;
    }

    //Update

    function confirmDebt(uint debtId){

        var debt = debtArr[debtId];

        if(debt.companyAccount == msg.sender){
            debt.isAgreed = true;
        }
    }

    //Get constant

    function getOrderLength() constant returns(uint){
        return orderId;
    }

    function getDebtLength() constant returns(uint){
        return debtId;
    }

    function getOrderById(uint orderId) constant returns( uint id,
                                                          string details,
                                                          address moneyHolderAccount,
                                                          bool isFinilized,
                                                          address owner){

        Order order = orderArr[orderId];

        return(order.id, order.details, order.moneyHolderAccount, order.isFinilized, order.owner);

    }

    function getDebtById(uint debtId) constant returns(
                                                        uint id,
                                                        uint orderId,
                                                        address companyAccount,
                                                        uint amount,
                                                        bool isAgreed){

        Debt debt = debtArr[debtId];

        return (debt.id, debt.orderId, debt.companyAccount, debt.amount, debt.isAgreed);
    }

}

pragma solidity ^0.4.0;

contract DebtManager {

    //Company address | name, by company address we will have a name and can chack that company exist
    mapping(address => string) public companies;

    struct Order{
        uint id;
        string details;
        address moneyHolderAccount; // TODO:Name ??
        bool isFinilized;
        address owner;

    }

    struct Debt{

        uint id;
        uint orderId;

        address companyAccount;
        uint amount;
        bool isAgreed;
    }

    uint debtId; // auto increment unique id
    uint orderId; // auto increment unique id

    Order[] orderArr; // array of orders
    Debt[] debtArr;

    //---------------------------------------------------
    // Functions

    //Constructor
    function DebtManager() {

        //TODO: predefine data
    }

    //Create
    function createOrder(string details, address moneyHolderAccount) returns(uint) {
        orderArr.push(Order(orderId, details, moneyHolderAccount, false,msg.sender));

        orderId++;
        return --orderId;
    }

    function createDebt(uint orderId, address companyAccountress, uint amount) returns(uint){
        //TODO: check if company in a company list

        //TODO: check if order id in the order list, probably with order index or just with index if we do not delete orders

        debtArr.push(Debt(debtId, orderId, companyAccountress, amount, false));

        debtId++;
        return --debtId;
    }

    //Update

    function confirmDebt(uint debtId){

        var debt = debtArr[debtId];

        if(debt.companyAccount == msg.sender){
            debt.isAgreed = true;
        }
    }

    //Get constant

    function getOrderLength() constant returns(uint){
        return orderId;
    }

    function getDebtLength() constant returns(uint){
        return debtId;
    }

    function getOrderById(uint orderId) constant returns( uint id,
                                                          string details,
                                                          address moneyHolderAccount,
                                                          bool isFinilized,
                                                          address owner){

        Order order = orderArr[orderId];

        return(order.id, order.details, order.moneyHolderAccount, order.isFinilized, order.owner);

    }

    function getDebtById(uint debtId) constant returns(
                                                        uint id,
                                                        uint orderId,
                                                        address companyAccount,
                                                        uint amount,
                                                        bool isAgreed){

        Debt debt = debtArr[debtId];

        return (debt.id, debt.orderId, debt.companyAccount, debt.amount, debt.isAgreed);
    }

}


contrato Pool.sol caso de uso del principal

pragma solidity ^0.4.4;

contract IdentityManager{

    function comprueba(address a, bytes32 rol) returns (bool isRegistered){
     a = 0x00;
     rol = "a";
    return true;
    }
    function controla(address user, bytes32 hash,bytes32 rol){
     user = 0x0;
     hash = "";
     rol="";
 }

}

contract Votaciones{
    //nombre del usuario del gestor
    bytes32 public name;

    bytes32[] Allencuestas;
    address[] a;

    struct Votacion{
        bytes32 nombre;
        address[] yahanvotado;
        bytes32[] aspirantes;
        uint256[] puntuaciones;

    }
    mapping(bytes32 => Votacion) public votaciones;
    mapping(address => bytes32) public tokens;

    function Votaciones(bytes32 _name){
        name = _name;

    }
    event DevuelveBytes(bytes32);
    event DevuelveUint(uint256);
    event DevuelveAddr(address);
    event DevuelveArrayAddress(address[]);

    address addr = 0x950a13dc7a79187e519e6d7d5d5e1065fe9d35a2;
    IdentityManager identitymanager= IdentityManager(addr);

    /*function vota(bytes32 nombre,bytes32 aspirante){
    if(votaciones[nombre].yahanvotado.length == 0){
    votaciones[nombre].yahanvotado.push("0x0000000000000000000000000000000000000000");
    }
    for(uint256 r = 0; r< votaciones[nombre].yahanvotado.length;r++){
    if(votaciones[nombre].yahanvotado[r] == msg.sender){
    throw;
    }else{

     for(uint256 i = 0; i< votaciones[nombre].aspirantes.length;i++){
         if(votaciones[nombre].aspirantes[i] == aspirante){
             uint256 aux = votaciones[nombre].puntuaciones[i];
             aux++;
             votaciones[nombre].puntuaciones[i] = aux;
             DevuelveUint(votaciones[nombre].puntuaciones[i]);
             address[] aux1 = votaciones[nombre].yahanvotado;
             aux1.push(msg.sender);
             votaciones[nombre].yahanvotado = aux1;
             //DevuelveAddr(votaciones[nombre].yahanvotado[votaciones[nombre].yahanvotado.length]);

         }
     }

    }

     }
    }*/

    function vota(bytes32 nombre,bytes32 aspirante){

    if(votaciones[nombre].yahanvotado.length == 0){
        votaciones[nombre].yahanvotado.push(0x0000);
        DevuelveUint(votaciones[nombre].yahanvotado.length);
        DevuelveAddr(votaciones[nombre].yahanvotado[0]);
    }

    for(uint256 r = 0; r< votaciones[nombre].yahanvotado.length;r++){
        if(votaciones[nombre].yahanvotado[r] == msg.sender){
            DevuelveUint(3000);
            return;
        }
    }
     for(uint256 i = 0; i< votaciones[nombre].aspirantes.length;i++){
         if(votaciones[nombre].aspirantes[i] == aspirante){
             uint256 aux = votaciones[nombre].puntuaciones[i];
             aux++;
             votaciones[nombre].puntuaciones[i] = aux;
             DevuelveUint(votaciones[nombre].puntuaciones[i]);
             address[] aux1 = votaciones[nombre].yahanvotado;
             aux1.push(msg.sender);
             votaciones[nombre].yahanvotado = aux1;
             DevuelveArrayAddress(votaciones[nombre].yahanvotado);
             //DevuelveAddr(votaciones[nombre].yahanvotado[votaciones[nombre].yahanvotado.length]);

    }

     }
    }
    function createVotacion(bytes32 nombre, bytes32[] aspirantes, uint256[] puntuaciones){
        if(identitymanager.comprueba(msg.sender,"gerente")){

        votaciones[nombre] = Votacion({nombre:nombre,yahanvotado:a,aspirantes:aspirantes,puntuaciones:puntuaciones});
        Allencuestas.push(nombre);
        DevuelveBytes(votaciones[nombre].aspirantes[0]);
        DevuelveUint(votaciones[nombre].puntuaciones[0]);

        }
    }
    function eliminarVotacion(bytes32 nombre){
    	if(identitymanager.comprueba(msg.sender,"staff")){
        delete votaciones[nombre];
        }
    }

    function registraToken(bytes32 rol) returns (bytes32 a){

    a = sha3(block.timestamp,msg.sender);
    tokens[msg.sender] = a;
    DevuelveBytes(a);
    identitymanager.controla(msg.sender,a,rol);
    return a;
    }

    function  devuelveTodasEncuestas() returns(bytes32[]){
        return Allencuestas;
    }

    function devuelveToken() returns (bytes32 t ){
    t = tokens[msg.sender];
    tokens[msg.sender] = "0x0";
    return t;

    }

    function devuelveEncuestados(bytes32 encuesta) returns(bytes32[] encuestados){
        encuestados = votaciones[encuesta].aspirantes;
        return encuestados;

    }

    function devuelvePuntuaciones(bytes32 encuesta) returns(uint256[] values){
        values = votaciones[encuesta].puntuaciones;
        return values;

    }

}

error: pathspec 'pool.sol' did not match any file(s) known to git


assert is now built in

assert is now built in

pragma solidity ^0.4.11;

/**
 * Math operations with safety checks
 */
library SafeMath {
  function mul(uint a, uint b) internal returns (uint) {
    uint c = a * b;
    assert(a == 0 || c / a == b);
    return c;
  }

  function div(uint a, uint b) internal returns (uint) {
    // assert(b > 0); // Solidity automatically throws when dividing by 0
    uint c = a / b;
    // assert(a == b * c + a % b); // There is no case in which this doesn't hold
    return c;
  }

  function sub(uint a, uint b) internal returns (uint) {
    assert(b <= a);
    return a - b;
  }

  function add(uint a, uint b) internal returns (uint) {
    uint c = a + b;
    assert(c >= a);
    return c;
  }

  function max64(uint64 a, uint64 b) internal constant returns (uint64) {
    return a >= b ? a : b;
  }

  function min64(uint64 a, uint64 b) internal constant returns (uint64) {
    return a < b ? a : b;
  }

  function max256(uint256 a, uint256 b) internal constant returns (uint256) {
    return a >= b ? a : b;
  }

  function min256(uint256 a, uint256 b) internal constant returns (uint256) {
    return a < b ? a : b;
  }

}

pragma solidity ^0.4.11;

/**
 * Math operations with safety checks
 */
library SafeMath {
  function mul(uint a, uint b) internal returns (uint) {
    uint c = a * b;
    assert(a == 0 || c / a == b);
    return c;
  }

  function div(uint a, uint b) internal returns (uint) {
    // assert(b > 0); // Solidity automatically throws when dividing by 0
    uint c = a / b;
    // assert(a == b * c + a % b); // There is no case in which this doesn't hold
    return c;
  }

  function sub(uint a, uint b) internal returns (uint) {
    assert(b <= a);
    return a - b;
  }

  function add(uint a, uint b) internal returns (uint) {
    uint c = a + b;
    assert(c >= a);
    return c;
  }

  function max64(uint64 a, uint64 b) internal constant returns (uint64) {
    return a >= b ? a : b;
  }

  function min64(uint64 a, uint64 b) internal constant returns (uint64) {
    return a < b ? a : b;
  }

  function max256(uint256 a, uint256 b) internal constant returns (uint256) {
    return a >= b ? a : b;
  }

  function min256(uint256 a, uint256 b) internal constant returns (uint256) {
    return a < b ? a : b;
  }

  function assert(bool assertion) internal {
    if (!assertion) {
      throw;
    }
  }
}


Sega. Add first version of contract.

Sega. Add first version of contract.

pragma solidity ^0.4.13;

/**
    This contract represents a two-of-two multisig wallet with some usefull options
**/
contract Multisig {
    // Ethereum addresses of multisig owners
    address public owner1;
    address public owner2;

    // Ethereum addresses of witnesses
    address public witness1;
    address public witness2;

    // This structure represents who (from two owners) allowed some amount to spent the last time.
    // By default isFirstOwner = False so the owner2 is the person who last time allows to spend
    struct AllowancePosition {
        bool isFirstOwner;
        uint256 amount;
    }
    // Define allowance table
    mapping (address => AllowancePosition) public allowance;

    // Withdrawal limits approved by owners to each other
    uint256 public withdrawal1;
    uint256 public withdrawal2;

    // Active claims for the case when partners decide to end cooperation by this contract
    struct Claim {
        bool active;
        uint256 amount;
        address recipient;
        bool witnessApprove1;
        bool witnessApprove2;
    }
    Claim public ownerClaim1;
    Claim public ownerClaim2;

    // Modifiers
    modifier onlyOwners() {
        require(msg.sender == owner1 || msg.sender == owner2);
        _;
    }
    modifier onlyParticipants() {
        require(msg.sender == owner1 || msg.sender == owner2 || msg.sender == witness1 || msg.sender == witness2);
        _;
    }

    // Events
    event ChangeAllowance(address recipient, uint256 amount, address owner);
    event Transfer(address recipient, uint256 amount, address sender);
    event NewWithdrawals(uint256 firstOwnerAmount, uint256 secondOwnerAmount);
    event NewClaim(address claimCreator, uint256 amountRequested);

    // Constructor
    function Multisig(
        address _owner1,
        address _owner2,
        address _witness1,
        address _witness2) {
        // Set all addresses here
        owner1 = _owner1;
        owner2 = _owner2;
        witness1 = _witness1;
        witness2 = _witness2;
    }

    // Fallback function allows contract to recieve ether
    function () payable {}

    // That function change allowance or
    // try to send ether to `recipient` dependding on who is the message sender
    function TransferTo(address recipient, uint256 amount) onlyOwners {
        // first check who is the message sender
        bool isFirstOwner = true;
        if (msg.sender == owner2) {
            isFirstOwner = false;
        }
        // check if we need increase allowance or transfer the ether
        if (allowance[recipient].isFirstOwner == isFirstOwner) {
            allowance[recipient].amount += amount;  // increase allowance and return
            return;
        } else {
            // transfer the allowed part of ether
            // and change allowance if amount covers its initial value
            uint256 amountToSend = amount;
            if (amountToSend > allowance[recipient].amount) {
                amountToSend = allowance[recipient].amount;
            }
            if (amountToSend > this.balance) {
                amountToSend = this.balance;
            }
            // transfer ether
            if (amountToSend > 0) {
                allowance[recipient].amount -= amountToSend;
                recipient.transfer(amountToSend);
                Transfer(recipient, amountToSend, msg.sender);
            }
            // finilize function execution if we can't transfer the allowed value
            if (allowance[recipient].amount > 0 ) {
                return;
            }
            // increase allowance and change between the owners
            uint256 amountForAllowance = amount - amountToSend;
            if (amountForAllowance > 0) {
                allowance[recipient].amount = amountForAllowance;
                allowance[recipient].isFirstOwner = isFirstOwner;
                ChangeAllowance(recipient, amountForAllowance, msg.sender);
            }
        }
    }

    // Try to decrease the allowance
    function DecreaseTheAllowance(address recipient, uint256 amount) onlyOwners {
        if (amount > allowance[recipient].amount) {
            allowance[recipient].amount = 0;
            ChangeAllowance(recipient, 0, msg.sender);
            return;
        }
        allowance[recipient].amount -= amount;
        ChangeAllowance(recipient, allowance[recipient].amount, msg.sender);
    }

    // Change the withdrawal amount
    function IncreaseWithdrawalAmount(uint256 amount) onlyOwners {
        if (msg.sender == owner1) {
            withdrawal2 += amount;
        } else {
            withdrawal1 += amount;
        }
        NewWithdrawals(withdrawal1, withdrawal2);
    }

    function DecreaseWithdrawalAmount(uint256 amount) onlyOwners {
        if (msg.sender == owner1) {
            if (amount > withdrawal2) {
                amount = withdrawal2;
            }
            withdrawal2 -= amount;
        } else {
            if (amount > withdrawal1) {
                amount = withdrawal1;
            }
            withdrawal1 -= amount;
        }
        NewWithdrawals(withdrawal1, withdrawal2);
    }

    // Transfer ether by withdrawal limit
    function Withdrawal(address to, uint256 amount) onlyOwners {
        require(this.balance >= amount);
        if (msg.sender == owner1) {
            require(withdrawal1 >= amount);
            withdrawal1 -= amount;
            to.transfer(amount);
        } else {
            require(withdrawal2 >= amount);
            withdrawal2 -= amount;
            to.transfer(amount);
        }
        Transfer(to, amount, msg.sender);
    }

    // Claim proposition to end cooperation
    function createClaim(address to, uint256 amount) onlyOwners {
        if (msg.sender == owner1) {
            ownerClaim1.recipient = to;
            ownerClaim1.amount = amount;
            ownerClaim1.active = true;
            ownerClaim1.witnessApprove1 = false;
            ownerClaim1.witnessApprove2 = false;
        } else {
            ownerClaim2.recipient = to;
            ownerClaim2.amount = amount;
            ownerClaim2.active = true;
            ownerClaim2.witnessApprove1 = false;
            ownerClaim2.witnessApprove2 = false;
        }
        NewClaim(msg.sender, amount);
    }

    // Deactivate active claim
    function deactivateClaim() onlyOwners {
        if (msg.sender == owner1) {
            ownerClaim1.active = false;
            return;
        }
        ownerClaim2.active = false;
    }

    // Distribute ether according to the plan and destroy the contract processed by owners
    function JustifyClaim(address to) onlyOwners {
        if (msg.sender == owner1) {
            require(ownerClaim2.active);
            if (ownerClaim2.amount > this.balance) {
                ownerClaim2.amount = this.balance;
            }
            // Send ether
            ownerClaim2.active = false;
            ownerClaim2.recipient.transfer(ownerClaim2.amount);
            to.transfer(this.balance);
        } else {
            require(ownerClaim1.active);
            if (ownerClaim1.amount > this.balance) {
                ownerClaim1.amount = this.balance;
            }
            // Send ether
            ownerClaim1.active = false;
            ownerClaim1.recipient.transfer(ownerClaim1.amount);
            to.transfer(this.balance);
        }
        require(this.balance == 0);
        suicide(msg.sender);
    }

    // Any owner can justify their climes if it has 2 witness approves
    // If witness wants to approve the claim he or she need to set claimNumber
    function JustifyClaimWithWitness(uint8 claimNumber) onlyParticipants {
        // First witness case
        if (msg.sender == witness1) {
            if (claimNumber == 1) {
                ownerClaim1.witnessApprove1 = true;
            }
            if (claimNumber == 2) {
                ownerClaim2.witnessApprove1 = true;
            }
            return;
        }
        // Second witness case
        if (msg.sender == witness2) {
            if (claimNumber == 1) {
                ownerClaim1.witnessApprove2 = true;
            }
            if (claimNumber == 2) {
                ownerClaim2.witnessApprove2 = true;
            }
            return;
        }
        // First owner wants to justify
        if (msg.sender == owner1) {
            require(ownerClaim1.active);
            require(ownerClaim2.witnessApprove1 && ownerClaim2.witnessApprove2);
            if (ownerClaim1.amount > this.balance) {
                ownerClaim1.amount = this.balance;
            }
            // Send ether
            ownerClaim1.active = false;
            ownerClaim1.recipient.transfer(ownerClaim1.amount);
            owner2.transfer(this.balance);
        }
        // Second owner wants to justify
        if (msg.sender == owner2) {
            require(ownerClaim2.active);
            require(ownerClaim2.witnessApprove1 && ownerClaim2.witnessApprove2);
            if (ownerClaim2.amount > this.balance) {
                ownerClaim2.amount = this.balance;
            }
            // Send ether
            ownerClaim2.active = false;
            ownerClaim2.recipient.transfer(ownerClaim2.amount);
            owner1.transfer(this.balance);
        }
        require(this.balance == 0);
        suicide(msg.sender);
    }

    // Mist reset function for DEBUG mode
    function resetMistCallLoad() payable {
        require(msg.value == 0);
    }
}

error: pathspec 'contracts/multisig.sol' did not match any file(s) known to git