Interaction within functions

StephanTualStephanTual London, EnglandMember, Moderator Posts: 1,282 mod
This discussion was created from comments split from: Feature Updates.

Comments

  • terzimterzim LondonMember Posts: 41
    Hi @chriseth I was wondering if the language supports time interaction within functions.
    That is, is it possible to have self activating functions that are launched every time the block.timestamp hits a predefined barrier?

    e.g. In my contract I had thought of something along the lines below:

    for (block.timestamp >= l.timelimit + l.grace_period && loan balance > 0; block.timestamp++)

    Would this ever be supported? Or the person who runs the contract will have to call the function every month? Any other idea?

    Thanks,
    Massi
  • chrisethchriseth Member Posts: 170 ✭✭✭
    As @smithgift said, someone has to call the function from outside every month.
    It might be that it even works without you bothering about setting up a job on a server to trigger the transaction each month: Just pay the person sending the transaction a small amount. If you care about precision, you can pay more the closer the trigger is to the first of a month.
  • SmithgiftSmithgift Member Posts: 64
    @chriseth: An issue with this kind of thing (and the more general idea of reactors I posted somewhere around here) is that a miner could watch for transactions that would give any sender money and replace that transaction with one of his own. It still gets triggered, yes, but then there's little incentive for non-miners.

    Thinking of it now, my advice would be, if possible, to simulate monthly calls in a continuous fashion when the function is called later. For example, if a contract is sending a monthly bill, say, it would send a bill for (months past since last bill sent * monthly amount). It would be the responsibility of the payee to call it regularly to get individual monthly payments.
Sign In or Register to comment.