forked from s6ruby/programming-crypto-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathponzi_gradual.rb
43 lines (28 loc) · 934 Bytes
/
ponzi_gradual.rb
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
# encoding: utf-8
##
# a more realistic gradual ponzy (scheme) contract
# last investors (or suckers) HODLing the bag
#
# to run type:
# $ ruby ./run_ponzi_gradual.rb
class GradualPonzi < Contract
MINIMUM_INVESTMENT = 1_000_000
def initialize
@investors = [] # type address[] - array of address
@investors.push( msg.sender )
@balances = Mapping.of( Address => Money ) # type mapping( address => unit )
end
def receive # @payable default function
assert( msg.value >= MINIMUM_INVESTMENT )
investor_share = msg.value / @investors.size
@investors.each do |investor|
@balances[investor] += investor_share
end
@investors.push( msg.sender )
end
def withdraw
payout = @balances[msg.sender]
@balances[msg.sender] = 0
msg.sender.transfer( payout )
end
end # class GradualPonzi