Added framework for assessment protocol. Somebody do documentation, we’re even worse than the Solidity dev.

contract Master
{
  function Master()
  {

  }
  mapping(address => uint) tokenBalance;
  mapping(address => string) tagName;
  mapping(string => address) tagAddress;
  mapping(address => string[]) acheivements;
  function addTag(string name, address[] parentList) returns(uint)
  {
    uint response = 0;
    if(tokenBalance[msg.sender] < 1)
    {
      response += 1;
    }
    if(tagAddress[name] == 0)
    {
      response += 10;
    }
    if(response==0)
    {
      Tag newTag;
      address newTagAddress = address(newTag);
      tagName[newTagAddress] = name;
      tagAddress[name] = newTagAddress;
      for(uint i=0; i<= parentList.length; i++)
      {
        if(parentList[i]==0)
        {
          response += 100;
        }
        if(response==0)
        {
          newTag.addParent(parentList[i]);
        }
      }
    }
    newTag.setMaster(address(this));
    return response;
  }
}

contract Tag
{
  address[] parents;
  address masterAddress;
  address[] owners;
  mapping(address => address[]) assessmentHistory;
  mapping(address => uint) scores;
  function Tag()
  {

  }
  function addParent(address parent)
  {
    parents.push(parent);
  }
  function setMaster(address master)
  {
    masterAddress = master;
  }
  function getAssessors(uint randomNumber)
  {

  }
  function startAssessment(address assessee, address[] assessors)
  {
    Assessment newAssessment;
    newAssessment.setAssessee(assessee);
    newAssessment.setAssessors(assessors);
  }
  function getAssessmentResults(bool result, uint score, address assessee, address assessment) returns(bool)
  {
    if(result == true)
    {
      owners.push(assessee);
      scores[assessee] = score;
    }
    assessmentHistory[assessee] = assessment;
    return result;
  }
}

contract Assessment
{
  address assessee;
  address[] assessors;
  mapping(address => uint[]) assessmentData;
  mapping(address => uint[]) assessmentAnswers;
  mapping(address => bool[]) assessmentResults;
  mapping(address => uint[]) assessmentScores;

  function Assessment()
  {

  }
  function setAssessee(address newAssessee)
  {
    assessee = newAssessee;
  }
  function setAssessors(address[] newAssessors)
  {
    assessors = newAssessors;
  }
  function assess()
  {

  }
  function cashout()
  {

  }
}

contract Master
{
  function Master()
  {

  }
  mapping (address => uint) tokenBalance;
  mapping (address => string) tagName;
  mapping (string => address) tagAddress;
  mapping (address => string[]) acheivements;
  function addTag(string name, address[] parentList) returns(uint)
  {
    uint response = 0;
    if(tokenBalance[msg.sender] < 1)
    {
      response += 1;
    }
    if(tagAddress[name] == 0)
    {
      response += 10;
    }
    if(response==0)
    {
      Tag newTag;
      address newTagAddress = address(newTag);
      tagName[newTagAddress] = name;
      tagAddress[name] = newTagAddress;
      for(uint i=0; i<= parentList.length; i++)
      {
        if(parentList[i]==0)
        {
          response += 100;
        }
        if(response==0)
        {
          newTag.addParent(parentList[i]);
        }
      }
    }
    return response;
  }
  function getTagName(address parentAddress) returns(string)
  {
    return tagName[parentAddress];
  }
}

contract Tag
{
  address[] parents;
  function Tag()
  {

  }
  function addParent(address parent)
  {
    parents.push(parent);
  }
}


Added acceptContract() method

Added acceptContract() method

pragma solidity ^0.4.2;

import "./priced.sol";
import "./stateMachine.sol";
import "./accessRestricted.sol";

/// @title Brehon Contract
contract BrehonContract is
    priced,
    stateMachine,
    accessRestricted {
  struct Party {
    address addr;
    bool contractAccepted;
    bool primaryBrehonApproval;
    bool secondaryBrehonApproval;
    bool tertiaryBrehonApproval;
  }

  struct Brehon {
    address addr;
    bool contractAccepted;
    uint fixedFee;
    uint disputeFee;
  }

  uint transactionAmount;
  Party partyA;
  Party partyB;
  Brehon primaryBrehon;
  Brehon secondaryBrehon;
  Brehon tertiaryBrehon;

  modifier eitherByParty(Party _party1, Party _party2)
  {
      if (msg.sender != _party1.addr ||
          msg.sender != _party2.addr)
          throw;
      _;

  }

  modifier eitherByBrehon(Brehon _brehon1, Brehon _brehon2, Brehon _brehon3)
  {
      if (msg.sender != _brehon1.addr ||
          msg.sender != _brehon2.addr ||
          msg.sender != _brehon3.addr)
          throw;
      _;

  }

  function BrehonContract(
      address _partyA,
      address _partyB,
      uint _transactionAmount,
      address _primaryBrehon,
      uint _primaryBrehonFixedFee,
      uint _primaryBrehonDisputeFee,
      address _secondaryBrehon,
      uint _secondaryBrehonFixedFee,
      uint _secondaryBrehonDisputeFee,
      address _tertiaryBrehon,
      uint _tertiaryBrehonFixedFee,
      uint _tertiaryBrehonDisputeFee
  ) {
    partyA.addr = _partyA;
    partyA.primaryBrehonApproval = false;
    partyA.secondaryBrehonApproval = false;
    partyA.tertiaryBrehonApproval = false;

    transactionAmount = _transactionAmount;

    partyB.addr = _partyB;
    partyB.primaryBrehonApproval = false;
    partyB.secondaryBrehonApproval = false;
    partyB.tertiaryBrehonApproval = false;

    primaryBrehon.addr = _primaryBrehon;
    primaryBrehon.fixedFee = _primaryBrehonFixedFee;
    primaryBrehon.disputeFee = _primaryBrehonDisputeFee;

    secondaryBrehon.addr = _secondaryBrehon;
    secondaryBrehon.fixedFee = _secondaryBrehonFixedFee;
    secondaryBrehon.disputeFee = _secondaryBrehonDisputeFee;

    tertiaryBrehon.addr = _tertiaryBrehon;
    tertiaryBrehon.fixedFee = _tertiaryBrehonFixedFee;
    tertiaryBrehon.disputeFee = _tertiaryBrehonDisputeFee;

    //Defaults
    stage = Stages.Negotiation;
    partyA.contractAccepted = false;
    partyB.contractAccepted = false;
    primaryBrehon.contractAccepted = false;
    secondaryBrehon.contractAccepted = false;
    tertiaryBrehon.contractAccepted = false;
  }

  function acceptContract()
    atStage(Stages.Negotiation)
    eitherByParty(partyA, partyB)
    eitherByBrehon(primaryBrehon, secondaryBrehon, tertiaryBrehon)
  {
      if (msg.sender == partyA.addr) {
          partyA.contractAccepted = true;
      } else if (msg.sender == partyB.addr) {
          partyB.contractAccepted = true;
      } else if(msg.sender == primaryBrehon.addr) {
          primaryBrehon.contractAccepted = true;
      } else if(msg.sender == secondaryBrehon.addr) {
          secondaryBrehon.contractAccepted = true;
      } else if(msg.sender == tertiaryBrehon.addr) {
          tertiaryBrehon.contractAccepted = true;
      }
  }

  function nominatePrimaryBrehon(address _primaryBrehon, uint _fixedFee, uint _disputeFee)
    atStage(Stages.Negotiation)
    eitherByParty(partyA, partyB)
  {
    if(msg.sender == partyA.addr &&
      !partyA.primaryBrehonApproval) {
      partyA.primaryBrehonApproval = true;
    }
    if(msg.sender == partyB.addr &&
      !partyB.primaryBrehonApproval) {
      partyB.primaryBrehonApproval = true;
    }
    primaryBrehon.addr = _primaryBrehon;
    primaryBrehon.fixedFee = _fixedFee;
    primaryBrehon.disputeFee = _disputeFee;
  }

  function assignSecondaryBrehon(address _secondaryBrehon, uint _fixedFee, uint _disputeFee)
    atStage(Stages.Negotiation)
  {
    secondaryBrehon.addr = _secondaryBrehon;
    secondaryBrehon.fixedFee = _fixedFee;
    secondaryBrehon.disputeFee = _disputeFee;
  }

  function assignTertiaryBrehon(address _tertiaryBrehon, uint _fixedFee, uint _disputeFee)
    atStage(Stages.Negotiation)
  {
    tertiaryBrehon.addr = _tertiaryBrehon;
    tertiaryBrehon.fixedFee = _fixedFee;
    tertiaryBrehon.disputeFee = _disputeFee;
  }

  function deposit() {
  }

  function startContract() {
  }

  function raiseDispute() {
  }

  function getActiveBrehon() {
  }

  function arbitrate() {
  }

  function claimFunds() {
  }

  function raiseAppeal() {
  }

  function raise2ndAppeal() {
  }
}

pragma solidity ^0.4.2;

import "./priced.sol";
import "./stateMachine.sol";
import "./accessRestricted.sol";

/// @title Brehon Contract
contract BrehonContract is
    priced,
    stateMachine,
    accessRestricted {
  struct Party {
    address addr;
    bool primaryBrehonApproval;
    bool secondaryBrehonApproval;
    bool tertiaryBrehonApproval;
  }

  struct Brehon {
    address addr;
    uint fixedFee;
    uint disputeFee;
  }

  uint transactionAmount;
  Party partyA;
  Party partyB;
  Brehon primaryBrehon;
  Brehon secondaryBrehon;
  Brehon tertiaryBrehon;

  modifier eitherByParty(Party _party1, Party _party2)
  {
      if (msg.sender != _party1.addr ||
          msg.sender != _party2.addr)
          throw;

      _;

  }

  function BrehonContract(
      address _partyA,
      address _partyB,
      uint _transactionAmount,
      address _primaryBrehon,
      uint _primaryBrehonFixedFee,
      uint _primaryBrehonDisputeFee,
      address _secondaryBrehon,
      uint _secondaryBrehonFixedFee,
      uint _secondaryBrehonDisputeFee,
      address _tertiaryBrehon,
      uint _tertiaryBrehonFixedFee,
      uint _tertiaryBrehonDisputeFee
  ) {
    partyA.addr = _partyA;
    partyA.primaryBrehonApproval = false;
    partyA.secondaryBrehonApproval = false;
    partyA.tertiaryBrehonApproval = false;

    transactionAmount = _transactionAmount;

    partyB.addr = _partyB;
    partyB.primaryBrehonApproval = false;
    partyB.secondaryBrehonApproval = false;
    partyB.tertiaryBrehonApproval = false;

    primaryBrehon.addr = _primaryBrehon;
    primaryBrehon.fixedFee = _primaryBrehonFixedFee;
    primaryBrehon.disputeFee = _primaryBrehonDisputeFee;

    secondaryBrehon.addr = _secondaryBrehon;
    secondaryBrehon.fixedFee = _secondaryBrehonFixedFee;
    secondaryBrehon.disputeFee = _secondaryBrehonDisputeFee;

    tertiaryBrehon.addr = _tertiaryBrehon;
    tertiaryBrehon.fixedFee = _tertiaryBrehonFixedFee;
    tertiaryBrehon.disputeFee = _tertiaryBrehonDisputeFee;

    //Defaults
    stage = Stages.Negotiation;
  }

  function acceptContract()
    atStage(Stages.Negotiation)
    eitherByParty(partyA, partyB, primaryBrehon, secondaryBrehon, tertiaryBrehon)
  {
      if (msg.sender == partyA.addr) {
          partyA.primaryBrehonApproval = true;
      } else if (msg.sender == partyB.addr) {
          partyA.primaryBrehonApproval = true;
      }
  }

  function nominatePrimaryBrehon(address _primaryBrehon, uint _fixedFee, uint _disputeFee)
    atStage(Stages.Negotiation)
    eitherByParty(partyA, partyB)
  {
    if(msg.sender == partyA.addr &&
      !partyA.primaryBrehonApproval) {
      partyA.primaryBrehonApproval = true;
    }
    if(msg.sender == partyB.addr &&
      !partyB.primaryBrehonApproval) {
      partyB.primaryBrehonApproval = true;
    }
    primaryBrehon.addr = _primaryBrehon;
    primaryBrehon.fixedFee = _fixedFee;
    primaryBrehon.disputeFee = _disputeFee;
  }

  function assignSecondaryBrehon(address _secondaryBrehon, uint _fixedFee, uint _disputeFee)
    atStage(Stages.Negotiation)
  {
    secondaryBrehon.addr = _secondaryBrehon;
    secondaryBrehon.fixedFee = _fixedFee;
    secondaryBrehon.disputeFee = _disputeFee;
  }

  function assignTertiaryBrehon(address _tertiaryBrehon, uint _fixedFee, uint _disputeFee)
    atStage(Stages.Negotiation)
  {
    tertiaryBrehon.addr = _tertiaryBrehon;
    tertiaryBrehon.fixedFee = _fixedFee;
    tertiaryBrehon.disputeFee = _disputeFee;
  }

  function deposit() {
  }

  function startContract() {
  }

  function raiseDispute() {
  }

  function getActiveBrehon() {
  }

  function arbitrate() {
  }

  function claimFunds() {
  }

  function raiseAppeal() {
  }

  function raise2ndAppeal() {
  }
}


-Added atDisputeStages() modifier

-Added atDisputeStages() modifier

pragma solidity ^0.4.2;

import "./priced.sol";
import "./stateMachine.sol";
import "./accessRestricted.sol";

/// @title Brehon Contract
contract BrehonContract is
    priced,
    stateMachine,
    accessRestricted {

  struct Party {
    address addr;
    uint deposit;
    bool contractAccepted;
    bool primaryBrehonApproval;
    bool secondaryBrehonApproval;
    bool tertiaryBrehonApproval;
  }

  struct Brehon {
    address addr;
    bool contractAccepted;
    uint fixedFee;
    uint disputeFee;
  }

  int8 public appealLevel;
  uint public transactionAmount;
  Party public partyA;
  Party public partyB;
  Brehon public primaryBrehon;
  Brehon public secondaryBrehon;
  Brehon public tertiaryBrehon;
  Brehon public activeBrehon;

  mapping (address => uint) awards;

  uint appealPeriodInDays = 5;
  uint public appealPeriodStartTime;

  event ExecutionStarted(address _partyA, address _partyB, uint _totalDeposits);
  event ContractDisputed(address _disputingParty, address _activeBrehon);
  event AppealPeriodStarted(int8 _appealLevel, uint _startTime, address _activeBrehon, uint _awardPartyA, uint _awardPartyB);
  event AppealRaised(int8 _appealLevel, address _activeBrehon);

  modifier eitherByParty(Party _party1, Party _party2)
  {
    if (msg.sender != _party1.addr ||
        msg.sender != _party2.addr)
        throw;
    _;
  }

  modifier atDisputeStages()
  {
    if(stage != Stages.Dispute &&
       stage != Stages.Resolution &&
       stage != Stages.AppealPeriod &&
       stage != Stages.Appeal)
        throw;
    _;
  }

  modifier eitherByBrehon(Brehon _brehon1, Brehon _brehon2, Brehon _brehon3)
  {
    if (msg.sender != _brehon1.addr ||
        msg.sender != _brehon2.addr ||
        msg.sender != _brehon3.addr)
        throw;
    _;
  }

  modifier onlyByBrehon(Brehon _brehon) {
    if (msg.sender != _brehon.addr)
        throw;
    _;
  }

  function BrehonContract(
      address _partyA,
      address _partyB,
      uint _transactionAmount,
      address _primaryBrehon,
      uint _primaryBrehonFixedFee,
      uint _primaryBrehonDisputeFee,
      address _secondaryBrehon,
      uint _secondaryBrehonFixedFee,
      uint _secondaryBrehonDisputeFee,
      address _tertiaryBrehon,
      uint _tertiaryBrehonFixedFee,
      uint _tertiaryBrehonDisputeFee
  ) {
    partyA.addr = _partyA;
    transactionAmount = _transactionAmount;

    partyB.addr = _partyB;

    primaryBrehon.addr = _primaryBrehon;
    primaryBrehon.fixedFee = _primaryBrehonFixedFee;
    primaryBrehon.disputeFee = _primaryBrehonDisputeFee;

    secondaryBrehon.addr = _secondaryBrehon;
    secondaryBrehon.fixedFee = _secondaryBrehonFixedFee;
    secondaryBrehon.disputeFee = _secondaryBrehonDisputeFee;

    tertiaryBrehon.addr = _tertiaryBrehon;
    tertiaryBrehon.fixedFee = _tertiaryBrehonFixedFee;
    tertiaryBrehon.disputeFee = _tertiaryBrehonDisputeFee;

    //Defaults
    stage = Stages.Negotiation;
    appealLevel = -1;
    partyA.contractAccepted = false;
    partyA.primaryBrehonApproval = false;
    partyA.secondaryBrehonApproval = false;
    partyA.tertiaryBrehonApproval = false;
    partyA.deposit = 0;

    partyB.contractAccepted = false;
    partyB.primaryBrehonApproval = false;
    partyB.secondaryBrehonApproval = false;
    partyB.tertiaryBrehonApproval = false;
    partyB.deposit = 0;

    primaryBrehon.contractAccepted = false;
    secondaryBrehon.contractAccepted = false;
    tertiaryBrehon.contractAccepted = false;
  }

  function acceptContract()
    atStage(Stages.Negotiation)
    eitherByParty(partyA, partyB)
    eitherByBrehon(primaryBrehon, secondaryBrehon, tertiaryBrehon)
  {
      if (msg.sender == partyA.addr) {
          partyA.contractAccepted = true;
      } else if (msg.sender == partyB.addr) {
          partyB.contractAccepted = true;
      } else if(msg.sender == primaryBrehon.addr) {
          primaryBrehon.contractAccepted = true;
      } else if(msg.sender == secondaryBrehon.addr) {
          secondaryBrehon.contractAccepted = true;
      } else if(msg.sender == tertiaryBrehon.addr) {
          tertiaryBrehon.contractAccepted = true;
      } else throw;
  }

  function deposit()
    payable
    eitherByParty(partyA, partyB)
  {
      if(msg.sender == partyA.addr) {
          partyA.deposit += msg.value;
      } else if (msg.sender == partyB.addr) {
          partyB.deposit += msg.value;
      } else throw;
  }

  function startContract()
    atStage(Stages.Negotiation)
    eitherByParty(partyA, partyB)
  {
      if ((partyA.deposit + partyB.deposit) >
          (primaryBrehon.fixedFee + primaryBrehon.disputeFee +
          secondaryBrehon.fixedFee + secondaryBrehon.disputeFee +
          tertiaryBrehon.fixedFee + tertiaryBrehon.disputeFee) +
          transactionAmount
         ) {
             ExecutionStarted(partyA.addr, partyB.addr, partyA.deposit + partyB.deposit);
             stage = Stages.Execution;
      }
  }

  function raiseDispute()
    atStage(Stages.Execution)
    eitherByParty(partyA, partyB)
  {
    stage = Stages.Dispute;
    appealLevel = 0;
    activeBrehon = primaryBrehon;
    ContractDisputed(msg.sender, primaryBrehon.addr);
  }

  function adjudicate(uint _awardPartyA, uint _awardPartyB)
    atStage(Stages.Dispute)
    onlyByBrehon(activeBrehon)
  {
    stage = Stages.AppealPeriod;
    appealPeriodStartTime = now;

    awards[partyA.addr] = _awardPartyA;
    awards[partyB.addr] = _awardPartyB;

    AppealPeriodStarted(appealLevel, appealPeriodInDays, activeBrehon.addr, _awardPartyA, _awardPartyB);
  }

  function claimFunds()
    timedTransition(appealPeriodStartTime, appealPeriodInDays, Stages.AppealPeriod, Stages.Completed)
    atStage(Stages.Completed)
    eitherByParty(partyA, partyB)
    returns (bool)
  {
    uint amount = awards[msg.sender];
    awards[msg.sender] = 0;
    if(msg.sender.send(amount)) {
      return true;
    } else {
    awards[msg.sender] = amount;
      return false;
    }
  }

  function raiseAppeal()
    atStage(Stages.AppealPeriod)
    eitherByParty(partyA, partyB)
  {
    stage = Stages.Dispute;
    appealLevel = 1;

    activeBrehon = secondaryBrehon;

    AppealRaised(appealLevel, activeBrehon.addr);
  }

  function raise2ndAppeal()
    atStage(Stages.AppealPeriod)
    eitherByParty(partyA, partyB)
  {
    stage = Stages.Dispute;
    appealLevel = 2;

    activeBrehon = tertiaryBrehon;

    AppealRaised(appealLevel, activeBrehon.addr);
  }

  function proposeSettlement()
    atDisputeStages()
  {
  }

  function acceptSettlement() {
  }
}

pragma solidity ^0.4.2;

import "./priced.sol";
import "./stateMachine.sol";
import "./accessRestricted.sol";

/// @title Brehon Contract
contract BrehonContract is
    priced,
    stateMachine,
    accessRestricted {

  struct Party {
    address addr;
    uint deposit;
    bool contractAccepted;
    bool primaryBrehonApproval;
    bool secondaryBrehonApproval;
    bool tertiaryBrehonApproval;
  }

  struct Brehon {
    address addr;
    bool contractAccepted;
    uint fixedFee;
    uint disputeFee;
  }

  int8 public appealLevel;
  uint public transactionAmount;
  Party public partyA;
  Party public partyB;
  Brehon public primaryBrehon;
  Brehon public secondaryBrehon;
  Brehon public tertiaryBrehon;
  Brehon public activeBrehon;

  mapping (address => uint) awards;

  uint appealPeriodInDays = 5;
  uint public appealPeriodStartTime;

  event ExecutionStarted(address _partyA, address _partyB, uint _totalDeposits);
  event ContractDisputed(address _disputingParty, address _activeBrehon);
  event AppealPeriodStarted(int8 _appealLevel, uint _startTime, address _activeBrehon, uint _awardPartyA, uint _awardPartyB);
  event AppealRaised(int8 _appealLevel, address _activeBrehon);

  modifier eitherByParty(Party _party1, Party _party2)
  {
    if (msg.sender != _party1.addr ||
        msg.sender != _party2.addr)
        throw;
    _;
  }

  modifier eitherByBrehon(Brehon _brehon1, Brehon _brehon2, Brehon _brehon3)
  {
    if (msg.sender != _brehon1.addr ||
        msg.sender != _brehon2.addr ||
        msg.sender != _brehon3.addr)
        throw;
    _;
  }

  modifier onlyByBrehon(Brehon _brehon) {
    if (msg.sender != _brehon.addr)
        throw;
    _;
  }

  function BrehonContract(
      address _partyA,
      address _partyB,
      uint _transactionAmount,
      address _primaryBrehon,
      uint _primaryBrehonFixedFee,
      uint _primaryBrehonDisputeFee,
      address _secondaryBrehon,
      uint _secondaryBrehonFixedFee,
      uint _secondaryBrehonDisputeFee,
      address _tertiaryBrehon,
      uint _tertiaryBrehonFixedFee,
      uint _tertiaryBrehonDisputeFee
  ) {
    partyA.addr = _partyA;
    transactionAmount = _transactionAmount;

    partyB.addr = _partyB;

    primaryBrehon.addr = _primaryBrehon;
    primaryBrehon.fixedFee = _primaryBrehonFixedFee;
    primaryBrehon.disputeFee = _primaryBrehonDisputeFee;

    secondaryBrehon.addr = _secondaryBrehon;
    secondaryBrehon.fixedFee = _secondaryBrehonFixedFee;
    secondaryBrehon.disputeFee = _secondaryBrehonDisputeFee;

    tertiaryBrehon.addr = _tertiaryBrehon;
    tertiaryBrehon.fixedFee = _tertiaryBrehonFixedFee;
    tertiaryBrehon.disputeFee = _tertiaryBrehonDisputeFee;

    //Defaults
    stage = Stages.Negotiation;
    appealLevel = -1;
    partyA.contractAccepted = false;
    partyA.primaryBrehonApproval = false;
    partyA.secondaryBrehonApproval = false;
    partyA.tertiaryBrehonApproval = false;
    partyA.deposit = 0;

    partyB.contractAccepted = false;
    partyB.primaryBrehonApproval = false;
    partyB.secondaryBrehonApproval = false;
    partyB.tertiaryBrehonApproval = false;
    partyB.deposit = 0;

    primaryBrehon.contractAccepted = false;
    secondaryBrehon.contractAccepted = false;
    tertiaryBrehon.contractAccepted = false;
  }

  function acceptContract()
    atStage(Stages.Negotiation)
    eitherByParty(partyA, partyB)
    eitherByBrehon(primaryBrehon, secondaryBrehon, tertiaryBrehon)
  {
      if (msg.sender == partyA.addr) {
          partyA.contractAccepted = true;
      } else if (msg.sender == partyB.addr) {
          partyB.contractAccepted = true;
      } else if(msg.sender == primaryBrehon.addr) {
          primaryBrehon.contractAccepted = true;
      } else if(msg.sender == secondaryBrehon.addr) {
          secondaryBrehon.contractAccepted = true;
      } else if(msg.sender == tertiaryBrehon.addr) {
          tertiaryBrehon.contractAccepted = true;
      } else throw;
  }

  function deposit()
    payable
    eitherByParty(partyA, partyB)
  {
      if(msg.sender == partyA.addr) {
          partyA.deposit += msg.value;
      } else if (msg.sender == partyB.addr) {
          partyB.deposit += msg.value;
      } else throw;
  }

  function startContract()
    atStage(Stages.Negotiation)
    eitherByParty(partyA, partyB)
  {
      if ((partyA.deposit + partyB.deposit) >
          (primaryBrehon.fixedFee + primaryBrehon.disputeFee +
          secondaryBrehon.fixedFee + secondaryBrehon.disputeFee +
          tertiaryBrehon.fixedFee + tertiaryBrehon.disputeFee) +
          transactionAmount
         ) {
             ExecutionStarted(partyA.addr, partyB.addr, partyA.deposit + partyB.deposit);
             stage = Stages.Execution;
      }
  }

  function raiseDispute()
    atStage(Stages.Execution)
    eitherByParty(partyA, partyB)
  {
    stage = Stages.Dispute;
    appealLevel = 0;
    activeBrehon = primaryBrehon;
    ContractDisputed(msg.sender, primaryBrehon.addr);
  }

  function adjudicate(uint _awardPartyA, uint _awardPartyB)
    atStage(Stages.Dispute)
    onlyByBrehon(activeBrehon)
  {
    stage = Stages.AppealPeriod;
    appealPeriodStartTime = now;

    awards[partyA.addr] = _awardPartyA;
    awards[partyB.addr] = _awardPartyB;

    AppealPeriodStarted(appealLevel, appealPeriodInDays, activeBrehon.addr, _awardPartyA, _awardPartyB);
  }

  function claimFunds()
    timedTransition(appealPeriodStartTime, appealPeriodInDays, Stages.AppealPeriod, Stages.Completed)
    atStage(Stages.Completed)
    eitherByParty(partyA, partyB)
    returns (bool)
  {
    uint amount = awards[msg.sender];
    awards[msg.sender] = 0;
    if(msg.sender.send(amount)) {
      return true;
    } else {
    awards[msg.sender] = amount;
      return false;
    }
  }

  function raiseAppeal()
    atStage(Stages.AppealPeriod)
    eitherByParty(partyA, partyB)
  {
    stage = Stages.Dispute;
    appealLevel = 1;

    activeBrehon = secondaryBrehon;

    AppealRaised(appealLevel, activeBrehon.addr);
  }

  function raise2ndAppeal()
    atStage(Stages.AppealPeriod)
    eitherByParty(partyA, partyB)
  {
    stage = Stages.Dispute;
    appealLevel = 2;

    activeBrehon = tertiaryBrehon;

    AppealRaised(appealLevel, activeBrehon.addr);
  }

  function proposeSettlement() {
  }

  function acceptSettlement() {
  }
}


Added comments for Rules.sol

Added comments for Rules.sol

import "Adjudicator.sol";
import "LockedState.sol";

/**
 * Rules
 *
 * The rules of the state channel. Will be further implemented by any inheriting contracts.
 */
contract Rules {

    // Event triggered when a new state channel is created (this contract is initialised)
    event StateChannelCreated(address Adjudicator, address LockedState);

    Adjudicator adjudicator;

    // Creates a new Rules
    function Rules() {
        adjudicator = createAdjudicator();
        StateChannelCreated(adjudicator, adjudicator.getLockedStateAddress());
    }

    // An abstract method which create and return an Adjudicator. The Adjudicator will be owned by this contract.
    function createAdjudicator() internal returns (Adjudicator);

    // you may define the rules and exposure conditions of the state channel
    // in a subcontract that inherits from this contract
}

import "Adjudicator.sol";
import "LockedState.sol";

contract Rules {

    event StateChannelCreated(address Adjudicator, address LockedState);

    Adjudicator adjudicator;

    function Rules() {
        adjudicator = createAdjudicator();
        StateChannelCreated(adjudicator, adjudicator.getLockedStateAddress());
    }

    function createAdjudicator() internal returns (Adjudicator);

    // you may define the rules and exposure conditions of the state channel
    // in a subcontract that inherits from this contract
}


Fix typo: "an uint256" -> "a uint256" (#1658)

Using "a" instead of "an" makes this consistent with the comment on `allowance`.

pragma solidity ^0.5.2;

import "./IERC20.sol";
import "../../math/SafeMath.sol";

/**
 * @title Standard ERC20 token
 *
 * @dev Implementation of the basic standard token.
 * https://eips.ethereum.org/EIPS/eip-20
 * Originally based on code by FirstBlood:
 * https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
 *
 * This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
 * all accounts just by listening to said events. Note that this isn't required by the specification, and other
 * compliant implementations may not do it.
 */
contract ERC20 is IERC20 {
    using SafeMath for uint256;

    mapping (address => uint256) private _balances;

    mapping (address => mapping (address => uint256)) private _allowed;

    uint256 private _totalSupply;

    /**
     * @dev Total number of tokens in existence
     */
    function totalSupply() public view returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev Gets the balance of the specified address.
     * @param owner The address to query the balance of.
     * @return A uint256 representing the amount owned by the passed address.
     */
    function balanceOf(address owner) public view returns (uint256) {
        return _balances[owner];
    }

    /**
     * @dev Function to check the amount of tokens that an owner allowed to a spender.
     * @param owner address The address which owns the funds.
     * @param spender address The address which will spend the funds.
     * @return A uint256 specifying the amount of tokens still available for the spender.
     */
    function allowance(address owner, address spender) public view returns (uint256) {
        return _allowed[owner][spender];
    }

    /**
     * @dev Transfer token to a specified address
     * @param to The address to transfer to.
     * @param value The amount to be transferred.
     */
    function transfer(address to, uint256 value) public returns (bool) {
        _transfer(msg.sender, to, value);
        return true;
    }

    /**
     * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
     * Beware that changing an allowance with this method brings the risk that someone may use both the old
     * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
     * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     */
    function approve(address spender, uint256 value) public returns (bool) {
        _approve(msg.sender, spender, value);
        return true;
    }

    /**
     * @dev Transfer tokens from one address to another.
     * Note that while this function emits an Approval event, this is not required as per the specification,
     * and other compliant implementations may not emit the event.
     * @param from address The address which you want to send tokens from
     * @param to address The address which you want to transfer to
     * @param value uint256 the amount of tokens to be transferred
     */
    function transferFrom(address from, address to, uint256 value) public returns (bool) {
        _transfer(from, to, value);
        _approve(from, msg.sender, _allowed[from][msg.sender].sub(value));
        return true;
    }

    /**
     * @dev Increase the amount of tokens that an owner allowed to a spender.
     * approve should be called when _allowed[msg.sender][spender] == 0. To increment
     * allowed value is better to use this function to avoid 2 calls (and wait until
     * the first transaction is mined)
     * From MonolithDAO Token.sol
     * Emits an Approval event.
     * @param spender The address which will spend the funds.
     * @param addedValue The amount of tokens to increase the allowance by.
     */
    function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
        _approve(msg.sender, spender, _allowed[msg.sender][spender].add(addedValue));
        return true;
    }

    /**
     * @dev Decrease the amount of tokens that an owner allowed to a spender.
     * approve should be called when _allowed[msg.sender][spender] == 0. To decrement
     * allowed value is better to use this function to avoid 2 calls (and wait until
     * the first transaction is mined)
     * From MonolithDAO Token.sol
     * Emits an Approval event.
     * @param spender The address which will spend the funds.
     * @param subtractedValue The amount of tokens to decrease the allowance by.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
        _approve(msg.sender, spender, _allowed[msg.sender][spender].sub(subtractedValue));
        return true;
    }

    /**
     * @dev Transfer token for a specified addresses
     * @param from The address to transfer from.
     * @param to The address to transfer to.
     * @param value The amount to be transferred.
     */
    function _transfer(address from, address to, uint256 value) internal {
        require(to != address(0));

        _balances[from] = _balances[from].sub(value);
        _balances[to] = _balances[to].add(value);
        emit Transfer(from, to, value);
    }

    /**
     * @dev Internal function that mints an amount of the token and assigns it to
     * an account. This encapsulates the modification of balances such that the
     * proper events are emitted.
     * @param account The account that will receive the created tokens.
     * @param value The amount that will be created.
     */
    function _mint(address account, uint256 value) internal {
        require(account != address(0));

        _totalSupply = _totalSupply.add(value);
        _balances[account] = _balances[account].add(value);
        emit Transfer(address(0), account, value);
    }

    /**
     * @dev Internal function that burns an amount of the token of a given
     * account.
     * @param account The account whose tokens will be burnt.
     * @param value The amount that will be burnt.
     */
    function _burn(address account, uint256 value) internal {
        require(account != address(0));

        _totalSupply = _totalSupply.sub(value);
        _balances[account] = _balances[account].sub(value);
        emit Transfer(account, address(0), value);
    }

    /**
     * @dev Approve an address to spend another addresses' tokens.
     * @param owner The address that owns the tokens.
     * @param spender The address that will spend the tokens.
     * @param value The number of tokens that can be spent.
     */
    function _approve(address owner, address spender, uint256 value) internal {
        require(spender != address(0));
        require(owner != address(0));

        _allowed[owner][spender] = value;
        emit Approval(owner, spender, value);
    }

    /**
     * @dev Internal function that burns an amount of the token of a given
     * account, deducting from the sender's allowance for said account. Uses the
     * internal burn function.
     * Emits an Approval event (reflecting the reduced allowance).
     * @param account The account whose tokens will be burnt.
     * @param value The amount that will be burnt.
     */
    function _burnFrom(address account, uint256 value) internal {
        _burn(account, value);
        _approve(account, msg.sender, _allowed[account][msg.sender].sub(value));
    }
}

pragma solidity ^0.5.2;

import "./IERC20.sol";
import "../../math/SafeMath.sol";

/**
 * @title Standard ERC20 token
 *
 * @dev Implementation of the basic standard token.
 * https://eips.ethereum.org/EIPS/eip-20
 * Originally based on code by FirstBlood:
 * https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
 *
 * This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
 * all accounts just by listening to said events. Note that this isn't required by the specification, and other
 * compliant implementations may not do it.
 */
contract ERC20 is IERC20 {
    using SafeMath for uint256;

    mapping (address => uint256) private _balances;

    mapping (address => mapping (address => uint256)) private _allowed;

    uint256 private _totalSupply;

    /**
     * @dev Total number of tokens in existence
     */
    function totalSupply() public view returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev Gets the balance of the specified address.
     * @param owner The address to query the balance of.
     * @return An uint256 representing the amount owned by the passed address.
     */
    function balanceOf(address owner) public view returns (uint256) {
        return _balances[owner];
    }

    /**
     * @dev Function to check the amount of tokens that an owner allowed to a spender.
     * @param owner address The address which owns the funds.
     * @param spender address The address which will spend the funds.
     * @return A uint256 specifying the amount of tokens still available for the spender.
     */
    function allowance(address owner, address spender) public view returns (uint256) {
        return _allowed[owner][spender];
    }

    /**
     * @dev Transfer token to a specified address
     * @param to The address to transfer to.
     * @param value The amount to be transferred.
     */
    function transfer(address to, uint256 value) public returns (bool) {
        _transfer(msg.sender, to, value);
        return true;
    }

    /**
     * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
     * Beware that changing an allowance with this method brings the risk that someone may use both the old
     * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
     * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     */
    function approve(address spender, uint256 value) public returns (bool) {
        _approve(msg.sender, spender, value);
        return true;
    }

    /**
     * @dev Transfer tokens from one address to another.
     * Note that while this function emits an Approval event, this is not required as per the specification,
     * and other compliant implementations may not emit the event.
     * @param from address The address which you want to send tokens from
     * @param to address The address which you want to transfer to
     * @param value uint256 the amount of tokens to be transferred
     */
    function transferFrom(address from, address to, uint256 value) public returns (bool) {
        _transfer(from, to, value);
        _approve(from, msg.sender, _allowed[from][msg.sender].sub(value));
        return true;
    }

    /**
     * @dev Increase the amount of tokens that an owner allowed to a spender.
     * approve should be called when _allowed[msg.sender][spender] == 0. To increment
     * allowed value is better to use this function to avoid 2 calls (and wait until
     * the first transaction is mined)
     * From MonolithDAO Token.sol
     * Emits an Approval event.
     * @param spender The address which will spend the funds.
     * @param addedValue The amount of tokens to increase the allowance by.
     */
    function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
        _approve(msg.sender, spender, _allowed[msg.sender][spender].add(addedValue));
        return true;
    }

    /**
     * @dev Decrease the amount of tokens that an owner allowed to a spender.
     * approve should be called when _allowed[msg.sender][spender] == 0. To decrement
     * allowed value is better to use this function to avoid 2 calls (and wait until
     * the first transaction is mined)
     * From MonolithDAO Token.sol
     * Emits an Approval event.
     * @param spender The address which will spend the funds.
     * @param subtractedValue The amount of tokens to decrease the allowance by.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
        _approve(msg.sender, spender, _allowed[msg.sender][spender].sub(subtractedValue));
        return true;
    }

    /**
     * @dev Transfer token for a specified addresses
     * @param from The address to transfer from.
     * @param to The address to transfer to.
     * @param value The amount to be transferred.
     */
    function _transfer(address from, address to, uint256 value) internal {
        require(to != address(0));

        _balances[from] = _balances[from].sub(value);
        _balances[to] = _balances[to].add(value);
        emit Transfer(from, to, value);
    }

    /**
     * @dev Internal function that mints an amount of the token and assigns it to
     * an account. This encapsulates the modification of balances such that the
     * proper events are emitted.
     * @param account The account that will receive the created tokens.
     * @param value The amount that will be created.
     */
    function _mint(address account, uint256 value) internal {
        require(account != address(0));

        _totalSupply = _totalSupply.add(value);
        _balances[account] = _balances[account].add(value);
        emit Transfer(address(0), account, value);
    }

    /**
     * @dev Internal function that burns an amount of the token of a given
     * account.
     * @param account The account whose tokens will be burnt.
     * @param value The amount that will be burnt.
     */
    function _burn(address account, uint256 value) internal {
        require(account != address(0));

        _totalSupply = _totalSupply.sub(value);
        _balances[account] = _balances[account].sub(value);
        emit Transfer(account, address(0), value);
    }

    /**
     * @dev Approve an address to spend another addresses' tokens.
     * @param owner The address that owns the tokens.
     * @param spender The address that will spend the tokens.
     * @param value The number of tokens that can be spent.
     */
    function _approve(address owner, address spender, uint256 value) internal {
        require(spender != address(0));
        require(owner != address(0));

        _allowed[owner][spender] = value;
        emit Approval(owner, spender, value);
    }

    /**
     * @dev Internal function that burns an amount of the token of a given
     * account, deducting from the sender's allowance for said account. Uses the
     * internal burn function.
     * Emits an Approval event (reflecting the reduced allowance).
     * @param account The account whose tokens will be burnt.
     * @param value The amount that will be burnt.
     */
    function _burnFrom(address account, uint256 value) internal {
        _burn(account, value);
        _approve(account, msg.sender, _allowed[account][msg.sender].sub(value));
    }
}


Updated contract

Updated contract

contract NewPoll {

  //defines the poll
  struct Poll {
    address owner;
    string title;
    uint votelimit;
    string options;
    uint deadline;
    bool status;
    bytes32[] votes;
  }

  //declares the variables
  uint numVotes = 0;
  Poll public p;

  //initiator function that stores the necessary poll information
  function NewPoll(string _options, string _title, uint _votelimit, uint _deadline) {
    p.owner = msg.sender;
    p.options = _options;
    p.title = _title;
    p.votelimit = _votelimit;
    p.deadline = _deadline;
    p.status = true;
  }

  //function for user vote. input is a string choice
  function vote(bytes32 choice) returns (bool) {
    if (msg.sender != p.owner || p.status != true) {
      return false;
    }
    p.votes[numVotes] = choice;
    numVotes++;
    if (p.votelimit > 0) {
        if (numVotes >= p.votelimit) {
          endPoll();
        }
    }
    return true;
  }

  //when time or vote limit is reached, set the poll status to false
  function endPoll() returns (bool) {
    if (msg.sender != p.owner) {
      return false;
    }
    p.status = false;
    return true;
  }
}

contract NewPoll {

  //defines the poll
  struct Poll {
    address owner;
    string title;
    uint votelimit;
    string options;
    uint deadline;
    bool status;
  }

  //if someone voted, we want to be notified
  event Voted(string vote_choice);

  //declares the variables
  string[] votes;
  uint numVotes = 0;
  Poll public p;

  //initiator function that stores the necessary poll information
  function NewPoll(string _options, string _title, uint _votelimit, uint _deadline) {
    p.owner = msg.sender;
    p.options = _options;
    p.title = _title;
    p.votelimit = _votelimit;
    p.deadline = _deadline;
    p.status = true;
  }

  //function for user vote. input is a hex choice
  function vote(string choice) returns (bool) {
    if (msg.sender != p.owner || p.status != true) {
      return false;
    }
    votes[numVotes] = choice;
    numVotes++;
    Voted(choice);
    if (p.votelimit > 0) {
        if (numVotes >= p.votelimit) {
          endPoll();
        }
    }
    return true;
  }

  //when time or vote limit is reached, set the poll status to false
  function endPoll() returns (bool) {
    if (msg.sender != p.owner) {
      return false;
    }
    p.status = false;
    return true;
  }
}


Factor out common _transfer code.

Factor out common _transfer code.

// Implements standard token interface
// From: https://github.com/slockit/DAO/blob/f640568e694a057aaeb64a0f1049fae27efe818b/Token.sol
// See also https://github.com/ethereum/wiki/wiki/Standardized_Contract_APIs

contract TokenInterface {
    mapping (address => uint256) balances;
    mapping (address => mapping (address => uint256)) allowed;

    /// Total amount of tokens
    uint256 public totalSupply;

    /// @param _owner The address from which the balance will be retrieved
    /// @return The balance
    function balanceOf(address _owner) constant returns (uint256 balance);

    /// @notice Send `_amount` tokens to `_to` from `msg.sender`
    /// @param _to The address of the recipient
    /// @param _amount The amount of tokens to be transferred
    /// @return Whether the transfer was successful or not
    function transfer(address _to, uint256 _amount) returns (bool success);

    /// @notice Send `_amount` tokens to `_to` from `_from` on the condition it
    /// is approved by `_from`
    /// @param _from The address of the origin of the transfer
    /// @param _to The address of the recipient
    /// @param _amount The amount of tokens to be transferred
    /// @return Whether the transfer was successful or not
    function transferFrom(address _from, address _to, uint256 _amount) returns (bool success);

    /// @notice `msg.sender` approves `_spender` to spend `_amount` tokens on
    /// its behalf
    /// @param _spender The address of the account able to transfer the tokens
    /// @param _amount The amount of tokens to be approved for transfer
    /// @return Whether the approval was successful or not
    function approve(address _spender, uint256 _amount) returns (bool success);

    /// @param _owner The address of the account owning tokens
    /// @param _spender The address of the account able to transfer the tokens
    /// @return Amount of remaining tokens of _owner that _spender is allowed
    /// to spend
    function allowance(
        address _owner,
        address _spender
    ) constant returns (uint256 remaining);

    event Transfer(address indexed _from, address indexed _to, uint256 _amount);
    event Approval(
        address indexed _owner,
        address indexed _spender,
        uint256 _amount
    );
}

contract DynamicToken is TokenInterface {
  address public owner;

  address[] public accounts;

  // Protects users by preventing the execution of method calls that
  // inadvertently also transferred ether
  modifier noEther() {if (msg.value > 0) throw; _}

  event TransferFrom(address indexed _from, address indexed _to,  address indexed _spender, uint256 _amount);

  function DynamicToken() {
    owner = msg.sender;     // contract owner is contract creator
    totalSupply = 10**7;
    accounts.push(msg.sender);
  }

  modifier onlyOwner {
    if (msg.sender == owner) {
      _
    }
  }

  function setTotalSupply(uint256 _totalSupply) onlyOwner noEther {
    totalSupply = _totalSupply;
  }

  function getAccounts() noEther returns (address[] _accounts) {
    return accounts;
  }

  function issue(address _to, uint256 _value) onlyOwner noEther {
    if (balances[_to] + _value < balances[_to]) throw; // Check for overflows
    if (_value <= totalSupply) {
      balances[_to] = _value;
      indexAccount(_to);
    }
  }

  function setOwner(address _newOwner) onlyOwner noEther {
    owner = _newOwner;
  }

  function transfer(address _to, uint256 _amount) noEther returns (bool success) {
    return _transfer(msg.sender, _to, _amount);
  }

  function balanceOf(address _owner) noEther constant returns(uint256 balance) {
    return balances[_owner];
  }

  function approve(address _spender, uint256 _amount) noEther returns (bool success) {
    allowed[msg.sender][_spender] = _amount;
    Approval(msg.sender, _spender, _amount);
    return true;
  }

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

  function transferFrom(address _from, address _to, uint256 _amount) noEther returns (bool success) {
    if (allowed[_from][msg.sender] >= _amount &&
      _transfer(_from, _to, _amount)) {
      allowed[_from][msg.sender] -= _amount;
      TransferFrom(_from, _to, msg.sender, _amount);
      return true;
    } else {
      return false;
    }
  }

  function _transfer(address _from, address _to, uint256 _amount) private returns (bool success) {
    if (balances[_to] + _amount < balances[_to]) throw;  // Check for overflows

    if (balances[_from] >= _amount) {
      balances[_to] += _amount;
      balances[_from] -= _amount;
      indexAccount(_to);
      Transfer(_from, _to, _amount);
      return true;
    } else {
      return false;
    }
  }

  function indexAccount(address _account) private {
    for (uint32 i = 0;  i < accounts.length; i++) {
      if (accounts[i] == _account) return ;
    }
    accounts.push(_account);
  }

  function close() {
    if(msg.sender != owner) throw;
    selfdestruct(owner);
  }

  // throw on malformed calls
  function () {
    throw;
  }
}

// Implements standard token interface
// From: https://github.com/slockit/DAO/blob/f640568e694a057aaeb64a0f1049fae27efe818b/Token.sol
// See also https://github.com/ethereum/wiki/wiki/Standardized_Contract_APIs

contract TokenInterface {
    mapping (address => uint256) balances;
    mapping (address => mapping (address => uint256)) allowed;

    /// Total amount of tokens
    uint256 public totalSupply;

    /// @param _owner The address from which the balance will be retrieved
    /// @return The balance
    function balanceOf(address _owner) constant returns (uint256 balance);

    /// @notice Send `_amount` tokens to `_to` from `msg.sender`
    /// @param _to The address of the recipient
    /// @param _amount The amount of tokens to be transferred
    /// @return Whether the transfer was successful or not
    function transfer(address _to, uint256 _amount) returns (bool success);

    /// @notice Send `_amount` tokens to `_to` from `_from` on the condition it
    /// is approved by `_from`
    /// @param _from The address of the origin of the transfer
    /// @param _to The address of the recipient
    /// @param _amount The amount of tokens to be transferred
    /// @return Whether the transfer was successful or not
    function transferFrom(address _from, address _to, uint256 _amount) returns (bool success);

    /// @notice `msg.sender` approves `_spender` to spend `_amount` tokens on
    /// its behalf
    /// @param _spender The address of the account able to transfer the tokens
    /// @param _amount The amount of tokens to be approved for transfer
    /// @return Whether the approval was successful or not
    function approve(address _spender, uint256 _amount) returns (bool success);

    /// @param _owner The address of the account owning tokens
    /// @param _spender The address of the account able to transfer the tokens
    /// @return Amount of remaining tokens of _owner that _spender is allowed
    /// to spend
    function allowance(
        address _owner,
        address _spender
    ) constant returns (uint256 remaining);

    event Transfer(address indexed _from, address indexed _to, uint256 _amount);
    event Approval(
        address indexed _owner,
        address indexed _spender,
        uint256 _amount
    );
}

contract DynamicToken is TokenInterface {
  address public owner;

  address[] public accounts;

  // Protects users by preventing the execution of method calls that
  // inadvertently also transferred ether
  modifier noEther() {if (msg.value > 0) throw; _}

  event TransferFrom(address indexed _from, address indexed _to,  address indexed _spender, uint256 _amount);

  function DynamicToken() {
    owner = msg.sender;     // contract owner is contract creator
    totalSupply = 10**7;
    accounts.push(msg.sender);
  }

  modifier onlyOwner {
    if (msg.sender == owner) {
      _
    }
  }

  function setTotalSupply(uint256 _totalSupply) onlyOwner noEther {
    totalSupply = _totalSupply;
  }

  function getAccounts() noEther returns (address[] _accounts) {
    return accounts;
  }

  function issue(address _to, uint256 _value) onlyOwner noEther {
    if (balances[_to] + _value < balances[_to]) throw; // Check for overflows
    if (_value <= totalSupply) {
      balances[_to] = _value;
      indexAccount(_to);
    }
  }

  function setOwner(address _newOwner) onlyOwner noEther {
    owner = _newOwner;
  }

  function transfer(address _to, uint256 _amount) noEther returns (bool success) {
    // if (amount <= 0) return false; // TODO can we test this?
    if (balances[msg.sender] >= _amount) {
      if (balances[_to] + _amount < balances[_to]) throw;  // Check for overflows

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

  function balanceOf(address _owner) noEther constant returns(uint256 balance) {
    return balances[_owner];
  }

  function approve(address _spender, uint256 _amount) noEther returns (bool success) {
    allowed[msg.sender][_spender] = _amount;
    Approval(msg.sender, _spender, _amount);
    return true;
  }

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

  function transferFrom(address _from, address _to, uint256 _amount) noEther returns (bool success) {
    if (balances[_from] >= _amount
      && allowed[_from][msg.sender] >= _amount
      ) {
        indexAccount(_to);

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

  function indexAccount(address _account) private {
    for (uint32 i = 0;  i < accounts.length; i++) {
      if (accounts[i] == _account) return ;
    }
    accounts.push(_account);
  }

  function close() {
    if(msg.sender != owner) throw;
    selfdestruct(owner);
  }

  // throw on malformed calls
  function () {
    throw;
  }
}


vesting was added

vesting was added

pragma solidity 0.4.18;

/**
 * @title SafeMath
 * @dev Math operations with safety checks that throw on error
 */
library SafeMath {
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a * b;
        assert(a == 0 || c / a == b);
        return c;
    }

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

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

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

/**
 * @title Ownable
 * @dev The Ownable contract has an owner address, and provides basic authorization control
 * functions, this simplifies the implementation of "user permissions".
 */
contract Ownable {
    address public owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev The Ownable constructor sets the original `owner` of the contract to the sender
     * account.
     */
    function Ownable() public {
        owner = msg.sender;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(msg.sender == owner);
        _;
    }

    /**
     * @dev Allows the current owner to transfer control of the contract to a newOwner.
     * @param newOwner The address to transfer ownership to.
     */
    function transferOwnership(address newOwner) onlyOwner public {
        require(newOwner != address(0));
        OwnershipTransferred(owner, newOwner);
        owner = newOwner;
    }
}

/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/179
*/
contract ERC20Basic {
    uint256 public totalSupply;
    function balanceOf(address who) public constant returns (uint256);
    function transfer(address to, uint256 value) public returns (bool);
    event Transfer(address indexed from, address indexed to, uint256 value);
}

/**
 * @title ERC20 interface
 * @dev see https://github.com/ethereum/EIPs/issues/20
 */
contract ERC20 is ERC20Basic {
    function allowance(address owner, address spender) public constant returns (uint256);
    function transferFrom(address from, address to, uint256 value) public returns (bool);
    function approve(address spender, uint256 value) public returns (bool);
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

/**
 * @title Standard ERC20 token
 *
 * @dev Implementation of the basic standard token.
 * @dev https://github.com/ethereum/EIPs/issues/20
 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
 */
contract ApprovalContract is ERC20 {
    using SafeMath for uint256;

    mapping (address => mapping (address => uint256)) allowed;

    /**
     * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
     *
     * Beware that changing an allowance with this method brings the risk that someone may use both the old
     * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
     * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     * @param _spender The address which will spend the funds.
     * @param _value The amount of tokens to be spent.
     */
    function approve(address _spender, uint256 _value) public returns (bool) {
        allowed[msg.sender][_spender] = _value;
        Approval(msg.sender, _spender, _value);
        return true;
    }

    /**
     * @dev Function to check the amount of tokens that an owner allowed to a spender.
     * @param _owner address The address which owns the funds.
     * @param _spender address The address which will spend the funds.
     * @return A uint256 specifying the amount of tokens still available for the spender.
     */
    function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
        return allowed[_owner][_spender];
    }

    /**
     * approve should be called when allowed[_spender] == 0. To increment
     * allowed value is better to use this function to avoid 2 calls (and wait until
     * the first transaction is mined)
     * From MonolithDAO Token.sol
     */
    function increaseApproval (address _spender, uint _addedValue) public
    returns (bool success) {
        allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
        Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
        return true;
    }

    function decreaseApproval (address _spender, uint _subtractedValue) public
    returns (bool success) {
        uint oldValue = allowed[msg.sender][_spender];
        if (_subtractedValue > oldValue) {
            allowed[msg.sender][_spender] = 0;
        } else {
            allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
        }
        Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
        return true;
    }
}

contract MintableToken is ApprovalContract, Ownable {

    uint256 public hardCap;
    mapping(address => uint256) balances;

    event Mint(address indexed to, uint256 amount);

    modifier canMint() {
        require(totalSupply == 0);
        _;
    }

    /**
     * @dev Function to mint tokens
     * @param _to The address that will receive the minted tokens.
     * @param _amount The amount of tokens to mint.
     * @return A boolean that indicates if the operation was successful.
     */
    function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) {
        require(_amount < hardCap);
        totalSupply = totalSupply.add(_amount);
        balances[_to] = balances[_to].add(_amount);
        Mint(_to, _amount);
        Transfer(0x0, _to, _amount);
        return true;
    }
}

contract Vesting is MintableToken {

    event VestingMemberAdded(address _address, uint256 _amount, uint _start, uint _end);

    struct _Vesting {
    uint256 totalSum;
    uint256 start;
    uint256 end;
    uint256 usedAmount;
    }

    mapping (address => _Vesting ) public vestingMembers;

    function addVestingMember(
    address _address,
    uint256 _amount,
    uint256 _start,
    uint256 _end
    ) onlyOwner public returns (bool) {
        require(
        _address != address(0) &&
        _amount > 0 &&
        _start < _end &&
        vestingMembers[_address].totalSum == 0 &&
        balances[msg.sender] > _amount
        );

        balances[msg.sender] = balances[msg.sender].sub(_amount);

        vestingMembers[_address].totalSum = _amount;    //total amount
        vestingMembers[_address].start = _start;        //start block
        vestingMembers[_address].end = _end;            //end block
        vestingMembers[_address].usedAmount = 0;        //the amount of paid payments

        VestingMemberAdded(_address, _amount, _start, _end);

        return true;
    }

    function currentPart(address _address) private constant returns (uint256) {
        if (vestingMembers[_address].totalSum == 0) {
            return 0;
        }
        if (block.number >= vestingMembers[_address].end) {
            return vestingMembers[_address].totalSum.sub(vestingMembers[_address].usedAmount);
        }

        return vestingMembers[_address].totalSum
        .mul(block.number - vestingMembers[_address].start)
        .div(vestingMembers[_address].end - vestingMembers[_address].start)
        .sub(vestingMembers[_address].usedAmount);
    }

    function subFromBalance(address _address, uint256 _amount) private returns (uint256) {
        require(_address != address(0));

        if (vestingMembers[_address].totalSum == 0) {
            balances[_address] = balances[_address].sub(_amount);
            return balances[_address];
        }
        uint256 summary = balanceOf(_address);
        require(summary >= _amount);

        if (balances[_address] > _amount) {
            balances[_address] = balances[_address].sub(_amount);
        } else {
            uint256 part = currentPart(_address);
            if (block.number >= vestingMembers[_address].end) {
                vestingMembers[_address].totalSum = 0;          //total amount
                vestingMembers[_address].start = 0;             //start block
                vestingMembers[_address].end = 0;               //end block
                vestingMembers[_address].usedAmount = 0;        //the amount of paid payments
            } else {
                vestingMembers[_address].usedAmount = vestingMembers[_address].usedAmount.add(part);
            }
            balances[_address] = balances[_address].add(part).sub(_amount);
        }

        return balances[_address];
    }

    function balanceOf(address _owner) public constant returns (uint256 balance) {
        if (vestingMembers[_owner].totalSum == 0) {
            return balances[_owner];
        } else {
            return balances[_owner].add(currentPart(_owner));
        }
    }

    function transfer(address _to, uint256 _value) public returns (bool) {
        require(_to != address(0));
        require(_value <= balanceOf(msg.sender));

        subFromBalance(msg.sender, _value);

        balances[_to] = balances[_to].add(_value);
        Transfer(msg.sender, _to, _value);
        return true;
    }

    function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
        require(_to != address(0));

        uint256 _allowance = allowed[_from][msg.sender];

        subFromBalance(_from, _value);

        balances[_to] = balances[_to].add(_value);
        allowed[_from][msg.sender] = _allowance.sub(_value);
        Transfer(_from, _to, _value);
        return true;
    }
}

contract DMToken is Vesting {

    string public name = "DMarket Token";
    string public symbol = "MARK";
    uint256 public decimals = 8;

    function DMToken() public {
        hardCap = 15644283100000000;
    }

    function multiTransfer(address[] recipients, uint256[] amounts) public onlyOwner {
        require(recipients.length == amounts.length);
        uint256 sum = 0;
        for (uint i = 0; i < amounts.length; i++) {
            require(recipients[i] != address(0));
            sum += amounts[i];
        }
        require(sum <= balances[msg.sender]);
        for (i = 0; i < recipients.length; i++) {
            transfer(recipients[i], amounts[i]);
        }
    }

    function multiVesting(
    address[] _address,
    uint256[] _amount,
    uint256[] _start,
    uint256[] _end
    ) public onlyOwner {
        require(
        _address.length == _amount.length &&
        _address.length == _start.length &&
        _address.length == _end.length
        );

        uint256 sum = 0;
        for (uint i = 0; i < _amount.length; i++) {
            require(_address[i] != address(0));
            sum += _amount[i];
        }
        require(sum <= balances[msg.sender]);

        for (i = 0; i < _address.length; i++) {
            addVestingMember(_address[i], _amount[i], _start[i], _end[i]);
        }
    }
}

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


after testing 2 parties with 1 oversubscription

contract mixer {

    struct anon_registeration{
        address sender;
        uint value;
        bool valid;
    }

    struct public_user{
        uint deposit;
        address addr;
        bool valid;
        uint revealed_deposit;
	uint[] registration_values; // used only if there is violation
    }

    struct mixing_deal{
        uint start_time;
        public_user[] users; // must hold array to iterate them
        mapping (address=>uint) user_to_index_mapping;
        anon_registeration[] registrations;
        mapping (address=>uint) registration_to_index_mapping;

        uint32 min_num_participants;
        uint   registration_deposit_size_in_wei;
        uint   phase_time_in_secs;

        uint   deposit_sum;
        uint   registration_sum;
        bool   violated;
    }

    mixing_deal[] deals;

    enum deal_state{
        invalid,

        initial_deposit,
        anonymous_registration,
        anonymous_withdraw,

        anonymous_revealing,
        public_withdraw_not_enough_parties,
        public_withdraw_violation
    }

    modifier non_payable {
        if (msg.value > 0 )
            throw;
        _
    }
    function mixer(){
        deals.length = 0;
    }

    function number_of_deals( ) constant returns(uint){
	return deals.length;
    }

    function not_after_phase(mixing_deal deal, uint phase) constant private returns(bool){
        return deal.start_time + deal.phase_time_in_secs * phase >= now;
    }

    function get_deal_state(uint deal_id) constant returns(deal_state){
        if( deals.length <= deal_id ) return deal_state.invalid;
        mixing_deal deal = deals[ deal_id ];
        if( not_after_phase(deal, 1) ) return deal_state.initial_deposit;

        if( deal.users.length < deal.min_num_participants ) return deal_state.public_withdraw_not_enough_parties;

        if( not_after_phase(deal, 2) ) return deal_state.anonymous_registration;

        if( deal.violated ){
            if( not_after_phase(deal, 3) ) return deal_state.anonymous_revealing;
            // else - phase 4
            return deal_state.public_withdraw_violation;
        }
        else{
            return deal_state.anonymous_withdraw;
        }
    }

    function create_new_deal(uint32 _min_num_participants,
                             uint   _registration_deposit_size_in_wei,
                             uint32 _phase_time_in_minutes ) non_payable returns (uint) {
        uint deal_id = deals.length;
        deals.length += 1;

        deals[ deal_id ].start_time = now;
        deals[ deal_id ].min_num_participants = _min_num_participants;
        deals[ deal_id ].registration_deposit_size_in_wei = _registration_deposit_size_in_wei;
        deals[ deal_id ].phase_time_in_secs = _phase_time_in_minutes * 1 minutes;

	deals[ deal_id ].users.length = 0;
        deals[ deal_id ].deposit_sum = 0;
        deals[ deal_id ].registration_sum = 0;
        deals[ deal_id ].violated = false;

        return deal_id;
    }

    function make_initial_deposit( uint deal_id ){
        if( get_deal_state( deal_id ) != deal_state.initial_deposit ) throw;

        mixing_deal deal = deals[ deal_id ];
        uint user_index = deal.users.length;
        deal.users.length += 1;

        deal.users[ user_index ].deposit = msg.value;
        deal.users[ user_index ].addr = msg.sender;
        deal.users[ user_index ].revealed_deposit = 0;
        deal.users[ user_index ].valid = true;
	deal.users[ user_index ].registration_values.length = 0;

        deal.user_to_index_mapping[ msg.sender ] = user_index;

        deal.deposit_sum += msg.value;
    }

    function make_anonymous_registration( uint deal_id, uint amount_in_wei ){
        if( get_deal_state( deal_id ) != deal_state.anonymous_registration ) throw;
        if( amount_in_wei > 1024 * 1024 * 1024 ether ) throw; // prevent overflows

        mixing_deal deal = deals[ deal_id ];

        if( msg.value != deal.registration_deposit_size_in_wei ) throw;

        uint reg_id = deal.registrations.length;
        deal.registrations.length += 1;

        deal.registrations[ reg_id ].sender = msg.sender;
        deal.registrations[ reg_id ].value = amount_in_wei;
        deal.registrations[ reg_id ].valid = true;

        deal.registration_to_index_mapping[ msg.sender ] = reg_id;

        deal.registration_sum += amount_in_wei;

        if( deal.registration_sum > deal.deposit_sum ) deal.violated = true;
    }

    function make_anonymous_withdraw(uint deal_id) non_payable{
        if( get_deal_state( deal_id ) != deal_state.anonymous_withdraw ) throw;
        uint reg_index = deals[ deal_id ].registration_to_index_mapping[ msg.sender ];
        anon_registeration reg = deals[ deal_id ].registrations[ reg_index ];
        if( ! reg.valid ) throw;

        // invalidate for next time
        reg.valid = false;

        uint value = reg.value + deals[ deal_id ].registration_deposit_size_in_wei;

        if( ! reg.sender.send( value ) ) throw;
    }

    function reveal_registration( uint deal_id, address public_address ) non_payable{
        if( get_deal_state( deal_id ) != deal_state.anonymous_revealing ) throw;

        mixing_deal deal = deals[ deal_id ];

        // get registration
        uint reg_index = deal.registration_to_index_mapping[ msg.sender ];
        anon_registeration reg = deal.registrations[ reg_index ];
        if( ! reg.valid ) throw;
	reg.valid = false;

        // get user
        uint user_index = deal.user_to_index_mapping[ public_address ];
        public_user user = deal.users[ user_index ];
        if( ! user.valid ) throw;

        // assume no overflows
        if( user.deposit >= user.revealed_deposit + reg.value ){
	    uint rev_id = user.registration_values.length;
            user.registration_values.length += 1;
            user.registration_values[ rev_id ] = reg.value;
            user.revealed_deposit += reg.value;
            return;
        }

        // else - replace with higher value deposit
        uint max_index = 0;
        uint max_value = user.registration_values[ 0 ];
        for ( uint index = 1; index < user.registration_values.length; index += 1 ){
            if( user.registration_values[ index ] > max_value ){
                max_index = index;
                max_value = user.registration_values[ index ];
            }
        }
        if( max_value < reg.value ) return; // ignore this registration
        // else - replace max with new reg
        user.registration_values[ max_index ] = reg.value;
        user.revealed_deposit = user.revealed_deposit + reg.value - max_value;
    }

    function public_withdraw( uint deal_id ) non_payable{
        if( ( get_deal_state( deal_id ) != deal_state.public_withdraw_not_enough_parties ) &&
            ( get_deal_state( deal_id ) != deal_state.public_withdraw_violation ) ) throw;

        mixing_deal deal = deals[ deal_id ];
        uint user_index = deal.user_to_index_mapping[ msg.sender ];
        public_user user = deal.users[ user_index ];
        if( ! user.valid ) throw;
        user.valid = false;

        uint value = user.deposit;

        if( get_deal_state( deal_id ) == deal_state.public_withdraw_violation ){
            value += user.registration_values.length * deal.registration_deposit_size_in_wei;
        }

        if( ! user.addr.send( value ) ) throw;
    }

}

contract mixer {

    struct anon_registeration{
        address sender;
        uint value;
        bool valid;
    }

    struct public_user{
        uint deposit;
        address addr;
        bool valid;
        uint revealed_deposit;
        anon_registeration[] registrations; // used only if there is violation
    }

    struct mixing_deal{
        uint start_time;
        public_user[] users; // must hold array to iterate them
        mapping (address=>uint) user_to_index_mapping;
        anon_registeration[] registrations;
        mapping (address=>uint) registration_to_index_mapping;

        uint32 min_num_participants;
        uint   registration_deposit_size_in_wei;
        uint   phase_time_in_secs;

        uint   deposit_sum;
        uint   registration_sum;
        bool   violated;
    }

    mixing_deal[] deals;

    enum deal_state{
        invalid,

        initial_deposit,
        anonymous_registration,
        anonymous_withdraw,

        anonymous_revealing,
        public_withdraw_not_enough_parties,
        public_withdraw_violation
    }

    modifier non_payable {
        if (msg.value > 0 )
            throw;
        _
    }
    function mixer(){
        deals.length = 0;
    }

    function not_after_phase(mixing_deal deal, uint phase) constant private returns(bool){
        return deal.start_time + deal.phase_time_in_secs * phase >= now;
    }

    function get_deal_state(uint deal_id) constant returns(deal_state){
        if( deals.length <= deal_id ) return deal_state.invalid;
        mixing_deal deal = deals[ deal_id ];
        if( not_after_phase(deal, 1) ) return deal_state.initial_deposit;

        if( deal.users.length < deal.min_num_participants ) return deal_state.public_withdraw_not_enough_parties;

        if( not_after_phase(deal, 2) ) return deal_state.anonymous_registration;

        if( deal.violated ){
            if( not_after_phase(deal, 3) ) return deal_state.anonymous_revealing;
            // else - phase 4
            return deal_state.public_withdraw_violation;
        }
        else{
            return deal_state.anonymous_withdraw;
        }
    }

    function create_new_deal(uint32 _min_num_participants,
                             uint   _registration_deposit_size_in_wei,
                             uint32 _phase_time_in_minutes ) non_payable returns (uint) {
        uint deal_id = deals.length;
        deals.length += 1;

        deals[ deal_id ].start_time = now;
        deals[ deal_id ].min_num_participants = _min_num_participants;
        deals[ deal_id ].registration_deposit_size_in_wei = _registration_deposit_size_in_wei;
        deals[ deal_id ].phase_time_in_secs = _phase_time_in_minutes * 1 minutes;

        deals[ deal_id ].deposit_sum = 0;
        deals[ deal_id ].registration_sum = 0;
        deals[ deal_id ].violated = false;

        return deal_id;
    }

    function make_initial_deposit( uint deal_id ){
        if( get_deal_state( deal_id ) != deal_state.initial_deposit ) throw;

        mixing_deal deal = deals[ deal_id ];
        uint user_index = deal.users.length;
        deal.users.length += 1;

        deal.users[ user_index ].deposit = msg.value;
        deal.users[ user_index ].addr = msg.sender;
        deal.users[ user_index ].revealed_deposit = 0;
        deal.users[ user_index ].valid = true;

        deal.user_to_index_mapping[ msg.sender ] = user_index;

        deal.deposit_sum += msg.value;
    }

    function make_anonymous_registration( uint deal_id, uint amount_in_wei ){
        if( get_deal_state( deal_id ) != deal_state.anonymous_registration ) throw;
        if( amount_in_wei > 1024 * 1024 * 1024 ether ) throw; // prevent possible overflows

        mixing_deal deal = deals[ deal_id ];

        if( msg.value != deal.registration_deposit_size_in_wei ) throw;

        uint reg_id = deal.registrations.length;
        deal.registrations.length += 1;

        deal.registrations[ reg_id ].sender = msg.sender;
        deal.registrations[ reg_id ].value = amount_in_wei;
        deal.registrations[ reg_id ].valid = true;

        deal.registration_to_index_mapping[ msg.sender ] = reg_id;

        deals[ deal_id ].registration_sum += amount_in_wei;

        if( deals[ deal_id ].registration_sum > deal.deposit_sum ) deals[ deal_id ].violated = true;
    }

    function make_anonymous_withdraw(uint deal_id) non_payable{
        if( get_deal_state( deal_id ) != deal_state.anonymous_withdraw ) throw;
        uint reg_index = deals[ deal_id ].registration_to_index_mapping[ msg.sender ];
        anon_registeration reg = deals[ deal_id ].registrations[ reg_index ];
        if( ! reg.valid ) throw;

        // invalidate for next time
        reg.valid = false;

        uint value = reg.value + deals[ deal_id ].registration_deposit_size_in_wei;

        if( ! reg.sender.send( value ) ) throw;
    }

    function reveal_registration( uint deal_id, address public_address ) non_payable{
        if( get_deal_state( deal_id ) != deal_state.anonymous_revealing ) throw;

        mixing_deal deal = deals[ deal_id ];

        // get registration
        uint reg_index = deal.registration_to_index_mapping[ msg.sender ];
        anon_registeration reg = deal.registrations[ reg_index ];
        if( ! reg.valid ) throw;

        // get user
        uint user_index = deal.user_to_index_mapping[ public_address ];
        public_user user = deal.users[ user_index ];
        if( ! user.valid ) throw;

        // assume no overflows
        if( user.deposit >= user.revealed_deposit + reg.value ){
            user.registrations.length += 1;
            user.registrations[ user.registrations.length - 1 ] = reg;
            user.revealed_deposit += reg.value;
            return;
        }

        // else - replace with maximal value deposit
        uint max_index = 0;
        uint max_value = user.registrations[ 0 ].value;
        for ( uint index = 1; index < user.registrations.length; index += 1 ){
            if( user.registrations[ index ].value > max_value ){
                max_index = index;
                max_value = user.registrations[ index ].value;
            }
        }
        if( max_value > reg.value ) return; // ignore this registration
        // else - replace max with new reg
        user.registrations[ max_index ] = reg;
        user.revealed_deposit = user.revealed_deposit + reg.value - max_value;
    }

    function public_withdraw( uint deal_id ) non_payable{
        if( ( get_deal_state( deal_id ) != deal_state.public_withdraw_not_enough_parties ) &&
            ( get_deal_state( deal_id ) != deal_state.public_withdraw_violation ) ) throw;

        mixing_deal deal = deals[ deal_id ];
        uint user_index = deal.user_to_index_mapping[ msg.sender ];
        public_user user = deal.users[ user_index ];
        if( ! user.valid ) throw;

        uint value = user.deposit;

        if( get_deal_state( deal_id ) == deal_state.public_withdraw_violation ){
            value += user.registrations.length * deal.registration_deposit_size_in_wei;
        }

        user.valid = false;

        if( ! user.addr.send( value ) ) throw;
    }

}


Allow additional funding

Allow additional funding

contract DaoChallenge
{
	modifier noEther() {if (msg.value > 0) throw; _}

	modifier onlyOwner() {if (owner != msg.sender) throw; _}

	event notifySellToken(uint256 n, address buyer);
	event notifyRefundToken(uint256 n, address tokenHolder);
	event notifyTerminate(uint256 finalBalance);

	/* This creates an array with all balances */
  mapping (address => uint256) public tokenBalanceOf;

	uint256 constant tokenPrice = 1000000000000000; // 1 finney

	// Owner of the challenge; a real DAO doesn't an owner.
	address owner;

	function sendOrThrow(address destination, uint256 amount) {
		bool result = destination.send(amount);
		if (!result) {
			throw;
		}
	}

	function DaoChallenge () {
		owner = msg.sender; // Owner of the challenge. Don't use this in a real DAO.
	}

	function () {
		address sender = msg.sender;
		uint256 amount = msg.value;

		// No fractional tokens:
		if (amount % tokenPrice != 0) {
			throw;
		}
		tokenBalanceOf[sender] += amount / tokenPrice;
		notifySellToken(amount, sender);
	}

	function refund() noEther {
		address sender = msg.sender;
		uint256 tokenBalance = tokenBalanceOf[sender];
		if (tokenBalance == 0) { throw; }
		tokenBalanceOf[sender] = 0;
		sendOrThrow(sender, tokenBalance * tokenPrice);
		notifyRefundToken(tokenBalance, sender);
	}

	// The owner of the challenge can terminate it. Don't use this in a real DAO.
	function terminate() noEther onlyOwner {
		notifyTerminate(this.balance);
		suicide(owner);
	}
}

contract DaoChallenge
{
	modifier noEther() {if (msg.value > 0) throw; _}

	modifier onlyOwner() {if (owner != msg.sender) throw; _}

	event notifySellToken(uint256 n, address buyer);
	event notifyRefundToken(uint256 n, address tokenHolder);
	event notifyTerminate(uint256 finalBalance);

	/* This creates an array with all balances */
  mapping (address => uint256) public tokenBalanceOf;

	uint256 constant tokenPrice = 1000000000000000; // 1 finney

	// Owner of the challenge; a real DAO doesn't an owner.
	address owner;

	function sendOrThrow(address destination, uint256 amount) {
		bool result = destination.send(amount);
		if (!result) {
			throw;
		}
	}

	function DaoChallenge () {
		owner = msg.sender; // Owner of the challenge. Don't use this in a real DAO.
	}

	function () {
		address sender = msg.sender;
		if(tokenBalanceOf[sender] != 0) {
			throw;
		}
		// No fractional tokens:
		if (msg.value % tokenPrice != 0) {
			throw;
		}
		tokenBalanceOf[sender] = msg.value / tokenPrice;
		notifySellToken(tokenBalanceOf[sender], sender);
	}

	function refund() noEther {
		address sender = msg.sender;
		uint256 tokenBalance = tokenBalanceOf[sender];
		if (tokenBalance == 0) { throw; }
		tokenBalanceOf[sender] = 0;
		sendOrThrow(sender, tokenBalance * tokenPrice);
		notifyRefundToken(tokenBalance, sender);
	}

	// The owner of the challenge can terminate it. Don't use this in a real DAO.
	function terminate() noEther onlyOwner {
		notifyTerminate(this.balance);
		suicide(owner);
	}
}


internal funcs

internal funcs

contract OracleItI {
    address public callbackAddress;
    uint public defaultGasLimit;
    uint public defaultGasPrice;
    function query(uint timestamp, bytes32 dataSource, string arg1, string arg2, uint gasLimit, uint gasPrice) returns(uint id);
    function getPrice(bytes32 dataSource) returns(uint price);
}

contract OracleItAddrResolverI {
    function getAddress() returns (address _oracleItAddress);
}

contract usingOracleIt {
    OracleItAddrResolverI OIAR;

    OracleItI oracleIt;
    modifier oracleItAPI {
        if(address(OIAR)==0) oracleItSetNetwork();
        oracleIt = OracleItI(OIAR.getAddress());
        _
    }

    function oracleItSetNetwork() internal returns(bool){
        if (getCodeSize(0x878101bd3ee632b6d46005d98262d482a070f631)>0){
            OIAR = OracleItAddrResolverI(0x878101bd3ee632b6d46005d98262d482a070f631);
            return true;
        }
        return false;
    }

    function oracleItQuery(string dataSource, string arg1) oracleItAPI internal returns (uint id){
        return oracleItQuery(0, dataSource, arg1, "", 0, 0);
    }

    function oracleItQuery(uint timestamp, string dataSource, string arg1) oracleItAPI internal returns (uint id){
        return oracleItQuery(timestamp, dataSource, arg1, "", 0, 0);
    }

    function oracleItQuery(string dataSource, string arg1, uint gasLimit, uint gasPrice) oracleItAPI internal returns (uint id){
        return oracleItQuery(0, dataSource, arg1, "", gasLimit, gasPrice);
    }

    function oracleItQuery(uint timestamp, string dataSource, string arg1, uint gasLimit, uint gasPrice) oracleItAPI internal returns (uint id){
        return oracleItQuery(timestamp, dataSource, arg1, "", gasLimit, gasPrice);
    }

    function oracleItQuery(string dataSource, string arg1, string arg2) oracleItAPI internal returns (uint id){
        return oracleItQuery(0, dataSource, arg1, arg2, 0, 0);
    }

    function oracleItQuery(uint timestamp, string dataSource, string arg1, string arg2) oracleItAPI internal returns (uint id){
        return oracleItQuery(timestamp, dataSource, arg1, arg2, 0, 0);
    }

    function oracleItQuery(string dataSource, string arg1, string arg2, uint gasLimit, uint gasPrice) oracleItAPI internal returns (uint id){
        return oracleItQuery(0, dataSource, arg1, arg2, gasLimit, gasPrice);
    }

    function oracleItQuery(uint timestamp, string _dataSource, string arg1, string arg2, uint gasLimit, uint gasPrice) oracleItAPI internal returns (uint id){
        if(gasLimit == 0) gasLimit = oracleIt.defaultGasLimit();
        if(gasPrice == 0) gasPrice = oracleIt.defaultGasPrice();
        bytes32 dataSource = stringToBytes32(_dataSource);
        uint price = oracleIt.getPrice(dataSource);
        if (price > 1 ether) return 0; // unexpectedly high price
        price += gasLimit * gasPrice;
        return oracleIt.query.value(price)(timestamp, dataSource, arg1, arg2, gasLimit, gasPrice);
    }

    function oracleItCallbackAddress() oracleItAPI internal returns (address){
        return oracleIt.callbackAddress();
    }

    function getCodeSize(address _addr) constant internal returns(uint _size) {
        assembly {
            _size := extcodesize(_addr)
        }
    }

    function stringToBytes32(string memory source) internal returns (bytes32 result) {
        assembly {
            result := mload(add(source, 32))
        }
    }
}

contract OracleItAPI{
}

contract OracleItI {
    address public callbackAddress;
    uint public defaultGasLimit;
    uint public defaultGasPrice;
    function query(uint timestamp, bytes32 dataSource, string arg1, string arg2, uint gasLimit, uint gasPrice) returns(uint id);
    function getPrice(bytes32 dataSource) returns(uint price);
}

contract OracleItAddrResolverI {
    function getAddress() returns (address _oracleItAddress);
}

contract usingOracleIt {
    OracleItAddrResolverI OIAR;

    OracleItI oracleIt;
    modifier oracleItAPI {
        if(address(OIAR)==0) oracleItSetNetwork();
        oracleIt = OracleItI(OIAR.getAddress());
        _
    }

    function oracleItSetNetwork() internal returns(bool){
        if (getCodeSize(0x878101bd3ee632b6d46005d98262d482a070f631)>0){
            OIAR = OracleItAddrResolverI(0x878101bd3ee632b6d46005d98262d482a070f631);
            return true;
        }
        return false;
    }

    function oracleItQuery(string dataSource, string arg1) oracleItAPI internal returns (uint id){
        return oracleItQuery(0, dataSource, arg1, "", 0, 0);
    }

    function oracleItQuery(uint timestamp, string dataSource, string arg1) oracleItAPI internal returns (uint id){
        return oracleItQuery(timestamp, dataSource, arg1, "", 0, 0);
    }

    function oracleItQuery(string dataSource, string arg1, uint gasLimit, uint gasPrice) oracleItAPI internal returns (uint id){
        return oracleItQuery(0, dataSource, arg1, "", gasLimit, gasPrice);
    }

    function oracleItQuery(uint timestamp, string dataSource, string arg1, uint gasLimit, uint gasPrice) oracleItAPI internal returns (uint id){
        return oracleItQuery(timestamp, dataSource, arg1, "", gasLimit, gasPrice);
    }

    function oracleItQuery(string dataSource, string arg1, string arg2) oracleItAPI internal returns (uint id){
        return oracleItQuery(0, dataSource, arg1, arg2, 0, 0);
    }

    function oracleItQuery(uint timestamp, string dataSource, string arg1, string arg2) oracleItAPI internal returns (uint id){
        return oracleItQuery(timestamp, dataSource, arg1, arg2, 0, 0);
    }

    function oracleItQuery(string dataSource, string arg1, string arg2, uint gasLimit, uint gasPrice) oracleItAPI internal returns (uint id){
        return oracleItQuery(0, dataSource, arg1, arg2, gasLimit, gasPrice);
    }

    function oracleItQuery(uint timestamp, string _dataSource, string arg1, string arg2, uint gasLimit, uint gasPrice) oracleItAPI internal returns (uint id){
        if(gasLimit == 0) gasLimit = oracleIt.defaultGasLimit();
        if(gasPrice == 0) gasPrice = oracleIt.defaultGasPrice();
        bytes32 dataSource = stringToBytes32(_dataSource);
        uint price = oracleIt.getPrice(dataSource);
        if (price > 1 ether) return 0; // unexpectedly high price
        price += gasLimit * gasPrice;
        return oracleIt.query.value(price)(timestamp, dataSource, arg1, arg2, gasLimit, gasPrice);
    }

    function oracleItCallbackAddress() oracleItAPI internal returns (address){
        return oracleIt.callbackAddress();
    }

    function getCodeSize(address _addr) constant internal returns(uint _size) {
        assembly {
            _size := extcodesize(_addr)
        }
    }

    function stringToBytes32(string memory source) returns (bytes32 result) {
        assembly {
            result := mload(add(source, 32))
        }
    }
}

contract OracleItAPI{
}


Added token holder contract

Added token holder contract

pragma solidity ^0.4.4;
import 'common/Object.sol';
import 'token/Recipient.sol';

contract TokenHolder is Object, Recipient {
    /**
     * @dev Recipient account address
     */
    address public recipient;

    /**
     * @dev Block number for holding before it'll not mined
     */
    uint256 public holdBeforeBlock;

    /**
     * @dev Construct TokenHolder contract
     * @param _recipient Recipient account address
     * @param _releaseBlock Block for releasing assets
     */
    function TokenHolder(address _recipient, uint256 _releaseBlock) {
        recipient       = _recipient;
        holdBeforeBlock = _releaseBlock;
    }

    /**
     * @dev Check for current block is not release block
     */
    modifier holding { if (block.number < holdBeforeBlock) throw; _; }

    /**
     * @dev Claim ERC20 token
     * @param _token Token address
     */
    function claimERC20(ERC20 _token) holding {
        if (!_token.transfer(recipient, _token.balanceOf(this)))
            throw;
    }

    /**
     * @dev Claim ether
     */
    function claimEther() holding {
        if (!recipient.send(this.balance))
            throw;
    }
}

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


Refactor delete function

Refactor delete function

pragma solidity ^0.4.4;

contract Shop {

	struct Product {
		uint price;
		string name;
		uint stockBalance;
	}

    uint ownerWithdrawals;

	mapping (uint => Product) stock;

	uint[] products;

	address administrator;

	address owner;

	event AddProductEvent(uint id, uint price, string name);

	event DeleteProductEvent(uint id);

	event BuyProductEvent(uint id);

    event LogWithdrawEvent(address main, uint quantity);

	function Shop(address administratorAddress)
		public
	{
		administrator = administratorAddress;
		owner = msg.sender;
	}

    modifier isOwner
    {
        require(msg.sender == owner);
        _;
    }

    modifier isAdministrator
    {
        require(msg.sender == administrator);
        _;
    }

	function getProductCount()
		constant
		returns (uint length)
	{
		return products.length;
	}

	function getProductIdAt(uint index)
		constant
		returns (uint id)
	{
		return products[index];
	}

	function getProduct(uint id)
		constant
		returns (string name, uint price, uint stockBalance)
	{
		Product product = stock[id];
		return (product.name,
			product.price,
			product.stockBalance);
	}

    function addProduct(uint id, uint price, string name)
   		public
   		isAdministrator
   	{
   		products.push(id);
        stock[id].price = price;
        stock[id].stockBalance += 1;
        stock[id].name = name;
        AddProductEvent(id, price, name);

    }

    function deleteProduct(uint id)
    	public
    	isAdministrator
    {

        uint index = indexOf(id);

        for (uint i = index; i<products.length-1; i++){
            products[i] = products[i+1];
        }
        delete products[products.length-1];
        products.length--;
        delete stock[id];
        DeleteProductEvent(id);
    }

    function indexOf(uint id)
    	private
    	returns(uint)
	{

        for (uint i = 0; i<products.length-1; i++){
             if(products[i] == id) return i;
        }
       	throw;
  	}

    function buyProduct(uint id)
    	payable
    	public
    {
        require(stock[id].price > 0);
        require(stock[id].price <= msg.value);
        require(stock[id].stockBalance > 0);
        stock[id].stockBalance--;
        ownerWithdrawals += stock[id].price;
        BuyProductEvent(id);
    }

    function withdraw()
    	public
    	isOwner
    {

        if (ownerWithdrawals<=0) revert();

        ownerWithdrawals = 0;
        msg.sender.transfer(ownerWithdrawals);
        LogWithdrawEvent(msg.sender, ownerWithdrawals);

    }
}

pragma solidity ^0.4.4;

contract Shop {

	struct Product {
		uint price;
		string name;
		uint stockBalance;
	}

    uint ownerWithdrawals;

	mapping (uint => Product) stock;

	uint[] products;

	address administrator;

	address owner;

	event AddProductEvent(uint id, uint price, string name);

	event DeleteProductEvent(uint id, uint price, string name);

	event BuyProductEvent(uint id);

    event LogWithdrawEvent(address main, uint quantity);

	function Shop(address administratorAddress)
		public
	{
		administrator = administratorAddress;
		owner = msg.sender;
	}

    modifier isOwner
    {
        require(msg.sender == owner);
        _;
    }

    modifier isAdministrator
    {
        require(msg.sender == administrator);
        _;
    }

	function getProductCount()
		constant
		returns (uint length)
	{
		return products.length;
	}

	function getProductIdAt(uint index)
		constant
		returns (uint id)
	{
		return products[index];
	}

	function getProduct(uint id)
		constant
		returns (string name, uint price, uint stockBalance)
	{
		Product product = stock[id];
		return (product.name,
			product.price,
			product.stockBalance);
	}

    function addProduct(uint id, uint price, string name)
   		public
   		isAdministrator
   	{
        stock[id].price = price;
        stock[id].stockBalance += 1;
        stock[id].name = name;
        products.push(id);
        AddProductEvent(id, price, name);

    }

    function deleteProduct(uint id)
    	public
    	isAdministrator
    {
        stock[id].price = 0;
        stock[id].stockBalance = 0;
        stock[id].name = "";
    }

    function buyProduct(uint id)
    	payable
    	public
    {
        require(stock[id].price > 0);
        require(stock[id].price <= msg.value);
        require(stock[id].stockBalance > 0);
        stock[id].stockBalance--;
        ownerWithdrawals += stock[id].price;
        BuyProductEvent(id);
    }

    function withdraw()
    	public
    	isOwner
    {

        if (ownerWithdrawals<=0) revert();

        ownerWithdrawals = 0;
        msg.sender.transfer(ownerWithdrawals);
        LogWithdrawEvent(msg.sender, ownerWithdrawals);

    }
}