1

Ok, here's the code from solidity docs:

contract Sharer {
    function sendHalf(address addr) returns (uint balance) {
        if (!addr.send(msg.value / 2))
            throw; // also reverts the transfer to Sharer
        return this.balance;
    }
}

My problem with this example is the comment:

// also reverts the transfer to Sharer

It's confusing, because throw in my understanding reverts the transfer to the msg.sender and Sharer contract isn't the msg.sender here. What am I missing here?

Wouldn't it be les confusing if the code was changed to this:

contract Sharer {
        function sendHalf(address addr) returns (uint balance) {
            if (!addr.send(msg.value / 2)) // if false reverts the transfer to Sharer
                throw;                     // reverts the transfer to msg.sender
            return this.balance;
        }
    }

1 Answer 1

1

The "reverts" here means "cancels" not "returns funds".

So the sender makes a transaction sending funds to the contract, and specifying an address to split them with. This is the "transfer to sharer" transaction (I'll call this TTST). The contract tries to send funds to the specified address. If this fails, TTST is reverted, which returns funds to the sender.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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