// deploy a new purchase contract
function newPurchase()
public
payable
returns(address newContract)
{
Purchase c = (new Purchase).value(msg.value)(address(msg.sender));
contracts.push(c);
lastContractAddress = address(c);
return c;
}
I was going through this code: https://github.com/jacksonng77/StartEscrow/blob/master/StartEscrow.sol
and I got to this part of the code (see code above) where I am having difficulty trying to understand it. (The full code is on the link above) The difficulty is particularlly on this line
Purchase c = (new Purchase).value(msg.value)(address(msg.sender));
How does this return the address of the contract? Why are we doing a
.value(msg.value)
and what is the work of
(address(msg.sender));
Also this line...
lastContractAddress = address(c)
why can I just say
lastContractAddress = c;
what is the purpose of address()?
lastContractAddress
, but its type is most likelyaddress
, soaddress(c)
is required in order to castc
to the same type.