The FundManager
constructor creates a new Bank
contract object...
bank = new Bank();
...and stores its address in this variable:
// This holds a reference to the current bank contract.
address bank;
When the FundManager
's deposit
function is called, it calls the Bank
contract using its address, as explained in this previous thread:
Bank(bank)...
In full, the call is:
bool success = Bank(bank).deposit.value(msg.value)(msg.sender);
Where the deposit
function in the Bank
contract is defined as:
// This will take the value of the transaction and add to the senders account.
function deposit(address customer) returns (bool res)
The customer
address parameter equates to the msg.sender
passed by the call in FundManager
.
Edit:
Bank(bank).deposit.value(msg.value): What is happening here and what
is returned?
I don't think this is a valid call by itself. It'd probably complain about a missing argument.
Bank(bank).deposit.value(msg.value)(msg.sender): What is happening here?
Bank(bank).deposit()
is an external function call: it's calling a function in a different contract.
The parameter for the deposit
function in the second contract is address customer
, so we'd expect the call in the first contract to be:
Bank(bank).deposit(msg.sender)
...where msg.sender
equates to address customer
. So far so clear.
However, for external function calls, if we want the second contract to know the original value of msg.value
from the first contract, then we must explicitly pass it. The reason being (from this page in the Solidity docs (part-way down)):
The values of all members of msg, including msg.sender and msg.value
can change for every external function call. This includes calls to
library functions.
To explicitly pass the value we need a value(msg.value)
in there as well, which by convention goes before the actual parameter of the function we're calling:
+------------------------------------+
| |
| V
Bank(bank).deposit .value(msg.value) (msg.sender)
^
|
shove it in the middle