Self-funding contract

Can a contract be self-funding, i.e. by imposing fees upon prospective users based upon its own ether cost?

For example: I would like to make a lottery contract. The contract accepts ether. At a pre-determined time interval a random sender is selected and the sum of the inputs thus far is sent to that sender--minus the cost necessary to store the addresses of the senders, process the code used to select a winner, etc.

Now I know that ECLL is turing-complete, but can it refer to such variables? I'm still researching the language so forgive me if this is obvious; then again, maybe some documentation needs to be written (and I'd love to help.)

Comments

  • yoyoyoyo Member Posts: 34 ✭✭
    edited January 2014
    The contract *has* to be self-funding otherwise it will stop to work after a while.

    It has access to its own balance so yes, what you describe is perfectly doable. When sending the gains to the winning address, it can send a fixed percentage to its total balance, a percentage of total bids or whatever.

    Also note that after a round you should clean up storage for that round's players, it should partly reimburse you of the storage fees, I think.

    There is no notion of *time* in the contract, so your pattern should be to award gains every 1000 bids or something similar.

    There is also no random number generation (could be tampered with), you could elicit the winner as the player whose address is closest to a predetermined but future block hash.

    pseudo code:

    if not minimum bid:
    exit

    store hash of address of sender in persistent storage.
    if nb of addresses stored >= players_per_round:
    get parent block hash
    compare block hash with all stored players addresses' hashes.
    winner = closest address.
    store winner's address in temporary memory
    clean up all storage
    create tx to send N% of current balance to winner
    Adjust the minimum bid so that N% of (players_per_round * minimum bid) is enough to run the whole thing.
    Optionally send yourself 5% of current balance or something.


    Post edited by yoyo on
Sign In or Register to comment.