lib/zold/node/front.rb in zold-0.2 vs lib/zold/node/front.rb in zold-0.3
- old
+ new
@@ -45,23 +45,26 @@
# Web front
class Front < Sinatra::Base
configure do
set :bind, '0.0.0.0'
set :logging, true
+ set :dump_errors, true
set :start, Time.now
- set :lock, Mutex.new
+ set :lock, true
set :log, Log.new
set :show_exceptions, false
set :home, Dir.pwd
set :farm, Farm.new
set :server, 'webrick'
end
before do
if request.env[Http::SCORE_HEADER]
s = Score.parse(request.env[Http::SCORE_HEADER])
- raise 'The score is invalid' if !s.valid? || s.value < 3
+ error(400, 'The score is invalid') unless s.valid?
+ error(400, 'The score is too small') if s.value < 3
+ error(400, 'The score is weak') if s.strength < Score::STRENGTH
settings.remotes.add(s.host, s.port)
end
end
after do
@@ -91,10 +94,11 @@
memory: Facter::Memory.mem_size
},
wallets: {
total: wallets.all.count
},
+ farm: settings.farm.to_json,
date: `date --iso-8601=seconds -u`.strip,
age: Time.now - settings.start,
home: 'https://www.zold.io'
)
end
@@ -115,11 +119,11 @@
id = Id.new(params[:id])
wallet = wallets.find(id)
request.body.rewind
cps = copies(id)
cps.add(request.body.read, 'remote', Remotes::PORT, 0)
- Zold::Merge.new(wallet: wallet, copies: cps).run
+ Zold::Merge.new(wallets: wallets, copies: cps.root).run([id.to_s])
"Success, #{wallet.id} balance is #{wallet.balance}"
end
get '/remotes' do
content_type 'application/json'
@@ -137,9 +141,15 @@
not_found do
status 404
content_type 'text/plain'
'Page not found'
+ end
+
+ error 400 do
+ status 400
+ content_type 'text/plain'
+ env['sinatra.error'].message
end
error do
status 503
e = env['sinatra.error']