Combining lotteries with the game of chicken.

TL/DR

  1. Send at least one ether to participate and reset the time period.
  2. Once the time period passes without a participant sending ether, the last participant receives all ether sent by all participants.
  3. The award, sending address, and time period vary with each lottery.

Monitoring

lottopollo.iffy.studio

A second opinion: see the etherchain.org monitor link on each individual lottery page.

Deployed Code

contract lottopollo {
  address leader;
  uint    timestamp;
  
  function lottopollo() {
    log(1);
  }
  
  function () {
    if (timestamp > 0 && now - timestamp > 24 hours) { // "24 hours" is the time period, and varies per lottery
      msg.sender.send(msg.value);
      
      if (this.balance > 0) {
        leader.send(this.balance);
        log(4);
      }
      else {
        log(5);
      }
    }
    else if (msg.value >= 1 ether) {
      leader = msg.sender;
      timestamp = now;
      log(2);
    }
    else {
      log(3);
    }
  }
  
  event log(uint status);
}

Simplified Code

The above code is what's actually published on the blockchain, and can be used for verification purposes.

However, the log calls complicate the logic. The same code with the logging removed is:

contract lottopollo {
  address leader;
  uint    timestamp;
    
  function () {
    if (timestamp > 0 && now - timestamp > 24 hours) { // "24 hours" is the time period, and varies per lottery
      msg.sender.send(msg.value);

      if (this.balance > 0) {
        leader.send(this.balance);
      }
    }
    else if (msg.value >= 1 ether) {
      leader = msg.sender;
      timestamp = now;
    }
  }
}

Additional Notes

Sending more than one ether is supported. The entire amount sent will be added to the balance.

Sending less than one ether will also add the entire amount sent to the balance, but will not register the sender as a participant.

After the posted time period elapses, the contract does not automatically end; instead, any person can send an arbitrary amount of ether to the contract, which will trigger two events:

  1. The sender will have the sending amount returned.
  2. The entire balance will be awarded to the last participant.

Inadvertently sending ether to the contract after it expires will simply return the ether to the sender.