hi, in this project, I found there is an error in the solidity/docs/examples/safe-remote.rst file, count from bottom to top the second row:
buyer.transfer(value);
should be like this:
buyer.transfer(msg.value);
because at the top of the file, you have already valued the value as msg.value/2.
/// Confirm that you (the buyer) received the item.
/// This will release the locked ether.
function confirmReceived()
public
onlyBuyer
inState(State.Locked)
{
emit ItemReceived();
// It is important to change the state first because
// otherwise, the contracts called using `send` below
// can call in again here.
state = State.Inactive;
// NOTE: This actually allows both the buyer and the seller to
// block the refund - the withdraw pattern should be used.
buyer.transfer(value);
seller.transfer(address(this).balance);
}
Is it right?
@chenzuoli Thanks for the report. I think you are right, with a minor modification: it should be value * 2 and not msg.value since confirmReceived is just a purchase confirmation and not the actual purchase (i.e., msg.value for confirmReceived should be zero).
@ChrisChinchilla I'm tagging this as docs. If you think this is incorrect, please let me know. Also, an ack of what I said/correction would be useful here :-)
@chenzuoli I noticed that you closed the issue, we usually keep the issue open until it is resolved. I'm reopening it for now.
ok, sorry I don't know that.
@chenzuoli would you like to work on a PR to fix this?
Hi, I don't know what is PR, can you tell me something about it? or you can help me fix this problem. thanks.
@chenzuoli No problem, a PR is essentially a proposal for change. I'll create a PR for this issue.
Closed by https://github.com/ethereum/solidity/pull/7613#pullrequestreview-310920680
@chenzuoli actually, the original code is correct.
Seller and buyer "stake" 2x the value of item on sale
Once the purchase is made and delivery of item confirmed, the seller obtains value, and buyer loses value
Here's a blog post I found useful in understanding the economics of escrow: https://jacksonng.org/Safe-Remote-Purchase-1
Yeah, get it, I really appreciate you.