-
Notifications
You must be signed in to change notification settings - Fork 8
/
sample.sol
51 lines (37 loc) · 1.17 KB
/
sample.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
pragma solidity ^0.4.18;
import "node_modules/zeppelin-solidity/contracts/math/SafeMath.sol";
contract SampleContract {
using SafeMath for uint256;
// address where funds are store
address public wallet;
// amount of raised money in wei
uint256 public weiRaised;
// number of upvotes
uint256 public upvoteCount;
function SampleContract(address _wallet) public {
require(_wallet != address(0));
wallet = _wallet;
}
// internal method with no risky things
function isRich() internal view returns (bool) {
return weiRaised >= 1000000000000000000;
}
// publically accessible method with no risky things
function areMoniesNeeded() public view returns (bool) {
return !isRich();
}
// publically accessible method with some risky things
function upvote() public {
// update state
upvoteCount = weiRaised.add(1);
}
// publically accessible method with lots of risky things
function acceptMonies(address beneficiary) public payable {
require(beneficiary != address(0));
require(!isRich());
// update state
weiRaised = weiRaised.add(msg.value);
// make external call
wallet.transfer(msg.value);
}
}