This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.rb
76 lines (58 loc) · 2.03 KB
/
app.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require 'sinatra/base'
require 'data_mapper'
require './models.rb'
require './monacoin_rpc.rb'
class MonaKuji < Sinatra::Base
configure do
DataMapper.finalize.auto_upgrade!
@@wallet = MonacoinRPC.new('http://monacoinrpc:[email protected]:10010')
end
helpers do
def get_payout_address
@@wallet.getnewaddress
end
end
get '/' do
@additional_js = ['index.js']
@hoge = @@wallet.getbalance
erb :index, :layout => :layout
end
get '/buy' do
redirect "/"
end
post '/buy' do
units = params[:units].to_i
payout_address = params[:address]
halt("正しい受け取り用アドレスを指定してください") if !@@wallet.validateaddress(payout_address)["isvalid"]
halt("1口から500口までしか買えないよ!") if units < 1 || units > 500
sheet = Sheet.new(:units => units, :address => get_payout_address, :payout_address => payout_address)
units.times do
sheet.tickets.new
end
sheet.save
puts "Sheet ID: #{sheet.name} / #{units} Tickets\n========"
redirect "/sheet/#{sheet.name}"
end
get '/sheet/:name/?' do
@sheet ||= Sheet.first(:name => params[:name]) || halt("シートが存在しません")
erb :sheet, :layout => :layout
end
get '/payout/:name/?' do
@sheet ||= Sheet.first(:name => params[:name]) || halt("シートが存在しません")
if !(@sheet.payout > 0)
halt("当選金がありません!")
elsif @sheet.payouted
halt("もう当選金は払われています!")
end
begin
@@wallet.settxfee(0.001)
p @@wallet.sendtoaddress(@sheet.payout_address, @sheet.payout)
@sheet.payouted = true
@sheet.save
rescue
puts "Sending to #{@sheet.name} (#{@sheet.payout}) failed"
halt("ごめんなさい, エラーが発生しました. もし当選金が払われていないのであれば <a href='https://twitter.com/0x_osyoyu'>@0x_osyoyu</a> までご連絡ください")
end
erb :payout, :layout => :layout
end
end