【发布时间】:2017-08-22 10:55:55
【问题描述】:
我正在学习 here 之后的以太坊代币合约。我对下面的代码感到困惑:
function sell(uint amount) returns (uint revenue){
if (balanceOf[msg.sender] < amount ) throw; // checks if the sender has enough to sell
balanceOf[this] += amount; // adds the amount to owner's balance
balanceOf[msg.sender] -= amount; // subtracts the amount from seller's balance
revenue = amount * sellPrice;
if (!msg.sender.send(revenue)) { // sends ether to the seller: it's important
throw; // to do this last to prevent recursion attacks
} else {
Transfer(msg.sender, this, amount); // executes an event reflecting on the change
return revenue; // ends function and returns
}
}
行 msg.sender.send(revenue) 表示将以太币发送给卖家。我的问题是:
要发送的以太币是来自 msg.sender 还是来自令牌合约? 我认为它们来自 msg.sender。然而 msg.sender 实际上是代表卖家的,对吧?这使得卖家向自己发送以太币。我可以知道如何理解这一点。然后如何让合约自动将以太币发送回用户帐户?
谢谢!
【问题讨论】: