It seems that calling a payable function will transfer eth directly even without explicitly calling transfer(). For example:
contract Storage {
receive() external payable {}
// Fallback function is called when msg.data is not empty
fallback() external payable {}
function getBalance() public view returns (uint) {
return address(this).balance;
}
function getMoney() public payable returns (bool) {
// payable(address(this)).transfer(msg.value);
return true;
}
}
Say I have an instance of Storage is at address x. If I call getMoney() with msg.value=1, the balance of x will increase by 1, both with and without "payable(address(this)).transfer(msg.value);". Is this expected?