Adresse.(senden|übertragen), Empfänger nicht empfangen

In einem Solidity-Vertrag verwende ich address.send()und address.transfer()um Geld an einen Empfänger zu senden. Wenn ich diese Funktion ausführe, wird der Saldo des Vertrags abgezogen, aber die Empfängeradresse erhält niemals das Geld auf ihrem Konto.

Was läuft schief und wie debugge/repariere ich? Ich bin neu bei Ethereum, also kleine Schritte bitte :)

Danke

AKTUALISIEREN:

Ich verwende testrpc und es scheint, dass ich keine Transaktion für diesen Betrag in der Konsolenausgabe sehe. Alles, was ich in der Blockchain sehe, ist die Transaktion zum Aufrufen meiner Vertragsfunktion, die address.send(). Warum ist das?

UPDATE: Vertrag wie gewünscht

pragma solidity ^0.4.11;
// We have to specify what version of compiler this code will compile with

contract Hackathon {

  struct Entry {
    bytes32 name;
    uint votes;
    address wallet;
  }

  Entry[] public entries;
  address winner;

  function AddEth () payable {}

  /* mapping field below is equivalent to an associative array or hash.
  The key of the mapping is candidate name stored as type bytes32 and value is
  an unsigned integer to store the vote count
  */

  mapping (bytes32 => uint8) public votesReceived;

  /* Solidity doesn't let you pass in an array of strings in the constructor (yet).
  We will use an array of bytes32 instead to store the list of candidates
  */

  /* This is the constructor which will be called once when you
  deploy the contract to the blockchain. When we deploy the contract,
  we will pass an array of candidates who will be contesting in the election
  */
  function Hackathon() {
  }

  // This function returns the total votes a candidate has received so far
  function totalVotesFor(bytes32 candidate) returns (uint8) {
    if (validCandidate(candidate) == false) throw;
    return votesReceived[candidate];
  }

  // This function increments the vote count for the specified candidate. This
  // is equivalent to casting a vote
  function voteForCandidate(bytes32 candidate) {
    if (validCandidate(candidate) == false) throw;
    votesReceived[candidate] += 1;
  }

  function validCandidate(bytes32 candidate) returns (bool) {
    for(uint i = 0; i < entries.length; i++) {
      if (entries[i].name == candidate) {
        return true;
      }
    }
    return false;
  }

  function getWinner() returns (bytes32, uint256, address) {

    bytes32 winnerName;
    uint winningVoteCount = 0;

    for (uint p = 0; p < entries.length; p++) {
        if (votesReceived[entries[p].name] > winningVoteCount) {
            winningVoteCount = votesReceived[entries[p].name];
            winnerName = entries[p].name;
            winner = entries[p].wallet;
        }
    }

    return (winnerName, winningVoteCount, winner);
  }

  function payWinner() returns (bool) {

    winner.transfer(23);

    return true;
  }

  function addEntry(bytes32 name, address wallet) returns (uint256) {

    Entry memory tmpEntry;
    tmpEntry.name = name;
    tmpEntry.wallet = wallet;

    return entries.push(tmpEntry);
  }

  function getEntriesCount() returns (uint256) {

    return entries.length;
  }

  function getEntry(uint index) returns (bytes32, uint, address) {

    return (entries[index].name, votesReceived[entries[index].name], entries[index].wallet);
  }
}
Wir müssen Ihren Vertrag sehen, um ein Gefühl dafür zu bekommen, was passiert.
Ich habe die Frage aktualisiert. Ich habe alles weggeworfen, weil ich nicht sicher war, was wichtig war.

Antworten (1)

Ich habe mich da ziemlich verheddert und war nicht in der Lage, ein auffälliges Problem zu lokalisieren. Siehe Mapped Structs with Index hier drüben: Gibt es gut gelöste und einfache Speichermuster für Solidity?

Am Ende wurden die Daten neu organisiert, Ereignisse für Zustandsänderungen und forSchleifen (Anti-Muster) entfernt. Sie wollen diese nicht, weil es nicht skaliert, also verfolgt es den Anführer, während es jetzt geht. Es vergibt den Anführer nur einmal, nur der einzige kann dies tun, und es gibt passive Nur-Lese-Getter, die den Status nicht ändern (der alte getWinner änderte den Status).

Es ist wahrscheinlich nicht perfekt, aber ich denke, es ist mehr auf dem richtigen Weg und wird Ihnen hoffentlich Ideen geben.

pragma solidity ^0.4.11;
// We have to specify what version of compiler this code will compile with

contract Hackathon {

  address public leader;
  uint public leaderVotes;
  bool public isOver;
  uint public prize;
  address public owner;

  struct CandidateStruct {
    bytes32 name;
    uint votes;
    uint candidatePointer;
  }

  mapping(address => CandidateStruct) public candidateStructs;
  address[] public candidateList;

  modifier onlyOwner {
      if(msg.sender != owner) throw;
      _;
  }

  event LogDeposit(address sender, uint amount);
  event LogVote(address sender, address candidate, uint votes);
  event LogVotingClosed(address sender);
  event LogWinnerPaid(address sender, address winner, uint amount);
  event LogNewCandidate(address sender, bytes32 name, address candidate, uint row);
  event LogNewLeader(address leader);

  function Hackathon() {
      owner = msg.sender;
  }

  function deposit() payable returns(bool success) {
      LogDeposit(msg.sender, msg.value);
      prize = this.balance;
      return true;
  }

  function isCandidate(address candidate) public constant returns(bool success) {
      if(candidateList.length==0) return false;
      return(candidateList[candidateStructs[candidate].candidatePointer]==candidate);
  }

  // This function increments the vote count for the specified candidate. This
  // is equivalent to casting a vote
  function voteForCandidate(address candidate) public returns(bool success) {
    if(!isCandidate(candidate)) throw;
    if(isOver) throw;
    candidateStructs[candidate].votes += 1;
    if(candidateStructs[candidate].votes > leaderVotes) {
        leader = candidate;
        leaderVotes = candidateStructs[candidate].votes;
    }
    LogVote(msg.sender, candidate, candidateStructs[candidate].votes);
    return true;
  }

  function closeVoting() onlyOwner returns(bool success) {
    if(isOver) throw;
    isOver = true;
    LogVotingClosed(msg.sender);
    return true;
  }

  function payWinner() onlyOwner returns (bool) {
    if(!isOver) throw;
    if(prize == 0) throw;
    uint amount = prize;
    prize = 0; // re-entrace
    LogWinnerPaid(msg.sender, leader, amount);
    leader.transfer(amount);
    return true;
  }

  function addCandidate(bytes32 name, address candidate) public returns(bool success) {
    if(isCandidate(candidate)) throw;
    candidateStructs[candidate].name = name;
    candidateStructs[candidate].candidatePointer = candidateList.push(candidate)-1;
    LogNewCandidate(msg.sender, name, candidate, candidateStructs[candidate].candidatePointer);
    return true;
  }

  function getCandidateCount() public constant returns (uint256) {
    return candidateList.length;
  }

  function kill() onlyOwner {
      selfdestruct(owner);
  }

}

Im Remix, um zu zeigen, dass es funktioniert. Beachten Sie das Ereignisprotokoll, um zu sehen, was ich getan habe.

Geben Sie hier die Bildbeschreibung ein