Look at this very basic solidity function:
function myfunction() external {
address payable address1 = 0x....;
address payable address2 = 0x....;
address1.transfer(1 ether);
address2.transfer(1 ether);
}
Let's suppose the second transfer will fail. There are many reasons for that (insuffisant funds in the contract's balance, ). I want to be sure the first transfer will be cancelled in this case.
I suppose a solidity function is "atomic". I mean if something fails in the function, every operation made in the function is canceled.
I have test and i have see the first transfer is cancelled. I am happy to see that.
But somebody told me what i was doing is a bad practice. He told me i should write a "pull-payment" pattern. My question is why should i do that.
Is there some cases where a solidity function is not "atomic" ?
Thanks a lot
*** EDIT ***
Here is what i mean by "pull payment":
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/payment/PullPayment.sol
strategy, where the paying contract doesn't interact directly with the receiver account, which must withdraw its payments itself. Pull-payments are often considered the best practice when it comes to sending Ether
Is there some cases where a solidity function is not "atomic" ?
- no.pull payment pattern
means, and post it as part of your question. It is not a term that I've come across.