0

Cannot compile the "contract Auction". Got this error for Miscellaneous methods.

//Miscellaneous methods: Below methods are used to assist Grading. Please DONOT CHANGE THEM
function getPersonDetails(uint id) public constant returns(uint,uint,address){
    return (bidders[id].remainingTokens,bidders[id].personId,bidders[id].addr); 
}

https://i.stack.imgur.com/igtp1.png

EDIT

Complete code:

pragma solidity ^0.4.17;

contract Auction {
    // Data
    //Structure to hold details of the item
    struct Item { 
        uint itemId;          // id of the item 
        uint[] itemTokens;    //tokens bid in favor of the item
    }

    //Structure to hold the details of a persons
    struct Person { 
        uint remainingTokens; //tokens remaining with bidder
        uint personId;        //it serves as tokenId as well
        address addr;         //address of the bidder
    }

    mapping(address => Person) tokenDetails; //address to person
    Person [4] bidders;//Array containing 4 person objects

    Item [3] public items;       //Array containing 3 item objects 
    address[3] public winners;   //Array for address of winners 
    address public beneficiary;  //owner of the smart contract
    uint bidderCount=0;          //counter

    //functions
    function Auction() public payable{                     //constructor
        beneficiary = msg.sender;                          //Part 1 Task 1 – 1 line
        uint[] memory emptyArray; 
        items[0] = Item({itemId:0,itemTokens:emptyArray});
        items[1] = Item({itemId:1,itemTokens:emptyArray}); //Part 1 Task 2 – line 1
        items[2] = Item({itemId:2,itemTokens:emptyArray}); //Part 1 Task 2 – line 2
    }

    function register() public payable{
        bidders[bidderCount].personId = bidderCount;
        bidders[bidderCount].addr = addr;                  //Part 1 Task 3 – 1 line
        bidders[bidderCount].remainingTokens = 5;          // only 5 tokens
        tokenDetails[msg.sender]=bidders[bidderCount];
        bidderCount++; 
    }

    function bid(uint _itemId, uint _count) public payable{
        if (tokenDetails[msg.sender].remainingTokens < _count) return; //Part 1 Task 4 – line 1
        if (_itemId > 2) return;                                       //Part 1 Task 4 – line 2
        (tokenDetails[msg.sender].remainingTokens - _count);           //Part 1 Task 5 – 1 line
        bidders[tokenDetails[msg.sender].personId].remainingTokens= tokenDetails[msg.sender].remainingTokens; //updating the same balance in bidders map. 
        Item storage bidItem = items[_itemId]; 
        for(uint i=0; i<_count;i++) { 
            bidItem.itemTokens.push(tokenDetails[msg.sender].personId); 
        }
    }

    function revealWinners() public {
         for (uint id = 0; id < 3; id++) { 
             Item storage currentItem=items[id]; 
             If (currentItem.itemTokens.length != 0);
                 uint randomIndex = (block.number / currentItem.itemTokens.length)% currentItem.itemTokens.length; 
                 uint winnerId = currentItem.itemTokens[randomIndex];
                 return winnerId;                                      //Part 1 Task 6 – 1 line
            }
        }
    }

    //Miscellaneous methods: Below methods are used to assist Grading. Please DONOT CHANGE THEM
    function getPersonDetails(uint id) public constant returns(uint,uint,address){
      return (bidders[id].remainingTokens,bidders[id].personId,bidders[id].addr); 
    }
}
  • Please share the rest of the code. The problem is probably an extra curly brace somewhere above this. – user19510 Dec 8 '18 at 8:53
  • Like to do this, but cannot add the code because more than max char allowed. Possible to do this by mail? – D. Nerge Dec 8 '18 at 9:48
  • Maybe try pastebin.com? – user19510 Dec 8 '18 at 9:49
  • I created an account "DieterNerge". But how you get it from there? – D. Nerge Dec 8 '18 at 9:58
  • Message created! – D. Nerge Dec 8 '18 at 10:10
0

This line:

If (currentItem.itemTokens.length != 0);

should be:

if (currentItem.itemTokens.length != 0) {

(lowercase i in if and a curly brace instead of a semicolon)

  • May I ask a next question? Compilation was o.k. But I got warnings reg. gas and that's why I cannot run it. I created a new pastebin with all comments from the course. pastebin.com/tDMnvafT Thx in advance! – D. Nerge Dec 9 '18 at 16:24
  • All lines I edited are marked with //Part 1 - Task n - Line n – D. Nerge Dec 9 '18 at 16:26
  • Please create a new question. – user19510 Dec 9 '18 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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