这是拍卖智能合约。我想做这样的拍卖。如果有人注册他的产品进行竞标,任何想购买的人都可以参与此次竞标。
但是当我在 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];
}
}