|
Algorithm 5 Non-vulnerable DAO smart contract example. |
-
1:
//DAOexample.sol
-
2:
contract DAOexample {
-
3:
mapping(address => uint256) public funds;
-
4:
function incrementUserCredit() payable {
-
5:
funds[msg.sender] += msg.value;
-
6:
}
-
7:
function getUserCreditAmount() returns (uint) {
-
8:
return funds[msg.sender];
-
9:
}
-
10:
function recoverUserCredit(uint amount) {
-
11:
if (amount <= funds[msg.sender]) {
-
12:
funds[msg.sender] -= amount; //Update balance before the external call
-
13:
msg.sender.call.value(amount)();
-
14:
}
-
15:
}
-
16:
}
|