When you call buyTicket
, your funds are saved to the contract. registrantsPaid
only records funds for every account that has called buyTicket
. All funds are saved to the contract, because a contract is an account.
If you call the destroy
function, the funds of the contract will be refunded to organizer
account. You can get the balance of the contract by this.balance
.
Your code has a bug , if numRegistrants >= quota
is true, the user calling buyTicket
will looselose some funds, so you must refund him. Modified as follows:
pragma solidity ^0.4.13;
contract Conference {
address public organizer;
mapping (address => uint) public registrantsPaid;
uint public numRegistrants;
uint quota = 2000;
// ...
function buyTicket() payable public returns (bool success) {
require(numRegistrants >= quota);
registrantsPaid[msg.sender] = msg.value;
numRegistrants++;
return true;
}
// ...
function destroy() { // so funds not locked in contract forever
if (msg.sender == organizer) {
suicide(organizer); // send funds to organizer
}
}
function getContractBalance() constant returns (uint){
return this.balance;
}
}
Hope isit helps~