2
function safeWithdrawal() public afterDeadline {
    if (!fundingGoalReached) {
        uint amount = balanceOf[msg.sender];
        balanceOf[msg.sender] = 0;
        if (amount > 0) {
            if (msg.sender.send(amount)) {   //is this a condition or a command?
               emit FundTransfer(msg.sender, amount, false);
            } else {
                balanceOf[msg.sender] = amount;
            }
        }
    }

I was studying this code: https://www.ethereum.org/crowdsale and there was a part I didn't quite understand (see code above). My question is how does the contract iterate over every address that sent money to the contract and send it back... I can't see that in the code above. Also what does this condition (see code below) mean? From what I understand it looks like a command not a condition.

 msg.sender.send(amount)

Also How do you create a smart contract that receives funds, displays the addresses that sent the funds to the client? Like if in the crowdfunding dapp you would like to publicly display the addresses and how much they sent and even when they sent the funds.

1

The code does not iterate over senders. That function must be called by whoever wants to request for a withdrawal. If the crowdsale has failed, somebody has to notify the participants (or they have to find it out themselves) that they should call this function from the same address from which they participated the crowdsale. The sender is then sent his share of Eth (stored in balanceOf) back.

The line of msg.sender.send(amount) tries to send the Eth back. If that function call succeeds (the function send) it returns boolean true. That's just shorthand for:

boolean sendSucceeded = msg.sender.send(amount);
if (sendSucceeded) { ...

As for your last questions: everything in the blockchain is public so the information is already public. If you want, you can make the values somehow more visible or create a website to display the values from balanceOf variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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