Update some function signatures.

Update some function signatures.

/**
 * @title BlobStore
 * @author Jonathan Brown <jbrown@bluedroplet.com>
 */
contract BlobStore {

    struct BlobInfo {               // Single slot.
        bool updatable;             // Can the blob be updated? Can be disabled.
        bool enforceRevisions;      // When updating, always make a new revision. Can be enabled.
        bool retractable;           // Can the blob be retracted? Can be disabled.
        bool transferable;          // Can the blob be transfered to another user or disowned? Can be disabled.
        uint32 blockNumber;         // Which block has revision 0 of this blob.
        uint32 numRevisions;        // Number of additional revisions.
        address owner;              // Who owns this blob.
    }

    mapping (bytes32 => BlobInfo) blobInfo;
    mapping (bytes32 => mapping (uint => bytes32)) packedRevisionBlockNumbers;
    mapping (bytes32 => mapping (address => bool)) enabledTransfers;

    event logBlob(bytes32 indexed id, uint indexed revisionId, bytes blob);     // Greatest revisionId for the blob at time of logging.
    event logRetractRevision(bytes32 indexed id, uint revisionId);
    event logRetract(bytes32 indexed id);
    event logTransfer(bytes32 indexed id, address recipient);
    event logDisown(bytes32 indexed id);
    event logSetNotUpdatable(bytes32 indexed id);
    event logSetEnforceRevisions(bytes32 indexed id);
    event logSetNotRetractable(bytes32 indexed id);
    event logSetNotTransferable(bytes32 indexed id);

    // Create a 96-bit id for this contract. This is unique across all blockchains.
    // Wait a few minutes after deploying for this id to settle.
    bytes12 constant contractId = bytes12(sha3(this, block.blockhash(block.number - 1)));

    /**
     * @dev Throw if the current message is sending a payment.
     */
    modifier noValue() {
        if (msg.value > 0) {
            throw;      // Do not maintain a balance.
        }
        _
    }

    /**
     * @dev Throw if the blob has not been used before or it has been retracted.
     * @param id Id of the blob.
     */
    modifier exists(bytes32 id) {
        if (blobInfo[id].blockNumber == 0 || blobInfo[id].blockNumber == uint32(-1)) {
            throw;
        }
        _
    }

    /**
     * @dev Throw if the owner of the blob is not the message sender.
     * @param id Id of the blob.
     */
    modifier isOwner(bytes32 id) {
        if (blobInfo[id].owner != msg.sender) {
            throw;
        }
        _
    }

    /**
     * @dev Throw if the blob is not updatable.
     * @param id Id of the blob.
     */
    modifier isUpdatable(bytes32 id) {
        if (!blobInfo[id].updatable) {
            throw;
        }
        _
    }

    /**
     * @dev Throw if the blob is not enforcing revisions.
     * @param id Id of the blob.
     */
    modifier isNotEnforceRevisions(bytes32 id) {
        if (blobInfo[id].enforceRevisions) {
            throw;
        }
        _
    }

    /**
     * @dev Throw is the blob is not retractable.
     * @param id Id of the blob.
     */
    modifier isRetractable(bytes32 id) {
        if (!blobInfo[id].retractable) {
            throw;
        }
        _
    }

    /**
     * @dev Throw if the blob is not transferable.
     * @param id Id of the blob.
     */
    modifier isTransferable(bytes32 id) {
        if (!blobInfo[id].transferable) {
            throw;
        }
        _
    }

    /**
     * @dev Throw if the blob is not transferable to a specific user.
     * @param id Id of the blob.
     * @param recipient Address of the user.
     */
    modifier isTransferEnabled(bytes32 id, address recipient) {
        if (!enabledTransfers[id][recipient]) {
            throw;
        }
        _
    }

    /**
     * @dev Throw if the blob does not have revisions.
     * @param id Id of the blob.
     */
    modifier hasRevisions(bytes32 id) {
        if (blobInfo[id].numRevisions == 0) {
            throw;
        }
        _
    }

    /**
     * @dev Throw if a specific blob revision does not exist.
     * @param id Id of the blob.
     * @param revisionId Id of the revision.
     */
    modifier revisionExists(bytes32 id, uint revisionId) {
        if (revisionId > blobInfo[id].numRevisions) {
            throw;
        }
        _
    }

    /**
     * @dev Stores new blob in the transaction log. It is guaranteed that each user will get a different id from the same nonce.
     * @param blob Blob that should be stored.
     * @param nonce Any value that the user has not used previously to create a blob.
     * @param updatable Should the blob be updatable?
     * @param enforceRevisions Should the blob enforce revisions when updating?
     * @param retractable Should the blob be retractable?
     * @param transferable Should the blob be transferable?
     * @param anon Should the blob be anonymous?
     * @return id Id of the blob.
     */
    function create(bytes blob, bytes32 nonce, bool updatable, bool enforceRevisions, bool retractable, bool transferable, bool anon) noValue external returns (bytes32 id) {
        // Determine the id.
        id = contractId | (sha3(msg.sender, nonce) & (2 ** 160 - 1));
        // Make sure this id has not been used before.
        if (blobInfo[id].blockNumber != 0) {
            throw;
        }
        // Store blob info in state.
        blobInfo[id] = BlobInfo({
            updatable: updatable,
            enforceRevisions: enforceRevisions,
            retractable: retractable,
            transferable: transferable,
            numRevisions: 0,
            blockNumber: uint32(block.number),
            owner: anon ? 0 : msg.sender,
        });
        // Store the blob in a log in the current block.
        logBlob(id, 0, blob);
    }

    /**
     * @dev Store a blob revision block number in a packed slot.
     * @param id Id of the blob.
     * @param offset The offset of the block number should be retreived.
     */
    function setPackedRevisionBlockNumber(bytes32 id, uint offset) internal {
        // Get the slot.
        bytes32 slot = packedRevisionBlockNumbers[id][offset / 8];
        // Wipe the previous block number.
        slot &= ~bytes32(uint32(-1) * 2 ** ((offset % 8) * 32));
        // Insert the current block number.
        slot |= bytes32(uint32(block.number) * 2 ** ((offset % 8) * 32));
        // Store the slot.
        packedRevisionBlockNumbers[id][offset / 8] = slot;
    }

    /**
     * @dev Create a new blob revision.
     * @param id Id of the blob.
     * @param blob Blob that should be stored as the new revision.
     * @return revisionId The new revisionId.
     */
    function createNewRevision(bytes32 id, bytes blob) noValue isOwner(id) isUpdatable(id) external returns (uint revisionId) {
        // Increment the number of revisions.
        revisionId = ++blobInfo[id].numRevisions;
        // Store the block number.
        setPackedRevisionBlockNumber(id, revisionId - 1);
        // Store the new blob in a log in the current block.
        logBlob(id, revisionId, blob);
    }

    /**
     * @dev Update a blob's latest revsion.
     * @param id Id of the blob.
     * @param blob Blob that should be stored as the latest revision.
     */
    function updateLatestRevision(bytes32 id,  bytes blob) noValue isOwner(id) isUpdatable(id) isNotEnforceRevisions(id) external {
        if (blobInfo[id].numRevisions == 0) {
            blobInfo[id].blockNumber = uint32(block.number);
        }
        else {
            setPackedRevisionBlockNumber(id, blobInfo[id].numRevisions - 1);
        }
        // Store the new blob in a log in the current block.
        logBlob(id, blobInfo[id].numRevisions, blob);
    }

    /**
     * @dev Retract a blob's latest revision.
     * @param id Id of the blob.
     */
    function retractLatestRevision(bytes32 id) noValue isOwner(id) isUpdatable(id) isNotEnforceRevisions(id) hasRevisions(id) external {
        // Delete slot if empty
        if (blobInfo[id].numRevisions % 8 == 1) {
            delete packedRevisionBlockNumbers[id][blobInfo[id].numRevisions / 8];
        }
        // Log the retraction.
        logRetractRevision(id, blobInfo[id].numRevisions--);
    }

    /**
     * @dev Delete all of a blob's packed revision block numbers.
     * @param id Id of the blob.
     */
    function deleteAllRevisionBlockNumbers(bytes32 id) internal {
        uint numSlots = (blobInfo[id].numRevisions + 7) / 8;
        for (uint i = 0; i < numSlots; i++) {
            delete packedRevisionBlockNumbers[id][i];
        }
    }

    /**
     * @dev Delete all a blob's revisions and replace it with a new blob.
     * @param id Id of the blob.
     * @param blob Blob that should be stored.
     */
    function restart(bytes32 id, bytes blob) noValue isOwner(id) isUpdatable(id) isNotEnforceRevisions(id) external {
        // Try to get some gas refunds.
        deleteAllRevisionBlockNumbers(id);
        // Update the blob state info.
        blobInfo[id].blockNumber = uint32(block.number);
        blobInfo[id].numRevisions = 0;
        // Store the blob in a log in the current block.
        logBlob(id, 0, blob);
    }

    /**
     * @dev Retract a blob.
     * @param id Id of the blob.
     */
    function retract(bytes32 id) noValue isOwner(id) isRetractable(id) external {
        // Delete the packed revision block numbers.
        deleteAllRevisionBlockNumbers(id);
        // Mark this blob as retracted.
        blobInfo[id] = BlobInfo({
            updatable: false,
            enforceRevisions: false,
            retractable: false,
            transferable: false,
            numRevisions: 0,
            blockNumber: uint32(-1),
            owner: 0,
        });
        // Log that the blob has been retracted.
        logRetract(id);
    }

    /**
     * @dev Enable transfer of the blob to the current user.
     * @param id Id of the blob.
     */
    function transferEnable(bytes32 id) noValue isTransferable(id) external {
        // Record in state that the current user will accept this blob.
        enabledTransfers[id][msg.sender] = true;
    }

    /**
     * @dev Disable transfer of the blob to the current user.
     * @param id Id of the blob.
     */
    function transferDisable(bytes32 id) noValue isTransferEnabled(id, msg.sender) external {
        // Record in state that the current user will not accept this blob.
        enabledTransfers[id][msg.sender] = false;
    }

    /**
     * @dev Transfer a blob to a new user.
     * @param id Id of the blob.
     * @param recipient Address of the user to transfer to blob to.
     */
    function transfer(bytes32 id, address recipient) noValue isOwner(id) isTransferable(id) isTransferEnabled(id, recipient) external {
        // Update ownership of the blob.
        blobInfo[id].owner = recipient;
        // Disable this transfer in future and free up the slot.
        enabledTransfers[id][recipient] = false;
        // Log the transfer.
        logTransfer(id, recipient);
    }

    /**
     * @dev Disown a blob.
     * @param id Id of the blob.
     */
    function disown(bytes32 id) noValue isOwner(id) isTransferable(id) external {
        // Remove the owner from the blob's state.
        delete blobInfo[id].owner;
        // Log as blob as disowned.
        logDisown(id);
    }

    /**
     * @dev Set a blob as not updatable.
     * @param id Id of the blob.
     */
    function setNotUpdatable(bytes32 id) noValue isOwner(id) external {
        // Record in state that the blob is not updatable.
        blobInfo[id].updatable = false;
        // Log that the blob is not updatable.
        logSetNotUpdatable(id);
    }

    /**
     * @dev Set a blob to enforce revisions.
     * @param id Id of the blob.
     */
    function setEnforceRevisions(bytes32 id) noValue isOwner(id) external {
        // Record in state that all changes to this blob must be new revisions.
        blobInfo[id].enforceRevisions = true;
        // Log that the blob now forces new revisions.
        logSetEnforceRevisions(id);
    }

    /**
     * @dev Set a blob to not be retractable.
     * @param id Id of the blob.
     */
    function setNotRetractable(bytes32 id) noValue isOwner(id) external {
        // Record in state that the blob is not retractable.
        blobInfo[id].retractable = false;
        // Log that the blob is not retractable.
        logSetNotRetractable(id);
    }

    /**
     * @dev Set a blob to not be transferable.
     * @param id Id of the blob.
     */
    function setNotTransferable(bytes32 id) noValue isOwner(id) external {
        // Record in state that the blob is not transferable.
        blobInfo[id].transferable = false;
        // Log that the blob is not transferable.
        logSetNotTransferable(id);
    }

    function getContractId() noValue constant external returns (bytes12 _contractId) {
        _contractId = contractId;
    }

    /**
     * @dev Get info about a blob.
     * @param id Id of the blob.
     * @return owner Owner of the blob.
     * @return numRevisions How many revisions the blob has.
     * @return latestBlockNumber The block number of the latest revision.
     * @return updatable Is the blob updatable?
     * @return enforceRevisions Does the blob enforce revisions?
     * @return retractable Is the blob retractable?
     * @return transferable Is the blob transferable?
     */
    function getInfo(bytes32 id) noValue exists(id) constant external returns (address owner, uint numRevisions, uint latestBlockNumber, bool updatable, bool enforceRevisions, bool retractable, bool transferable) {
        owner = blobInfo[id].owner;
        numRevisions = blobInfo[id].numRevisions;
        latestBlockNumber = getRevisionBlockNumber(id, numRevisions);
        updatable = blobInfo[id].updatable;
        enforceRevisions = blobInfo[id].enforceRevisions;
        retractable = blobInfo[id].retractable;
        transferable = blobInfo[id].transferable;
    }

    /**
     * @dev Get the owner of a blob.
     * @param id Id of the blob.
     * @return owner Owner of the blob.
     */
    function getOwner(bytes32 id) noValue exists(id) constant external returns (address owner) {
        owner = blobInfo[id].owner;
    }

    /**
     * @dev Is a blob updatable?
     * @param id Id of the blob.
     * @return updatable Is the blob updatable?
     */
    function getUpdatable(bytes32 id) noValue exists(id) constant external returns (bool updatable) {
        updatable = blobInfo[id].updatable;
    }

    /**
     * @dev Does a blob enforce revisions?
     * @param id Id of the blob.
     * @return enforceRevisions Does the blob enforce revisions?
     */
    function getEnforceRevisions(bytes32 id) noValue exists(id) constant external returns (bool enforceRevisions) {
        enforceRevisions = blobInfo[id].enforceRevisions;
    }

    /**
     * @dev Is a blob retractable?
     * @param id Id of the blob.
     * @return retractable Is the blob retractable?
     */
    function getRetractable(bytes32 id) noValue exists(id) constant external returns (bool retractable) {
        retractable = blobInfo[id].retractable;
    }

    /**
     * @dev Is a blob transferable.
     * @param id Id of the blob.
     * @return transferable Is the blob transferable?
     */
    function getTransferable(bytes32 id) noValue exists(id) constant external returns (bool transferable) {
        transferable = blobInfo[id].transferable;
    }

    /**
     * @dev Get the number of revisions a blob has.
     * @param id Id of the blob.
     * @return numRevisions How many revisions the blob has.
     */
    function getNumRevisions(bytes32 id) noValue exists(id) constant external returns (uint numRevisions) {
        numRevisions = blobInfo[id].numRevisions;
    }

    /**
     * @dev Get the block number for a specific blob revision.
     * @param id Id of the blob.
     * @param revisionId Id of the revision.
     * @return blockNumber Block number of the specified revision.
     */
    function getRevisionBlockNumber(bytes32 id, uint revisionId) noValue exists(id) revisionExists(id, revisionId) constant returns (uint blockNumber) {
        if (revisionId == 0) {
            blockNumber = blobInfo[id].blockNumber;
        }
        else {
            bytes32 slot = packedRevisionBlockNumbers[id][(revisionId - 1) / 8];
            blockNumber = uint32(uint256(slot) / 2 ** (((revisionId - 1) % 8) * 32));
        }
    }

    /**
     * @dev Default function.
     */
    function() {
        throw;      // Do not maintain a balance.
    }

}

/**
 * @title BlobStore
 * @author Jonathan Brown <jbrown@bluedroplet.com>
 */
contract BlobStore {

    struct BlobInfo {               // Single slot.
        bool updatable;             // Can the blob be updated? Can be disabled.
        bool enforceRevisions;      // When updating, always make a new revision. Can be enabled.
        bool retractable;           // Can the blob be retracted? Can be disabled.
        bool transferable;          // Can the blob be transfered to another user or disowned? Can be disabled.
        uint32 blockNumber;         // Which block has revision 0 of this blob.
        uint32 numRevisions;        // Number of additional revisions.
        address owner;              // Who owns this blob.
    }

    mapping (bytes32 => BlobInfo) blobInfo;
    mapping (bytes32 => mapping (uint => bytes32)) packedRevisionBlockNumbers;
    mapping (bytes32 => mapping (address => bool)) enabledTransfers;

    event logBlob(bytes32 indexed id, uint indexed revisionId, bytes blob);     // Greatest revisionId for the blob at time of logging.
    event logRetractRevision(bytes32 indexed id, uint revisionId);
    event logRetract(bytes32 indexed id);
    event logTransfer(bytes32 indexed id, address recipient);
    event logDisown(bytes32 indexed id);
    event logSetNotUpdatable(bytes32 indexed id);
    event logSetEnforceRevisions(bytes32 indexed id);
    event logSetNotRetractable(bytes32 indexed id);
    event logSetNotTransferable(bytes32 indexed id);

    // Create a 96-bit id for this contract. This is unique across all blockchains.
    // Wait a few minutes after deploying for this id to settle.
    bytes12 constant contractId = bytes12(sha3(this, block.blockhash(block.number - 1)));

    /**
     * @dev Throw if the current message is sending a payment.
     */
    modifier noValue() {
        if (msg.value > 0) {
            throw;      // Do not maintain a balance.
        }
        _
    }

    /**
     * @dev Throw if the blob has not been used before or it has been retracted.
     * @param id Id of the blob.
     */
    modifier exists(bytes32 id) {
        if (blobInfo[id].blockNumber == 0 || blobInfo[id].blockNumber == uint32(-1)) {
            throw;
        }
        _
    }

    /**
     * @dev Throw if the owner of the blob is not the message sender.
     * @param id Id of the blob.
     */
    modifier isOwner(bytes32 id) {
        if (blobInfo[id].owner != msg.sender) {
            throw;
        }
        _
    }

    /**
     * @dev Throw if the blob is not updatable.
     * @param id Id of the blob.
     */
    modifier isUpdatable(bytes32 id) {
        if (!blobInfo[id].updatable) {
            throw;
        }
        _
    }

    /**
     * @dev Throw if the blob is not enforcing revisions.
     * @param id Id of the blob.
     */
    modifier isNotEnforceRevisions(bytes32 id) {
        if (blobInfo[id].enforceRevisions) {
            throw;
        }
        _
    }

    /**
     * @dev Throw is the blob is not retractable.
     * @param id Id of the blob.
     */
    modifier isRetractable(bytes32 id) {
        if (!blobInfo[id].retractable) {
            throw;
        }
        _
    }

    /**
     * @dev Throw if the blob is not transferable.
     * @param id Id of the blob.
     */
    modifier isTransferable(bytes32 id) {
        if (!blobInfo[id].transferable) {
            throw;
        }
        _
    }

    /**
     * @dev Throw if the blob is not transferable to a specific user.
     * @param id Id of the blob.
     * @param recipient Address of the user.
     */
    modifier isTransferEnabled(bytes32 id, address recipient) {
        if (!enabledTransfers[id][recipient]) {
            throw;
        }
        _
    }

    /**
     * @dev Throw if the blob does not have revisions.
     * @param id Id of the blob.
     */
    modifier hasRevisions(bytes32 id) {
        if (blobInfo[id].numRevisions == 0) {
            throw;
        }
        _
    }

    /**
     * @dev Throw if a specific blob revision does not exist.
     * @param id Id of the blob.
     * @param revisionId Id of the revision.
     */
    modifier revisionExists(bytes32 id, uint revisionId) {
        if (revisionId > blobInfo[id].numRevisions) {
            throw;
        }
        _
    }

    /**
     * @dev Stores new blob in the transaction log. It is guaranteed that each user will get a different id from the same nonce.
     * @param blob Blob that should be stored.
     * @param nonce Any value that the user has not used previously to create a blob.
     * @param updatable Should the blob be updatable?
     * @param enforceRevisions Should the blob enforce revisions when updating?
     * @param retractable Should the blob be retractable?
     * @param transferable Should the blob be transferable?
     * @param anon Should the blob be anonymous?
     * @return id Id of the blob.
     */
    function create(bytes blob, bytes32 nonce, bool updatable, bool enforceRevisions, bool retractable, bool transferable, bool anon) noValue external returns (bytes32 id) {
        // Determine the id.
        id = contractId | (sha3(msg.sender, nonce) & (2 ** 160 - 1));
        // Make sure this id has not been used before.
        if (blobInfo[id].blockNumber != 0) {
            throw;
        }
        // Store blob info in state.
        blobInfo[id] = BlobInfo({
            updatable: updatable,
            enforceRevisions: enforceRevisions,
            retractable: retractable,
            transferable: transferable,
            numRevisions: 0,
            blockNumber: uint32(block.number),
            owner: anon ? 0 : msg.sender,
        });
        // Store the blob in a log in the current block.
        logBlob(id, 0, blob);
    }

    /**
     * @dev Store a blob revision block number in a packed slot.
     * @param id Id of the blob.
     * @param offset The offset of the block number should be retreived.
     */
    function setPackedRevisionBlockNumber(bytes32 id, uint offset) internal {
        // Get the slot.
        bytes32 slot = packedRevisionBlockNumbers[id][offset / 8];
        // Wipe the previous block number.
        slot &= ~bytes32(uint32(-1) * 2 ** ((offset % 8) * 32));
        // Insert the current block number.
        slot |= bytes32(uint32(block.number) * 2 ** ((offset % 8) * 32));
        // Store the slot.
        packedRevisionBlockNumbers[id][offset / 8] = slot;
    }

    /**
     * @dev Create a new blob revision.
     * @param id Id of the blob.
     * @param blob Blob that should be stored as the new revision.
     * @return revisionId The new revisionId.
     */
    function createRevision(bytes32 id, bytes blob) noValue isOwner(id) isUpdatable(id) external returns (uint revisionId) {
        // Increment the number of revisions.
        revisionId = ++blobInfo[id].numRevisions;
        // Store the block number.
        setPackedRevisionBlockNumber(id, revisionId - 1);
        // Store the new blob in a log in the current block.
        logBlob(id, revisionId, blob);
    }

    /**
     * @dev Update a blob's latest revsion.
     * @param id Id of the blob.
     * @param blob Blob that should be stored as the latest revision.
     */
    function updateLatestRevision(bytes32 id,  bytes blob) noValue isOwner(id) isUpdatable(id) isNotEnforceRevisions(id) external {
        if (blobInfo[id].numRevisions == 0) {
            blobInfo[id].blockNumber = uint32(block.number);
        }
        else {
            setPackedRevisionBlockNumber(id, blobInfo[id].numRevisions - 1);
        }
        // Store the new blob in a log in the current block.
        logBlob(id, blobInfo[id].numRevisions, blob);
    }

    /**
     * @dev Retract a blob's latest revision.
     * @param id Id of the blob.
     */
    function retractLatestRevision(bytes32 id) noValue isOwner(id) isUpdatable(id) isNotEnforceRevisions(id) hasRevisions(id) external {
        // Delete slot if empty
        if (blobInfo[id].numRevisions % 8 == 1) {
            delete packedRevisionBlockNumbers[id][blobInfo[id].numRevisions / 8];
        }
        // Log the retraction.
        logRetractRevision(id, blobInfo[id].numRevisions--);
    }

    /**
     * @dev Delete all of a blob's packed revision block numbers.
     * @param id Id of the blob.
     */
    function deleteAllRevisionBlockNumbers(bytes32 id) internal {
        uint numSlots = (blobInfo[id].numRevisions + 7) / 8;
        for (uint i = 0; i < numSlots; i++) {
            delete packedRevisionBlockNumbers[id][i];
        }
    }

    /**
     * @dev Delete all a blob's revisions and replace it with a new blob.
     * @param id Id of the blob.
     * @param blob Blob that should be stored.
     */
    function restart(bytes32 id, bytes blob) noValue isOwner(id) isUpdatable(id) isNotEnforceRevisions(id) external {
        // Try to get some gas refunds.
        deleteAllRevisionBlockNumbers(id);
        // Update the blob state info.
        blobInfo[id].blockNumber = uint32(block.number);
        blobInfo[id].numRevisions = 0;
        // Store the blob in a log in the current block.
        logBlob(id, 0, blob);
    }

    /**
     * @dev Retract a blob.
     * @param id Id of the blob.
     */
    function retract(bytes32 id) noValue isOwner(id) isRetractable(id) external {
        // Delete the packed revision block numbers.
        deleteAllRevisionBlockNumbers(id);
        // Mark this blob as retracted.
        blobInfo[id] = BlobInfo({
            updatable: false,
            enforceRevisions: false,
            retractable: false,
            transferable: false,
            numRevisions: 0,
            blockNumber: uint32(-1),
            owner: 0,
        });
        // Log that the blob has been retracted.
        logRetract(id);
    }

    /**
     * @dev Enable transfer of the blob to the current user.
     * @param id Id of the blob.
     */
    function transferEnable(bytes32 id) noValue isTransferable(id) external {
        // Record in state that the current user will accept this blob.
        enabledTransfers[id][msg.sender] = true;
    }

    /**
     * @dev Disable transfer of the blob to the current user.
     * @param id Id of the blob.
     */
    function transferDisable(bytes32 id) noValue isTransferEnabled(id, msg.sender) external {
        // Record in state that the current user will not accept this blob.
        enabledTransfers[id][msg.sender] = false;
    }

    /**
     * @dev Transfer a blob to a new user.
     * @param id Id of the blob.
     * @param recipient Address of the user to transfer to blob to.
     */
    function transfer(bytes32 id, address recipient) noValue isOwner(id) isTransferable(id) isTransferEnabled(id, recipient) external {
        // Update ownership of the blob.
        blobInfo[id].owner = recipient;
        // Disable this transfer in future and free up the slot.
        enabledTransfers[id][recipient] = false;
        // Log the transfer.
        logTransfer(id, recipient);
    }

    /**
     * @dev Disown a blob.
     * @param id Id of the blob.
     */
    function disown(bytes32 id) noValue isOwner(id) isTransferable(id) external {
        // Remove the owner from the blob's state.
        delete blobInfo[id].owner;
        // Log as blob as disowned.
        logDisown(id);
    }

    /**
     * @dev Set a blob as not updatable.
     * @param id Id of the blob.
     */
    function setNotUpdatable(bytes32 id) noValue isOwner(id) external {
        // Record in state that the blob is not updatable.
        blobInfo[id].updatable = false;
        // Log that the blob is not updatable.
        logSetNotUpdatable(id);
    }

    /**
     * @dev Set a blob to enforce revisions.
     * @param id Id of the blob.
     */
    function setEnforceRevisions(bytes32 id) noValue isOwner(id) external {
        // Record in state that all changes to this blob must be new revisions.
        blobInfo[id].enforceRevisions = true;
        // Log that the blob now forces new revisions.
        logSetEnforceRevisions(id);
    }

    /**
     * @dev Set a blob to not be retractable.
     * @param id Id of the blob.
     */
    function setNotRetractable(bytes32 id) noValue isOwner(id) external {
        // Record in state that the blob is not retractable.
        blobInfo[id].retractable = false;
        // Log that the blob is not retractable.
        logSetNotRetractable(id);
    }

    /**
     * @dev Set a blob to not be transferable.
     * @param id Id of the blob.
     */
    function setNotTransferable(bytes32 id) noValue isOwner(id) external {
        // Record in state that the blob is not transferable.
        blobInfo[id].transferable = false;
        // Log that the blob is not transferable.
        logSetNotTransferable(id);
    }

    function getContractId() noValue constant external returns (bytes12 _contractId) {
        _contractId = contractId;
    }

    /**
     * @dev Get info about a blob.
     * @param id Id of the blob.
     * @return owner Owner of the blob.
     * @return updatable Is the blob updatable?
     * @return enforceRevisions Does the blob enforce revisions?
     * @return retractable Is the blob retractable?
     * @return transferable Is the blob transferable?
     * @return numRevisions How many revisions the blob has.
     * @return latestBlockNumber The block number of the latest revision.
     */
    function getInfo(bytes32 id) noValue exists(id) constant external returns (address owner, bool updatable, bool enforceRevisions, bool retractable, bool transferable, uint numRevisions, uint latestBlockNumber) {
        owner = blobInfo[id].owner;
        updatable = blobInfo[id].updatable;
        enforceRevisions = blobInfo[id].enforceRevisions;
        retractable = blobInfo[id].retractable;
        transferable = blobInfo[id].transferable;
        numRevisions = blobInfo[id].numRevisions;
        latestBlockNumber = getRevisionBlockNumber(id, numRevisions);
    }

    /**
     * @dev Get the owner of a blob.
     * @param id Id of the blob.
     * @return owner Owner of the blob.
     */
    function getOwner(bytes32 id) noValue exists(id) constant external returns (address owner) {
        owner = blobInfo[id].owner;
    }

    /**
     * @dev Is a blob updatable?
     * @param id Id of the blob.
     * @return updatable Is the blob updatable?
     */
    function getUpdatable(bytes32 id) noValue exists(id) constant external returns (bool updatable) {
        updatable = blobInfo[id].updatable;
    }

    /**
     * @dev Does a blob enforce revisions?
     * @param id Id of the blob.
     * @return enforceRevisions Does the blob enforce revisions?
     */
    function getEnforceRevisions(bytes32 id) noValue exists(id) constant external returns (bool enforceRevisions) {
        enforceRevisions = blobInfo[id].enforceRevisions;
    }

    /**
     * @dev Is a blob retractable?
     * @param id Id of the blob.
     * @return retractable Is the blob retractable?
     */
    function getRetractable(bytes32 id) noValue exists(id) constant external returns (bool retractable) {
        retractable = blobInfo[id].retractable;
    }

    /**
     * @dev Is a blob transferable.
     * @param id Id of the blob.
     * @return transferable Is the blob transferable?
     */
    function getTransferable(bytes32 id) noValue exists(id) constant external returns (bool transferable) {
        transferable = blobInfo[id].transferable;
    }

    /**
     * @dev Get the number of revisions a blob has.
     * @param id Id of the blob.
     * @return numRevisions How many revisions the blob has.
     */
    function getNumRevisions(bytes32 id) noValue exists(id) constant external returns (uint numRevisions) {
        numRevisions = blobInfo[id].numRevisions;
    }

    /**
     * @dev Get the block number for a specific blob revision.
     * @param id Id of the blob.
     * @param revisionId Id of the revision.
     * @return blockNumber Block number of the specified revision.
     */
    function getRevisionBlockNumber(bytes32 id, uint revisionId) noValue exists(id) revisionExists(id, revisionId) constant returns (uint blockNumber) {
        if (revisionId == 0) {
            blockNumber = blobInfo[id].blockNumber;
        }
        else {
            bytes32 slot = packedRevisionBlockNumbers[id][(revisionId - 1) / 8];
            blockNumber = uint32(uint256(slot) / 2 ** (((revisionId - 1) % 8) * 32));
        }
    }

    /**
     * @dev Default function.
     */
    function() {
        throw;      // Do not maintain a balance.
    }

}


AssertBytes32.sol

pragma solidity >= 0.4.15 < 0.6.0;

library AssertBytes32 {

    // Constant: BYTES32_NULL
    // The null bytes32: 0
    bytes32 constant BYTES32_NULL = 0x0;

    byte constant MINUS = byte('-');

    /*
        Event: TestEvent

        Fired when an assertion is made.

        Params:
            result (bool) - Whether or not the assertion holds.
            message (string) - A message to display if the assertion does not hold.
    */
    event TestEvent(bool indexed result, string message);

    // ************************************** bytes32 **************************************

    /*
        Function: equal(bytes32)

        Assert that two 'bytes32' are equal.

        : A == B

        Params:
            A (bytes32) - The first 'bytes32'.
            B (bytes32) - The second 'bytes32'.
            message (string) - A message that is sent if the assertion fails.

        Returns:
            result (bool) - The result.
    */
    function equal(bytes32 a, bytes32 b, string memory message) public returns (bool result) {
        result = (a == b);
        _report(result, message);
    }

    /*
        Function: notEqual(bytes32)

        Assert that two 'bytes32' are not equal.

        : A != B

        Params:
            A (bytes32) - The first 'bytes32'.
            B (bytes32) - The second 'bytes32'.
            message (string) - A message that is sent if the assertion fails.

        Returns:
            result (bool) - The result.
    */
    function notEqual(bytes32 a, bytes32 b, string memory message) public returns (bool result) {
        result = (a != b);
        _report(result, message);
    }

    /*
        Function: isZero(bytes32)

        Assert that a 'bytes32' is zero.

        : bts == BYTES32_NULL

        Params:
            bts (bytes32) - The 'bytes32'.
            message (string) - A message that is sent if the assertion fails.

        Returns:
            result (bool) - The result.
    */
    function isZero(bytes32 bts, string memory message) public returns (bool result) {
        result = (bts == BYTES32_NULL);
        _report(result, message);
    }

    /*
        Function: isNotZero(bytes32)

        Assert that a 'bytes32' is not zero.

        : bts != BYTES32_NULL

        Params:
            bts (bytes32) - The 'bytes32'.
            message (string) - A message that is sent if the assertion fails.

        Returns:
            result (bool) - The result.
    */
    function isNotZero(bytes32 bts, string memory message) public returns (bool result) {
        result = (bts != BYTES32_NULL);
        _report(result, message);
    }

    /******************************** internal ********************************/

        /*
            Function: _report

            Internal function for triggering <TestEvent>.

            Params:
                result (bool) - The test result (true or false).
                message (string) - The message that is sent if the assertion fails.
        */
    function _report(bool result, string memory message) internal {
        if(result)
            emit TestEvent(true, "");
        else
            emit TestEvent(false, message);
    }

}

error: pathspec 'packages/truffle-core/lib/testing/AssertBytes32.sol' did not match any file(s) known to git


Fix failing test

Fix failing test

import './Conference.sol';
import './zeppelin/PullPaymentCapable.sol';
import './zeppelin/Rejector.sol';
import './zeppelin/Killable.sol';
import './zeppelin/Ownable.sol';

/*
 * Bounty
 * This bounty will pay out if you can cause a Conference's balance
 * to be lower from its totalBalance, which would mean that it doesn't
 * have sufficient ether for everyone to withdraw.
 */
contract Bounty is PullPaymentCapable, Rejector, Ownable, Killable{
  uint public totalBounty;
  uint public totalReseachers;
  bool public claimed;
  mapping(address => address) public researchers;
  event TargetCreation(address createdAddress);
  event Error(string message);

  function Bounty(){
    totalBounty = 0;
    totalReseachers = 0;
  }

  function contribute() {
    totalBounty += msg.value;
    if (claimed) throw;
  }

  function createTarget() returns(Conference) {
    Conference target = new Conference(1 weeks);
    researchers[target] = msg.sender;
    totalReseachers+=1;
    TargetCreation(target);
    return target;
  }

  modifier hasResearcher(Conference target) {
    address researcher = researchers[target];
    if (researcher != 0){
      _
    }else{
      Error('there are no researcher');
    }
  }

  modifier hasBug(Conference target) {
    if (target.totalBalance() > target.balance){
      _
    }else{
      Error('No security breach');
    }
  }

  function claim(Conference target) hasResearcher(target) hasBug(target){
    address researcher = researchers[target];
    asyncSend(researcher, this.balance);
    totalBounty = 0;
    claimed = true;
  }
}

import './Conference.sol';
import './zeppelin/PullPaymentCapable.sol';
import './zeppelin/Rejector.sol';
import './zeppelin/Killable.sol';
import './zeppelin/Ownable.sol';

/*
 * Bounty
 * This bounty will pay out if you can cause a Conference's balance
 * to be lower from its totalBalance, which would mean that it doesn't
 * have sufficient ether for everyone to withdraw.
 */
contract Bounty is PullPaymentCapable, Rejector, Ownable, Killable{
  uint public totalBounty;
  uint public totalReseachers;
  bool public claimed;
  mapping(address => address) public researchers;
  event TargetCreation(address createdAddress);
  event Error(string message);

  function Bounty(){
    totalBounty = 0;
    totalReseachers = 0;
  }

  function contribute() {
    totalBounty += msg.value;
    if (claimed) throw;
  }

  function createTarget() returns(Conference) {
    Conference target = new Conference();
    researchers[target] = msg.sender;
    totalReseachers+=1;
    TargetCreation(target);
    return target;
  }

  modifier hasResearcher(Conference target) {
    address researcher = researchers[target];
    if (researcher != 0){
      _
    }else{
      Error('there are no researcher');
    }
  }

  modifier hasBug(Conference target) {
    if (target.totalBalance() > target.balance){
      _
    }else{
      Error('No security breach');
    }
  }

  function claim(Conference target) hasResearcher(target) hasBug(target){
    address researcher = researchers[target];
    asyncSend(researcher, this.balance);
    totalBounty = 0;
    claimed = true;
  }
}


Modify function's comments

Modify function's comments

pragma solidity ^0.4.11;

import "./ERC20Interface.sol";

contract UTCoin is ERC20Interface {
    string public constant symbol = "UTC";
    string public constant name = "UTCoin";
    uint8 public constant decimals = 18;
    uint256 _totalSupply = 1000000;

    // Owner of this contract
    address public owner;

    // Balances for each account
    mapping(address => uint256) balances;

    // Owner of account approves the transfer of an amount to another account
    mapping(address => mapping (address => uint256)) allowed;

    // Blacklist
    mapping (address => bool) public blacklist;

    // Events
    event TransferOwnership(address _old_addr, address _new_addr);
    event Blacklisted(address indexed _target);
    event DeleteFromBlacklist(address indexed _target);

    // Functions with this modifier can only be executed by the owner
    modifier onlyOwner() {
        require(msg.sender == owner);
        _;
    }

    // Constructor
    function UTCoin() {
        owner = msg.sender;
        balances[owner] = _totalSupply;
    }

    function totalSupply() constant returns (uint256 totalSupply) {
        totalSupply = _totalSupply;
    }

    // What is the balance of a particular account?
    function balanceOf(address _owner) constant returns (uint256 balance) {
        return balances[_owner];
    }

    // Transfer the balance from owner's account to another account
    function transfer(address _to, uint256 _amount) returns (bool success) {
        require(blacklist[msg.sender] == false);
        require(blacklist[_to] == false);

        if (balances[msg.sender] >= _amount
            && _amount > 0
            && balances[_to] + _amount > balances[_to]) {
            balances[msg.sender] -= _amount;
            balances[_to] += _amount;
            Transfer(msg.sender, _to, _amount);
            return true;
        } else {
            return false;
        }
    }

    // Send _value amount of tokens from address _from to address _to
    // The transferFrom method is used for a withdraw workflow, allowing contracts to send
    // tokens on your behalf, for example to "deposit" to a contract address and/or to charge
    // fees in sub-currencies; the command should fail unless the _from account has
    // deliberately authorized the sender of the message via some mechanism; we propose
    // these standardized APIs for approval:
    function transferFrom(address _from, address _to, uint256 _amount) returns (bool success) {
        require(blacklist[_from] == false);
        require(blacklist[_to] == false);

        if (balances[_from] >= _amount
            && allowed[_from][msg.sender] >= _amount
            && _amount > 0
            && balances[_to] + _amount > balances[_to]) {
            balances[_from] -= _amount;
            allowed[_from][msg.sender] -= _amount;
            balances[_to] += _amount;
            Transfer(_from, _to, _amount);
            return true;
        } else {
            return false;
        }
    }

    // Allow _spender to withdraw from your account, multiple times, up to the _value amount.
    // If this function is called again it overwrites the current allowance with _value.
    function approve(address _spender, uint256 _amount) returns (bool success) {
        allowed[msg.sender][_spender] = _amount;
        Approval(msg.sender, _spender, _amount);
        return true;
    }

    function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
        return allowed[_owner][_spender];
    }

    // Add address _addr to blacklist
    function blacklisting(address _addr) onlyOwner {
        blacklist[_addr] = true;
        Blacklisted(_addr);
    }

    // Remove address _addr from blacklist
    function deleteFromBlacklist(address _addr) onlyOwner {
        blacklist[_addr] = false;
        DeleteFromBlacklist(_addr);
    }

    // Transfer ownership to address _new_addr
    function transferOwnership(address _new_addr) onlyOwner {
        address old_addr = owner;
        owner = _new_addr;
        TransferOwnership(old_addr, owner);
    }
}

pragma solidity ^0.4.11;

import "./ERC20Interface.sol";

contract UTCoin is ERC20Interface {
    string public constant symbol = "UTC";
    string public constant name = "UTCoin";
    uint8 public constant decimals = 18;
    uint256 _totalSupply = 1000000;

    // Owner of this contract
    address public owner;

    // Balances for each account
    mapping(address => uint256) balances;

    // Owner of account approves the transfer of an amount to another account
    mapping(address => mapping (address => uint256)) allowed;

    // Blacklist
    mapping (address => bool) public blacklist;

    // Events
    event TransferOwnership(address _old_addr, address _new_addr);
    event Blacklisted(address indexed _target);
    event DeleteFromBlacklist(address indexed _target);

    // Functions with this modifier can only be executed by the owner
    modifier onlyOwner() {
        require(msg.sender == owner);
        _;
    }

    // Constructor
    function UTCoin() {
        owner = msg.sender;
        balances[owner] = _totalSupply;
    }

    function totalSupply() constant returns (uint256 totalSupply) {
        totalSupply = _totalSupply;
    }

    // What is the balance of a particular account?
    function balanceOf(address _owner) constant returns (uint256 balance) {
        return balances[_owner];
    }

    // Transfer the balance from owner's account to another account
    function transfer(address _to, uint256 _amount) returns (bool success) {
        require(blacklist[msg.sender] == false);
        require(blacklist[_to] == false);

        if (balances[msg.sender] >= _amount
            && _amount > 0
            && balances[_to] + _amount > balances[_to]) {
            balances[msg.sender] -= _amount;
            balances[_to] += _amount;
            Transfer(msg.sender, _to, _amount);
            return true;
        } else {
            return false;
        }
    }

    // Send _value amount of tokens from address _from to address _to
    // The transferFrom method is used for a withdraw workflow, allowing contracts to send
    // tokens on your behalf, for example to "deposit" to a contract address and/or to charge
    // fees in sub-currencies; the command should fail unless the _from account has
    // deliberately authorized the sender of the message via some mechanism; we propose
    // these standardized APIs for approval:
    function transferFrom(address _from, address _to, uint256 _amount) returns (bool success) {
        require(blacklist[_from] == false);
        require(blacklist[_to] == false);

        if (balances[_from] >= _amount
            && allowed[_from][msg.sender] >= _amount
            && _amount > 0
            && balances[_to] + _amount > balances[_to]) {
            balances[_from] -= _amount;
            allowed[_from][msg.sender] -= _amount;
            balances[_to] += _amount;
            Transfer(_from, _to, _amount);
            return true;
        } else {
            return false;
        }
    }

    // Allow _spender to withdraw from your account, multiple times, up to the _value amount.
    // If this function is called again it overwrites the current allowance with _value.
    function approve(address _spender, uint256 _amount) returns (bool success) {
        allowed[msg.sender][_spender] = _amount;
        Approval(msg.sender, _spender, _amount);
        return true;
    }

    function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
        return allowed[_owner][_spender];
    }

    /**
     * アドレスをブラックリストに登録
     * @param _addr 対象のアドレス
     */
    function blacklisting(address _addr) onlyOwner {
        blacklist[_addr] = true;
        Blacklisted(_addr);
    }

    /**
     * アドレスをブラックリストから削除
     * @param _addr 対象のアドレス
     */
    function deleteFromBlacklist(address _addr) onlyOwner {
        blacklist[_addr] = false;
        DeleteFromBlacklist(_addr);
    }

    /**
     * オーナーを移転
     * @param _new_addr 移転先のアドレス
     */
    function transferOwnership(address _new_addr) onlyOwner {
        address old_addr = owner;
        owner = _new_addr;
        TransferOwnership(old_addr, owner);
    }
}


Fix typo.

Fix typo.

pragma solidity ^0.4.17;

import "../tokens/IToken.sol";
import "../common/Math.sol";

library InvestorLedger {
    /// Events

    // A state transition in the loan FSM occured.
    event StateTransistion(
        address indexed loan,
        State from,
        State to
    );

    // A new investor has invested.
    event NewInvestor(
        address indexed loan,
        address indexed investor
    );

    // An investment has been sent.
    event InvestmentSent(
        address indexed loan,
        address indexed investor,
        uint256 amount
    );

    enum WithdrawalType {
        Invalid,
        // Address has withdrawn loan tokens.
        LoanTokens,
        // Address has withdrawn collateral tokens.
        CollateralTokens
    }

    // An address has withdrawn funds.
    event Withdrawal(
        address indexed loan,
        address indexed to,
        WithdrawalType withdrawalType,
        uint256 amount
    );

    uint constant PERMIL = 1000;

    enum State {
        // Loan is waiting for collateral to be received from borrower.
        CollateralCollection,
        // Loan is waiting to be funded by investors.
        Fundraising,
        // Loan is waiting for withdrawal from borrower.
        Payback,
        // Loan has been paid back succesfully.
        Paidback,
        // Loan has defaulted before it has been fully paid back.
        Defaulted,
        // Loan has been cancelled by borrower or has not gathered funds in
        // time.
        Canceled
    }

    // legalTransition is a safeguard function to be used in functions that
    // modify the Ledger state. It is not checked when the state does not
    // change (so all A -> A transitions are implicitly allowed).
    function legalTransition(State from, State to) pure private returns (bool legal) {
        // No switch statements in Solidity. We'll use a bunch of if-else
        // blocks, as the alternative is handcrafted assembly.
        if (from == State.CollateralCollection) {
            // Loan has collected collateral.
            if (to == State.Fundraising) {
                return true;
            }
            return false;
        }
        if (from == State.Fundraising) {
            // Loan has raised funds succesfully.
            if (to == State.Payback) {
                return true;
            }
            // Loan has not raised funds succesfully - let borrower and
            // investors (if any) collect their tokens back.
            if (to == State.Canceled) {
                return true;
            }
            return false;
        }
        if (from == State.Payback) {
            // Loan has been paid back successfully.
            if (to == State.Paidback) {
                return true;
            }
            // Loan has defaulted.
            if (to == State.Defaulted) {
                return true;
            }
            return false;
        }
        return false;
    }

    // newState applies a state transition to the ledger FSM and ensures it is
    // legal.
    function newState(Ledger storage ledger, State next) private {
        require(legalTransition(ledger.state, next));
        ledger.state = next;
    }

    // Ledger is the main state object of an ongoing loan ledger.
    struct Ledger {
        /// Constant ledger parameters.
        // Token used as collateral.
        IToken collateralToken;
        // Main loan Token.
        IToken loanToken;
        // Receiver of the loan.
        address borrower;
        // How much loanToken does borrower want to borrow.
        uint256 amountWanted;
        // Interest of loan in permils.
        uint16  interestPermil;
        // Delta (in seconds) between collateral collected and fundraising ending.
        uint64 fundraisingDelta;
        // Delta (in seconds)  between fundraising ending and payback needed.
        uint64 paybackDelta;

        /// Mutable ledger state.
        // Total collateralToken gathered for loan. It increases from 0 to
        // the loan collateral when its' gathered.
        uint256 receivedCollateral;
        // Data about each investor. It gets upserted any time a new investment
        // is added.
        mapping(address => InvestorData) investorData;
        // Sum of all investments, updated when investorData is updated.
        uint256 totalAmountInvested;
        // Absolute timestamp of fundraising deadline, in block time (seconds).
        // Calculated when we switch to the fundraising state.
        uint64 fundraisingDeadline;
        // Absolute timestamp of payback deadline, in block time (seconds).
        // Calculated when we switch to the payback state.
        uint64 paybackDeadline;

        /// Withdrawal counters. These increase as different types of withdrawals
        /// are performed.
        mapping(address => WithdrawalData) withdrawalData;

        /// Main ledger FSM state.
        State state;
    }

    struct InvestorData {
        uint256 amountInvested;
    }

    struct WithdrawalData {
        uint256 loanWithdrawn;
        uint256 collateralWithdrawn;
    }

    /// View functions for the Ledger structure that calculate denormalized
    /// data based on investment status.

    // amountInvested(address) returns how much was invested into this loan by
    // a particular address.
    function amountInvested(Ledger storage ledger, address investor) view public returns (uint256 amount) {
        return ledger.investorData[investor].amountInvested;
    }

    // paybackRequired returns how much payback is/will be required for this
    // loan (loan amount + interest).
    function paybackRequired(Ledger storage ledger) view public returns (uint256 amount) {
        return ledger.amountWanted + calculateInterest(ledger, ledger.amountWanted);
    }

    // calculateInterest is a convenience function to calculate the interest
    // of this loan on a given value.
    function calculateInterest(Ledger storage ledger, uint256 investment) view private returns (uint256 interest) {
        return investment * ledger.interestPermil / PERMIL;
    }

    // openAccount is a static constructor of the Ledger state object.
    // @param collateralToken: Token to be used as collateral during the loan.
    // @param loanToken: Token to be loaned.
    // @param borrower: Receiver of the loan.
    // @param totalLoanNeded: How much loanToken does borrower want to borrow.
    // @param interestPermil: Loan interest, in permil (1/10th of a percent).
    function openAccount(
        IToken collateralToken,
        IToken loanToken,
        address borrower,
        uint256 amountWanted,
        uint16 interestPermil,
        uint64 fundraisingDelta,
        uint64 paybackDelta) internal view returns (Ledger account)
    {
        // Argument validation.
        require(fundraisingDelta > 0);
        require(paybackDelta > 0);
        require(amountWanted > 0);
        require(block.timestamp + fundraisingDelta + paybackDelta > block.timestamp);
        require(block.timestamp + fundraisingDelta + paybackDelta > block.timestamp + fundraisingDelta);

        // Fill new state object.
        account.collateralToken = collateralToken;
        account.loanToken = loanToken;
        account.amountWanted = amountWanted;
        account.interestPermil = interestPermil;
        account.borrower = borrower;
        account.state = State.CollateralCollection;
        account.fundraisingDelta = fundraisingDelta;
        account.paybackDelta = paybackDelta;
        account.fundraisingDeadline = 0;
        account.paybackDeadline = 0;

        // And return it.
        return account;
    }

    function processTimeouts(Ledger storage ledger) public returns (bool) {
        if (ledger.state == State.Fundraising) {
            if (block.timestamp > ledger.fundraisingDeadline) {
                newState(ledger, State.Canceled);
                return false;
            }
        }

        if (ledger.state == State.Payback) {
            if (block.timestamp > ledger.paybackDeadline) {
                newState(ledger, State.Defaulted);
                return false;
            }
        }

        return true;
    }

    // collateralCollectionProcess performs processing within the
    // CollateralCollection state of the loan FSM and possibly advances to its'
    // next state. It can:
    //  - collect the collateral from the borrower and mark the loan as
    //    Fundraising (the loan now has a collateral it needs to send back)
    function collateralCollectionProcess(Ledger storage ledger, address caller) public {
        require(ledger.state == State.CollateralCollection);
        // Only allow borrower to perform the state transition, otherwise we
        // could permit races where a malicious actor performs the state
        // transition when the borrower is not ready to do so.
        if (caller == ledger.borrower) {
            var allowance = ledger.collateralToken.allowance(ledger.borrower, this);
            if (allowance > 0) {
                uint64 timestamp = uint64(block.timestamp);
                ledger.receivedCollateral += allowance;
                newState(ledger, State.Fundraising);
                ledger.fundraisingDeadline = timestamp + ledger.fundraisingDelta;
                require(ledger.fundraisingDeadline > timestamp);
                require(ledger.fundraisingDeadline + ledger.paybackDelta > ledger.fundraisingDeadline);

                require(
                    ledger.collateralToken.transferFrom(
                        ledger.borrower,
                        this,
                        allowance
                    )
                );
            }
        }
    }

    // fundraisingProcess performs processing within the Fundraising state of
    // the loan FSM and possibly advances to its' next state. It can:
    // - collect funds from an investor and mark them in a mapping
    // - if loan is fully funded, send out the investments to the borrower and
    //   advance to the Payback state
    // - if timeout is reached, advance to the Canceled state
    function fundraisingProcess(Ledger storage ledger, address caller) public {
        require(ledger.state == State.Fundraising);

        if (!processTimeouts(ledger)) {
            return;
        }

        uint256 amountNeeded = ledger.amountWanted - ledger.totalAmountInvested;
        address investor = caller;
        // Do not invest more than required to fullfill amountWanted.
        var investmentAmount = Math.min(
            ledger.loanToken.allowance(investor, this),
            amountNeeded
        );
        if (investmentAmount > 0) {
            uint64 timestamp = uint64(block.timestamp);
            var investorData = ledger.investorData[investor];
            if (investorData.amountInvested == 0) {
                NewInvestor(this, investor);
            }
            // Note down the investment.
            require(investorData.amountInvested + investmentAmount > investorData.amountInvested);
            require(ledger.totalAmountInvested + investmentAmount > ledger.totalAmountInvested);
            investorData.amountInvested += investmentAmount;
            ledger.totalAmountInvested += investmentAmount;
            // Did we just gather all investments required?
            if (ledger.totalAmountInvested == ledger.amountWanted) {
                newState(ledger, State.Payback);
                ledger.paybackDeadline = timestamp + ledger.paybackDelta;
            }
            // Transfer the investment to the receiving contract.
            InvestmentSent(this, investor, investmentAmount);
            require(
                ledger.loanToken.transferFrom(
                    investor,
                    this,
                    investmentAmount
                )
            );
            // If this was the last required invesment, transfer all the
            // invested money to the borrower.
            if (ledger.totalAmountInvested == ledger.amountWanted) {
                require(
                    ledger.loanToken.transfer(
                        ledger.borrower,
                        ledger.amountWanted
                    )
                );
            }
        }
    }

    // paybackProcess prforms processing within the Payback state of the loan
    // FSM and possibly advances to its' next state. It can:
    // - collect a full payback from the borrower and advance to the Paidback
    //   state
    // - if timeout is reached, advance to the Paidback state
    function paybackProcess(Ledger storage ledger, address caller) public {
        require(ledger.state == State.Payback);

        if (!processTimeouts(ledger)) {
            return;
        }
        if (caller != ledger.borrower)  {
            return;
        }

        // Gather payback, if possible.
        uint256 payback = paybackRequired(ledger);
        if (ledger.loanToken.allowance(ledger.borrower, this) >= payback) {
            newState(ledger, State.Paidback);
            require(
                ledger.loanToken.transferFrom(
                    ledger.borrower,
                    this,
                    payback
                )
            );
        }
    }

    // canWithdrawLoanToken performs processing to see if a given address can
    // withdraw loan tokens in one of the final states (Paidback, Canceled,
    // Defaulted)
    function canWithdrawLoanToken(Ledger storage ledger, address caller) public returns (uint256 _amount) {
        processTimeouts(ledger);

        if (ledger.state == State.Paidback) {
            // In Paidback, investors can withdraw investment with interest.
            uint256 invested = ledger.investorData[caller].amountInvested;
            invested += calculateInterest(ledger, invested);
            uint256 withdrawn = ledger.withdrawalData[caller].loanWithdrawn;
            return invested - withdrawn;
        }

        if (ledger.state == State.Canceled) {
            // If the loan was canceled before investment was finished,
            // investors can get their investment back without interest.
            invested = ledger.investorData[caller].amountInvested;
            withdrawn = ledger.withdrawalData[caller].loanWithdrawn;
            return invested - withdrawn;
        }

        return 0;
    }

    // canWithdrawCollateralToken performs processing to see if a given address
    // can withdraw collateral tokens in one of the final states (Paidback,
    // Canceled, Defaulted)
    function canWithdrawCollateralToken(Ledger storage ledger, address caller) public returns (uint256 _amount) {
        processTimeouts(ledger);

        if (ledger.state == State.Paidback && caller == ledger.borrower) {
            // In Paidback, the borrower can withdraw their collateral fully.
            uint256 collected = ledger.receivedCollateral;
            uint256 withdrawn = ledger.withdrawalData[caller].collateralWithdrawn;
            return collected - withdrawn;
        }
        if (ledger.state == State.Canceled && caller == ledger.borrower) {
            // In Canceled, the borrower can withdraw their collateral fully.
            collected = ledger.receivedCollateral;
            withdrawn = ledger.withdrawalData[caller].collateralWithdrawn;
            return collected - withdrawn;
        }
        if (ledger.state == State.Defaulted) {
            // In defaulted, investors can withdraw the collateral prorated by
            // their investment.
            collected = ledger.receivedCollateral;
            uint256 invested = ledger.investorData[caller].amountInvested;
            uint256 totalInvested = ledger.totalAmountInvested;
            uint256 share = invested * collected / totalInvested;
            withdrawn = ledger.withdrawalData[caller].collateralWithdrawn;
            return share - withdrawn;
        }

        return 0;
    }

    // withdraw performs withdrawal to a given address of a loan or collateral
    // token (whichever is available).
    function withdraw(Ledger storage ledger, address caller) public {
        uint256 loan = canWithdrawLoanToken(ledger, caller);
        if (loan > 0) {
            ledger.withdrawalData[caller].loanWithdrawn += loan;
            Withdrawal(this, caller, WithdrawalType.LoanTokens, loan);
            require(
                ledger.loanToken.transfer(
                    caller,
                    loan
                )
            );
            return;
        }
        uint256 collateral = canWithdrawCollateralToken(ledger, caller);
        if (collateral > 0) {
            ledger.withdrawalData[caller].collateralWithdrawn += collateral;
            Withdrawal(this, caller, WithdrawalType.CollateralTokens, collateral);
            require(
                ledger.collateralToken.transfer(
                    caller,
                    collateral
                )
            );
            return;
        }
    }

}

pragma solidity ^0.4.17;

import "../tokens/IToken.sol";
import "../common/Math.sol";

library InvestorLedger {
    /// Events

    // A state transition in the loan FSM occured.
    event StateTransistion(
        address indexed loan,
        State from,
        State to
    );

    // A new investor has invested.
    event NewInvestor(
        address indexed loan,
        address indexed investor
    );

    // An investment has been sent.
    event InvestmentSent(
        address indexed loan,
        address indexed investor,
        uint256 amount
    );

    enum WithdrawalType {
        Invalid,
        // Address has withdrawn loan tokens.
        LoanTokens,
        // Address has withdrawn collateral tokens.
        CollateralTokens
    }

    // An address has withdrawn funds.
    event Withdrawal(
        address indexed loan,
        address indexed to,
        WithdrawalType withdrawalType,
        uint256 amount
    );

    uint constant PERMIL = 1000;

    enum State {
        // Loan is waiting for collateral to be received from borrower.
        CollateralCollection,
        // Loan is waiting to be funded by investors.
        Fundraising,
        // Loan is waiting for withdrawal from borrower.
        Payback,
        // Loan has been paid back succesfully.
        Paidback,
        // Loan has defaulted before it has been fully paid back.
        Defaulted,
        // Loan has been cancelled by borrower or has not gathered funds in
        // time.
        Canceled
    }

    // legalTransition is a safeguard function to be used in functions that
    // modify the Ledger state. It is not checked when the state does not
    // change (so all A -> A transitions are implicitly allowed).
    function legalTransition(State from, State to) pure private returns (bool legal) {
        // No switch statements in Solidity. We'll use a bunch of if-else
        // blocks, as the alternative is handcrafted assembly.
        if (from == State.CollateralCollection) {
            // Loan has collected collateral.
            if (to == State.Fundraising) {
                return true;
            }
            return false;
        }
        if (from == State.Fundraising) {
            // Loan has raised funds succesfully.
            if (to == State.Payback) {
                return true;
            }
            // Loan has not raised funds succesfully - let borrower and
            // investors (if any) collect their tokens back.
            if (to == State.Canceled) {
                return true;
            }
            return false;
        }
        if (from == State.Payback) {
            // Loan has been paid back successfully.
            if (to == State.Paidback) {
                return true;
            }
            // Loan has defaulted.
            if (to == State.Defaulted) {
                return true;
            }
            return false;
        }
        return false;
    }

    // newState applies a state transition to the ledger FSM and ensures it is
    // legal.
    function newState(Ledger storage ledger, State next) private {
        require(legalTransition(ledger.state, next));
        ledger.state = next;
    }

    // Ledger is the main state object of an ongoing loan ledger.
    struct Ledger {
        /// Constant ledger parameters.
        // Token used as collateral.
        IToken collateralToken;
        // Main loan Token.
        IToken loanToken;
        // Receiver of the loan.
        address borrower;
        // How much loanToken does borrower want to borrow.
        uint256 amountWanted;
        // Interst of loan in permils.
        uint16  interestPermil;
        // Delta (in seconds) between collateral collected and fundraising ending.
        uint64 fundraisingDelta;
        // Delta (in seconds)  between fundraising ending and payback needed.
        uint64 paybackDelta;

        /// Mutable ledger state.
        // Total collateralToken gathered for loan. It increases from 0 to
        // the loan collateral when its' gathered.
        uint256 receivedCollateral;
        // Data about each investor. It gets upserted any time a new investment
        // is added.
        mapping(address => InvestorData) investorData;
        // Sum of all investments, updated when investorData is updated.
        uint256 totalAmountInvested;
        // Absolute timestamp of fundraising deadline, in block time (seconds).
        // Calculated when we switch to the fundraising state.
        uint64 fundraisingDeadline;
        // Absolute timestamp of payback deadline, in block time (seconds).
        // Calculated when we switch to the payback state.
        uint64 paybackDeadline;

        /// Withdrawal counters. These increase as different types of withdrawals
        /// are performed.
        mapping(address => WithdrawalData) withdrawalData;

        /// Main ledger FSM state.
        State state;
    }

    struct InvestorData {
        uint256 amountInvested;
    }

    struct WithdrawalData {
        uint256 loanWithdrawn;
        uint256 collateralWithdrawn;
    }

    /// View functions for the Ledger structure that calculate denormalized
    /// data based on investment status.

    // amountInvested(address) returns how much was invested into this loan by
    // a particular address.
    function amountInvested(Ledger storage ledger, address investor) view public returns (uint256 amount) {
        return ledger.investorData[investor].amountInvested;
    }

    // paybackRequired returns how much payback is/will be required for this
    // loan (loan amount + interest).
    function paybackRequired(Ledger storage ledger) view public returns (uint256 amount) {
        return ledger.amountWanted + calculateInterest(ledger, ledger.amountWanted);
    }

    // calculateInterest is a convenience function to calculate the interest
    // of this loan on a given value.
    function calculateInterest(Ledger storage ledger, uint256 investment) view private returns (uint256 interest) {
        return investment * ledger.interestPermil / PERMIL;
    }

    // openAccount is a static constructor of the Ledger state object.
    // @param collateralToken: Token to be used as collateral during the loan.
    // @param loanToken: Token to be loaned.
    // @param borrower: Receiver of the loan.
    // @param totalLoanNeded: How much loanToken does borrower want to borrow.
    // @param interestPermil: Loan interest, in permil (1/10th of a percent).
    function openAccount(
        IToken collateralToken,
        IToken loanToken,
        address borrower,
        uint256 amountWanted,
        uint16 interestPermil,
        uint64 fundraisingDelta,
        uint64 paybackDelta) internal view returns (Ledger account)
    {
        // Argument validation.
        require(fundraisingDelta > 0);
        require(paybackDelta > 0);
        require(amountWanted > 0);
        require(block.timestamp + fundraisingDelta + paybackDelta > block.timestamp);
        require(block.timestamp + fundraisingDelta + paybackDelta > block.timestamp + fundraisingDelta);

        // Fill new state object.
        account.collateralToken = collateralToken;
        account.loanToken = loanToken;
        account.amountWanted = amountWanted;
        account.interestPermil = interestPermil;
        account.borrower = borrower;
        account.state = State.CollateralCollection;
        account.fundraisingDelta = fundraisingDelta;
        account.paybackDelta = paybackDelta;
        account.fundraisingDeadline = 0;
        account.paybackDeadline = 0;

        // And return it.
        return account;
    }

    function processTimeouts(Ledger storage ledger) public returns (bool) {
        if (ledger.state == State.Fundraising) {
            if (block.timestamp > ledger.fundraisingDeadline) {
                newState(ledger, State.Canceled);
                return false;
            }
        }

        if (ledger.state == State.Payback) {
            if (block.timestamp > ledger.paybackDeadline) {
                newState(ledger, State.Defaulted);
                return false;
            }
        }

        return true;
    }

    // collateralCollectionProcess performs processing within the
    // CollateralCollection state of the loan FSM and possibly advances to its'
    // next state. It can:
    //  - collect the collateral from the borrower and mark the loan as
    //    Fundraising (the loan now has a collateral it needs to send back)
    function collateralCollectionProcess(Ledger storage ledger, address caller) public {
        require(ledger.state == State.CollateralCollection);
        // Only allow borrower to perform the state transition, otherwise we
        // could permit races where a malicious actor performs the state
        // transition when the borrower is not ready to do so.
        if (caller == ledger.borrower) {
            var allowance = ledger.collateralToken.allowance(ledger.borrower, this);
            if (allowance > 0) {
                uint64 timestamp = uint64(block.timestamp);
                ledger.receivedCollateral += allowance;
                newState(ledger, State.Fundraising);
                ledger.fundraisingDeadline = timestamp + ledger.fundraisingDelta;
                require(ledger.fundraisingDeadline > timestamp);
                require(ledger.fundraisingDeadline + ledger.paybackDelta > ledger.fundraisingDeadline);

                require(
                    ledger.collateralToken.transferFrom(
                        ledger.borrower,
                        this,
                        allowance
                    )
                );
            }
        }
    }

    // fundraisingProcess performs processing within the Fundraising state of
    // the loan FSM and possibly advances to its' next state. It can:
    // - collect funds from an investor and mark them in a mapping
    // - if loan is fully funded, send out the investments to the borrower and
    //   advance to the Payback state
    // - if timeout is reached, advance to the Canceled state
    function fundraisingProcess(Ledger storage ledger, address caller) public {
        require(ledger.state == State.Fundraising);

        if (!processTimeouts(ledger)) {
            return;
        }

        uint256 amountNeeded = ledger.amountWanted - ledger.totalAmountInvested;
        address investor = caller;
        // Do not invest more than required to fullfill amountWanted.
        var investmentAmount = Math.min(
            ledger.loanToken.allowance(investor, this),
            amountNeeded
        );
        if (investmentAmount > 0) {
            uint64 timestamp = uint64(block.timestamp);
            var investorData = ledger.investorData[investor];
            if (investorData.amountInvested == 0) {
                NewInvestor(this, investor);
            }
            // Note down the investment.
            require(investorData.amountInvested + investmentAmount > investorData.amountInvested);
            require(ledger.totalAmountInvested + investmentAmount > ledger.totalAmountInvested);
            investorData.amountInvested += investmentAmount;
            ledger.totalAmountInvested += investmentAmount;
            // Did we just gather all investments required?
            if (ledger.totalAmountInvested == ledger.amountWanted) {
                newState(ledger, State.Payback);
                ledger.paybackDeadline = timestamp + ledger.paybackDelta;
            }
            // Transfer the investment to the receiving contract.
            InvestmentSent(this, investor, investmentAmount);
            require(
                ledger.loanToken.transferFrom(
                    investor,
                    this,
                    investmentAmount
                )
            );
            // If this was the last required invesment, transfer all the
            // invested money to the borrower.
            if (ledger.totalAmountInvested == ledger.amountWanted) {
                require(
                    ledger.loanToken.transfer(
                        ledger.borrower,
                        ledger.amountWanted
                    )
                );
            }
        }
    }

    // paybackProcess prforms processing within the Payback state of the loan
    // FSM and possibly advances to its' next state. It can:
    // - collect a full payback from the borrower and advance to the Paidback
    //   state
    // - if timeout is reached, advance to the Paidback state
    function paybackProcess(Ledger storage ledger, address caller) public {
        require(ledger.state == State.Payback);

        if (!processTimeouts(ledger)) {
            return;
        }
        if (caller != ledger.borrower)  {
            return;
        }

        // Gather payback, if possible.
        uint256 payback = paybackRequired(ledger);
        if (ledger.loanToken.allowance(ledger.borrower, this) >= payback) {
            newState(ledger, State.Paidback);
            require(
                ledger.loanToken.transferFrom(
                    ledger.borrower,
                    this,
                    payback
                )
            );
        }
    }

    // canWithdrawLoanToken performs processing to see if a given address can
    // withdraw loan tokens in one of the final states (Paidback, Canceled,
    // Defaulted)
    function canWithdrawLoanToken(Ledger storage ledger, address caller) public returns (uint256 _amount) {
        processTimeouts(ledger);

        if (ledger.state == State.Paidback) {
            // In Paidback, investors can withdraw investment with interest.
            uint256 invested = ledger.investorData[caller].amountInvested;
            invested += calculateInterest(ledger, invested);
            uint256 withdrawn = ledger.withdrawalData[caller].loanWithdrawn;
            return invested - withdrawn;
        }

        if (ledger.state == State.Canceled) {
            // If the loan was canceled before investment was finished,
            // investors can get their investment back without interest.
            invested = ledger.investorData[caller].amountInvested;
            withdrawn = ledger.withdrawalData[caller].loanWithdrawn;
            return invested - withdrawn;
        }

        return 0;
    }

    // canWithdrawCollateralToken performs processing to see if a given address
    // can withdraw collateral tokens in one of the final states (Paidback,
    // Canceled, Defaulted)
    function canWithdrawCollateralToken(Ledger storage ledger, address caller) public returns (uint256 _amount) {
        processTimeouts(ledger);

        if (ledger.state == State.Paidback && caller == ledger.borrower) {
            // In Paidback, the borrower can withdraw their collateral fully.
            uint256 collected = ledger.receivedCollateral;
            uint256 withdrawn = ledger.withdrawalData[caller].collateralWithdrawn;
            return collected - withdrawn;
        }
        if (ledger.state == State.Canceled && caller == ledger.borrower) {
            // In Canceled, the borrower can withdraw their collateral fully.
            collected = ledger.receivedCollateral;
            withdrawn = ledger.withdrawalData[caller].collateralWithdrawn;
            return collected - withdrawn;
        }
        if (ledger.state == State.Defaulted) {
            // In defaulted, investors can withdraw the collateral prorated by
            // their investment.
            collected = ledger.receivedCollateral;
            uint256 invested = ledger.investorData[caller].amountInvested;
            uint256 totalInvested = ledger.totalAmountInvested;
            uint256 share = invested * collected / totalInvested;
            withdrawn = ledger.withdrawalData[caller].collateralWithdrawn;
            return share - withdrawn;
        }

        return 0;
    }

    // withdraw performs withdrawal to a given address of a loan or collateral
    // token (whichever is available).
    function withdraw(Ledger storage ledger, address caller) public {
        uint256 loan = canWithdrawLoanToken(ledger, caller);
        if (loan > 0) {
            ledger.withdrawalData[caller].loanWithdrawn += loan;
            Withdrawal(this, caller, WithdrawalType.LoanTokens, loan);
            require(
                ledger.loanToken.transfer(
                    caller,
                    loan
                )
            );
            return;
        }
        uint256 collateral = canWithdrawCollateralToken(ledger, caller);
        if (collateral > 0) {
            ledger.withdrawalData[caller].collateralWithdrawn += collateral;
            Withdrawal(this, caller, WithdrawalType.CollateralTokens, collateral);
            require(
                ledger.collateralToken.transfer(
                    caller,
                    collateral
                )
            );
            return;
        }
    }

}


Commented TicTacToeLockedState.sol

Commented TicTacToeLockedState.sol

import "LockedStateWithFunds.sol";

/**
 * TicTacToeLockedState
 *
 * The LockedState for a TicTacToe game.
 */
contract TicTacToeLockedState is LockedState {

    /* bit mappings for state
     * 0: X gets winnings
     * 1: O gets winnings
     * 2: X forfeits adjudication deposit
     * 3: O forfeits adjudication deposit
     * 4: X forfeits disconnect deposit
     * 5: O forfeits disconnect deposit
     * 6: used to indicate cheating. Doesn't change where funds will be sent
     * note, if tie, bits 0 and 1 should both be 0 to indicate tie
     */
    address addressX;
    address addressO;
    address burner;

    uint[6] funds;

    /**
     * addressX: the address of X
     * addressO: the address of O
     * burner: the address which funds will be burned to (usually 0)
     */
    function TicTacToeLockedState(address _addressX, address _addressO, address _burner) {
        addressX = _addressX;
        addressO = _addressO;
        burner = _burner;
    }

    /*
     * Deposits funds into an escrow account.
     *
     * Accounts are as follows:
     * 0: X's bet
     * 1: O's bet
     * 2: X's adjudication deposit
     * 3: O's adjudication deposit
     * 4: X's disconnect deposit
     * 5: O's disconnect deposit
     */
    function deposit(uint account) {
        if (account >= 6) {
            throw;
        } else {
            funds[account] += msg.value;
        }
    }

    /**
     * Checks if a given state is valid.
     * Must be a bytes1 that holds the specified values above.
     * Bits 0 and 1 must not both be 1.
     *
     * state: the state to check
     * returns: true if the state is valid, otherwise false
     */
    function checkState(bytes state) constant returns (bool) {
        if (state.length == 1) {
            return uint8(state[0]) & 0x03 != 0x03;
        } else {
            return false;
        }
    }

    /**
     * Splits the funds according to the state.
     *
     * state: the state that will be broadcast
     * returns: true if transaction sent sucessfully, otherwise false
     */
    function broadcastState(bytes state) external onlyOwner returns (bool) {
        if (!checkState(state)) {
            return false;
        }

        uint sendToX = 0;
        uint sendToO = 0;

        uint uintState = uint(state[0]);

        if (uintState & 0x03 == 0x01) {// X wins, gets bet
            sendToX += funds[0] + funds[1];
        } else if (uintState & 0x03 == 0x02) {// O wins, gets bet
            sendToO += funds[0] + funds[1];
        } else {// tie, they get individual bets back
            sendToX += funds[0];
            sendToO += funds[1];
        }

        // checks if funds should be forfeited
        sendToX += (uintState & 0x04 == 0x00 ? funds[2] : 0) + (uintState & 0x10 == 0x00 ? funds[4] : 0);
        sendToO += (uintState & 0x08 == 0x00 ? funds[3] : 0) + (uintState & 0x20 == 0x00 ? funds[5] : 0);

        if (!addressX.send(sendToX)) {
            throw;
        }

        if (!addressO.send(sendToO)) {
            throw;
        }

        // burns the remaining funds
        if (!burner.send(this.balance)) {
            throw;
        }

        return true;
    }

    // funds should only be sent through the deposit method
    function () {
        throw;
    }
}

import "LockedStateWithFunds.sol";

/**
 * TicTacToeLockedState
 *
 * The LockedState for a TicTacToe game.
 */
contract TicTacToeLockedState is LockedState {

    /* bit mappings for state
     * 0: X gets winnings
     * 1: O gets winnings
     * 2: X forfeits adjudication deposit
     * 3: O forfeits adjudication deposit
     * 4: X forfeits disconnect deposit
     * 5: O forfeits disconnect deposit
     * 6: used to indicate cheating, not used here
     * note, if tie, bits 0 and 1 should both be 0 to indicate tie
     */
    address addressX;
    address addressO;
    address burner = 0;

    uint[6] funds;

    function TicTacToeLockedState(address _addressX, address _addressO) {
        addressX = _addressX;
        addressO = _addressO;
    }

    function deposit(uint account) {
        if (account >= 6) {
            throw;
        } else {
            funds[account] += msg.value;
        }
    }

    /**
     * Checks if a given state is valid.
     * Must be a bytes1 that holds the specified values above.
     *
     * state: the state to check
     * returns: true if the state is valid, otherwise false
     */
    function checkState(bytes state) constant returns (bool) {
        if (state.length == 1) {
            return uint8(state[0]) & 0x03 != 0x03;
        } else {
            return false;
        }
    }

    /**
     * Splits the funds according to the state.
     *
     * state: the state that will be broadcast
     * returns: true if transaction sent sucessfully, otherwise false
     */
    function broadcastState(bytes state) external onlyOwner returns (bool) {
        if (!checkState(state)) {
            return false;
        }

        uint sendToX = 0;
        uint sendToO = 0;

        uint uintState = uint(state[0]);

        if (uintState & 0x03 == 0x01) {
            sendToX += funds[0] + funds[1];
        } else if (uintState & 0x03 == 0x02) {
            sendToO += funds[0] + funds[1];
        } else {
            sendToX += funds[0];
            sendToO += funds[1];
        }

        sendToX += (uintState & 0x04 == 0 ? funds[2] : 0) + (uintState & 0x10 == 0 ? funds[4] : 0);
        sendToO += (uintState & 0x08 == 0 ? funds[3] : 0) + (uintState & 0x20 == 0 ? funds[5] : 0);

        if (!addressX.send(sendToX)) {
            throw;
        }

        if (!addressO.send(sendToO)) {
            throw;
        }

        if (!burner.send(this.balance)) {
            throw;
        }

        return true;
    }

    function () {
        throw;
    }
}


Set start time.

Set start time.

/**
 * @title AcuityRevenue
 * @author Jonathan Brown <jbrown@acuity.social>
 */
contract AcuityRevenue {

    uint128 public startTime;
    uint128 public withdrawn;
    address payable public owner;

    /**
     * @dev The owner of this contract has chanaged.
     * @param oldOwner Old owner of this contract.
     * @param newOwner New Owner of this contract.
     */
    event ChangeOwner(address oldOwner, address newOwner);

    /**
     * @dev A withdrawal has occured.
     * @param recipient Recipient of the withdrawal.
     * @param amount Amount of ACU withdrawn.
     */
    event Withdraw(address recipient, uint amount);

    /**
     * @dev Throws if the sender is not the owner of the contract.
     */
    modifier isOwner() {
        require (msg.sender == owner);
        _;
    }

    /**
     * @dev Constructor.
     */
    constructor() {
        startTime = 1493240400;
        owner = msg.sender;
    }

    /**
     * @dev Changes the owner of the contract.
     * @param newOwner The new owner of the contract.
     */
    function changeOwner(address payable newOwner) external isOwner {
        owner = newOwner;
        emit ChangeOwner(msg.sender, newOwner);
    }

    /**
     * @dev Withdraws any available funds to the owner.
     */
    function withdraw() external isOwner {
        uint128 released = getReleased();
        uint128 amount = released - withdrawn;
        withdrawn = released;
        owner.transfer(amount);
        emit Withdraw(owner, amount);
    }

    /**
     * @dev Determines how much ACU has been released in total so far.
     */
    function getReleased() public view returns (uint128 released) {
        uint128 dailyAmount = 50000 ether;
        int128 elapsed = int128((block.timestamp - startTime) / 1 days);

        while ((dailyAmount != 0) && (elapsed > 0)) {
            if (elapsed < 200) {
                released += uint128(elapsed) * dailyAmount;
            }
            else {
                released += 200 * dailyAmount;
            }
            dailyAmount -= 5000 ether;
            elapsed -= 200;
        }
    }

}

/**
 * @title AcuityRevenue
 * @author Jonathan Brown <jbrown@acuity.social>
 */
contract AcuityRevenue {

    uint128 public startTime;
    uint128 public withdrawn;
    address payable public owner;

    /**
     * @dev The owner of this contract has chanaged.
     * @param oldOwner Old owner of this contract.
     * @param newOwner New Owner of this contract.
     */
    event ChangeOwner(address oldOwner, address newOwner);

    /**
     * @dev A withdrawal has occured.
     * @param recipient Recipient of the withdrawal.
     * @param amount Amount of ACU withdrawn.
     */
    event Withdraw(address recipient, uint amount);

    /**
     * @dev Throws if the sender is not the owner of the contract.
     */
    modifier isOwner() {
        require (msg.sender == owner);
        _;
    }

    /**
     * @dev Constructor.
     */
    constructor() {
        startTime = block.timestamp;
        owner = msg.sender;
    }

    /**
     * @dev Changes the owner of the contract.
     * @param newOwner The new owner of the contract.
     */
    function changeOwner(address payable newOwner) external isOwner {
        owner = newOwner;
        emit ChangeOwner(msg.sender, newOwner);
    }

    /**
     * @dev Withdraws any available funds to the owner.
     */
    function withdraw() external isOwner {
        uint128 released = getReleased();
        uint128 amount = released - withdrawn;
        withdrawn = released;
        owner.transfer(amount);
        emit Withdraw(owner, amount);
    }

    /**
     * @dev Determines how much ACU has been released in total so far.
     */
    function getReleased() public view returns (uint128 released) {
        uint128 dailyAmount = 50000 ether;
        int128 elapsed = int128((block.timestamp - startTime) / 1 days);

        while ((dailyAmount != 0) && (elapsed > 0)) {
            if (elapsed < 200) {
                released += uint128(elapsed) * dailyAmount;
            }
            else {
                released += 200 * dailyAmount;
            }
            dailyAmount -= 5000 ether;
            elapsed -= 200;
        }
    }

}


Create simplestorage.sol

Create simplestorage.sol

pragma solidity ^0.4.0;

contract SimpleStorage {
    uint storedData;

    function set(uint x) {
        storedData = x;
    }

    function get() constant returns (uint) {
        return storedData;
    }
}

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


Update etherToken.sol

Update etherToken.sol

contract ethertoken is token {

    /*Initial */
    function ethertoken() {
        creator = msg.sender;
        symbol = "Wei";
        name = "EthContractWallet";
    }

    function loadBalance() {
        balanceOf[msg.sender] += msg.value;
        totalSupply += msg.value;

    }

    function withdraw(uint256 _value) returns (bool result){
        if (balanceOf[msg.sender] < _value) {return false;}
        msg.sender.send(_value);
        return true;

    }

    function () {
        // This function gets executed if a
        // transaction with invalid data is sent to
        // the contract or just ether without data.
        // We revert the send so that no-one
        // accidentally loses money when using the
        // contract.
        throw;
    }

}

contract ethertoken is token {

    /*Initial */
    function ethertoken() {
        creator = msg.sender;
        symbol = "Wei";
        name = "EthContractWallet";
    }

    function loadBalance() {
        balanceOf[msg.sender] += msg.value;
        totalSupply += msg.value;

    }

    function withdraw(uint256 _value) returns (bool result){
        if (balanceOf[msg.sender] < _value) {return false;}
        if (balanceOf[msg.sender] + _value < balanceOf[msg.sender]) {return false;}
        msg.sender.send(_value);
        return true;

    }

    function () {
        // This function gets executed if a
        // transaction with invalid data is sent to
        // the contract or just ether without data.
        // We revert the send so that no-one
        // accidentally loses money when using the
        // contract.
        throw;
    }

}