Как перевести с одного эфирного кошелька на другой с помощью смартконтракта?

Я пытаюсь перевести эфиры с одной учетной записи на другую, используя свой смарт-контракт, но контракт не позволяет мне выполнять следующие функции:

function transferFrom(address _from, address _to, uint256 _value) returns (bool success)            /* A contract attempts to get the coins */ 
        {
            if (balanceOf[_from] < _value) 
            {
                throw;                                              // Check if the sender has enough
            }                 
            if (balanceOf[_to] + _value < balanceOf[_to]) 
            {
                throw;                                              // Check for overflows
            }  
            if (_value > allowance[_from][msg.sender]) 
            {
                throw;                                              // Check allowance
            }   
            balanceOf[_from] -= _value;                             // Subtract from the sender
            balanceOf[_to] += _value;                               // Add the same to the recipient
            allowance[_from][msg.sender] -= _value;
            Transfer(_from, _to, _value);
            return true;
        }
function sell(uint256 TokensAmount) afterDeadline
        {

            uint256 amount = TokensAmount;
            if (balanceOf[msg.sender] < amount ) 
            {
                throw;                                              // checks if the sender has enough to sell
            }        
            uint256 revenue = amount * sellPrice;
            balanceOf[msg.sender] -= amount;                        // subtracts the amount from seller's balance
            balanceOf[Killer] += amount;                            // adds the amount to owner's balance
            KilledTokens[msg.sender] += amount;
            KilledTillNow += amount;
            address _to = msg.sender;
            address _from = owner;
            uint256 _value = revenue;

            if (!msg.sender.send(revenue)) 
            {                                                       // sends ether to the seller: it's important
                throw;                                              // to do this last to prevent recursion attacks
            } 
            else 
            {  
                transferFrom(_from, _to, _value)
                Transfer(msg.sender, Killer, amount);               // executes an event reflecting on the change
                return;                                             // ends function and returns
            }
        }

Ответы (1)

Проблема видимо в подходе.

Вы пытаетесь перевести eth из кошельков, которые не контролирует контракт. Контракт может делать почти все, что может человек, но не более того. Если не может, например, тратить чужие деньги.

Подумайте об этом так:

  • Отправитель -> Контракт
  • Контракт -> Получатель (используя полученные деньги).

function pay(address receiver) payable returns(bool success) {
  // uint paid = msg.value
  balance[msg.sender] += paid;
  return true;
}

function claim() returns(bool success) {
  if(balance[msg.sender]==0) throw;
  uint amount = balance[msg.sender];
  msg.sender.transfer(amount);
  return true;
}

Надеюсь, поможет.