Я следую учебному пособию, чтобы написать контракт с регистрантом, и когда я пытаюсь отправить транзакции в контракт, я всегда получаю сообщение об ошибке: it seems this transaction will fail. If you submit it, it may consume all the gas upi provide
.
Я создал частную цепочку блоков на своем ноутбуке и развернул контракт через Mist. Исходный код показан ниже:
pragma solidity ^0.4.18;
contract EventRegistrant {
//basic class of registrant
struct Registrant {
uint amount;
uint numTickets;
string email;
}
//define variables
address public owner;
uint public numTicketsSold;
uint public quota;
uint public price;
mapping (address => Registrant) registrantsPaid;
event Deposit (address _from, uint _amount);
event Refund (address _to, uint _amount);
//Modifiers to define following functions
//character "_" means this is a modifier
modifier onlyOwner(){
require(msg.sender != owner);
_;
}
modifier soldOut(){
require(numTicketsSold >= quota);
_;
}
function EventRegistrant(uint _quota, uint _price) public {
owner = msg.sender;
numTicketsSold = 0;
quota = _quota;
price = _price;
}
function buyTicket(string email, uint numTickets) soldOut public payable {
uint totalAmount = price * numTickets;
require(msg.value > totalAmount);
if (registrantsPaid[msg.sender].amount > 0) {
registrantsPaid[msg.sender].amount += msg.value;
registrantsPaid[msg.sender].numTickets += numTickets;
registrantsPaid[msg.sender].email = email;
} else {
registrantsPaid[msg.sender].amount = totalAmount;
registrantsPaid[msg.sender].numTickets = numTickets;
registrantsPaid[msg.sender].email = email;
}
numTicketsSold += numTickets;
if (msg.value > totalAmount) {
uint refundAmount = msg.value - totalAmount;
require(msg.sender.send(refundAmount));
}
Deposit(msg.sender, msg.value);
}
function refundTickets(address buyer) onlyOwner public {
if (registrantsPaid[buyer].amount > 0) {
if (this.balance >= registrantsPaid[buyer].amount) {
registrantsPaid[buyer].amount = 0;
numTicketsSold = numTicketsSold - registrantsPaid[buyer].numTickets;
require(buyer.send(registrantsPaid[buyer].amount));
Refund(buyer, registrantsPaid[buyer].amount);
}
}
}
function withdrawFunds() onlyOwner public {
require(owner.send(this.balance));
}
function getRegistrantsAmountPaid(address buyer) public view returns (uint) {
return registrantsPaid[buyer].amount;
}
//destructor, to delete the contract when there is no need
function kill() onlyOwner public {
selfdestruct(owner);
}
}
Вот так выглядит мой контракт в Тумане. Это ошибка, когда я отправляю транзакцию.
Кто-нибудь может мне помочь? заранее спасибо.
buyTickets
кажется, что кто-то может купить билет только в том случае, если все билеты уже проданы ( soldOut
). Даже если это не источник проблемы, это почти наверняка ошибка.
Фрэнк Конг
Фрэнк Конг
пользователь19510
Фрэнк Конг