Кодовый вопрос аукциона умный контракт - PullRequest
0 голосов
/ 05 апреля 2019

Это Аукцион умный контракт.Я хочу сделать Аукцион таким.Если кто-то зарегистрирует свой продукт для участия в торгах, любой, кто захочет купить, может присоединиться к этим торгам.

Но когда я тестирую на Remix, он не может быть выполнен даже.Я думаю, что мое кодирование является проблемой.Пожалуйста, помогите мне.

pragma solidity ^0.5.0;

contract Auction{
//product for auction
struct Product{
    string name;
    string description;
    uint time;
}

//top bid
uint topMoney;

//presen owner of product
mapping (uint => address) productToOwner;
//owner of top bidder 
mapping (uint => address) topMoneyOwner;




event Listed(uint id, string name, uint itme);

Product[] public products;

//register product
function listUp(string memory _name, string memory _description) public {
    //time limit for bidding, 1 minutes;
    uint time = now + 1 minutes;
    //index of product
    uint id = products.push(Product(_name, _description, time)) - 1;
    //initial bid = 0
    topMoney=0;
    //initial owner of product
    productToOwner[id] = msg.sender;
    emit Listed(id, _name, time);
}

//bidding
function bidOn() payable public {
    if ( topMoney < msg.value){            
        topMoney = msg.value;   
        topMoneyOwner[topMoney] = msg.sender;         
    } else {
        msg.sender.transfer(msg.value);
    }

}

//bidding end? return (bool)
function _end(uint _id) private view returns (bool) {
    require(now >= products[_id].time);
        return true;             
}

//who is winner? Then, transfer money to owner of product.
function winner(uint _id)  public  {
    require( true == _end(_id));
    address(uint160(productToOwner[_id])).transfer(topMoney);
    productToOwner[_id] = topMoneyOwner[topMoney];
}   
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...