0

How does the transfer function behave? Was looking at a function I created, and saw that we transfer ether out of the contract, before deleting the data which determines whether or not it is allowed to. A lot of the code is hidden, because it's not really relevant.

Was wondering when does the transfer happen in user.transfer()? Let's say someone calls the function twice at the exact same time, so both calls enters the if statement, the user.transfer() are called twice, so the amount is transferred twice.

Afterwards, in the delete Bikes[_serialNo]; the call which is behind, will throw an error, because the information is already deleted. In the call, where delete Bikes[_serialNo]; throws an error, will the user.transfer still be executed? Or will it revert, hence eliminating the problem completely? If it was any other code, because of the error the whole transaction would be reverted and not executed, but does user.transfer() behave like that as well?

I know that I could just move delete Bikes[_serialNo]; over user.transfer, and there wouldn't be a problem, but it is more out of curiosity.

func{
    //some code and checks whether the _serialNo, corresponds to a stolen bike etc.
    user.transfer(Bikes[_serialNo].insuredAmount);
    delete Bikes[_serialNo];
}
0

Let's say someone calls the function twice at the exact same time, so both calls enters the if statement, the user.transfer() are called twice, so the amount is transferred twice.

This can't happen, because there is no concurrency. If two transactions are submitted, one will execute (fully) before the other.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.