Skip to main content
A spelling and typo corrected
Source Link
Ajoy Bhatia
  • 1.4k
  • 15
  • 31

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~

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 loose 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 is helps~

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 lose 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 it helps~

When you callingcall buyTicket, your fund isfunds are saved to the contract,. registrantsPaid only record fund ofrecords funds for every account, all fund is that has called buyTicket. All funds are saved to the contract, because a contract is aan account.If

If you call the destroy function, the fundfunds of the contract will be refundrefunded to organizer account, you. You can get the balance of the contract by this.balance. 

Your code has a bug , if numRegistrants >= quota is true, currentthe user of calling buyTicketbuyTicket will lostloose some fundfunds, so you must refund ithim. 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 is helps~

When you calling buyTicket, your fund is saved to contract, registrantsPaid only record fund of every account, all fund is saved to contract, because contract is a account.If you call destroy function, the fund of contract will be refund to organizer account, you can get balance of contract by this.balance. Your code has a bug , if numRegistrants >= quota is true, current user of calling buyTicket will lost some fund, so you must refund it. 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 is helps~

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 loose 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 is helps~

Source Link
BinGoBinBin
  • 2.2k
  • 14
  • 17

When you calling buyTicket, your fund is saved to contract, registrantsPaid only record fund of every account, all fund is saved to contract, because contract is a account.If you call destroy function, the fund of contract will be refund to organizer account, you can get balance of contract by this.balance. Your code has a bug , if numRegistrants >= quota is true, current user of calling buyTicket will lost some fund, so you must refund it. 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 is helps~