-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathPiggyBank.sol
36 lines (29 loc) · 970 Bytes
/
PiggyBank.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
pragma solidity ^0.4.0;
contract PiggyBank {
address creator;
uint deposits;
function PiggyBank() public
// Declaring this function as public makes it accessible to other users and smart contracts.
{
creator = msg.sender;
deposits = 0;
}
function deposit() payable returns (uint)
{
//check whether ether was actually sent
if(msg.value > 0)
deposits = deposits + 1;
return getNumberOfDeposits();
}
// When ether is deposited, the number of deposits go up and the total count is returned
function getNumberOfDeposits() constant returns (uint)
{
return deposits;
}
function kill()
{
if (msg.sender == creator)
selfdestruct(creator);
// When the account which instantiated this contract calls it again, it terminates and sends back its balance.
}
}