lib/zold/node/front.rb in zold-0.13.46 vs lib/zold/node/front.rb in zold-0.14.0

- old
+ new

@@ -47,10 +47,11 @@ set :start, Time.now set :lock, false set :show_exceptions, false set :server, 'webrick' set :version, VERSION # to be injected at node.rb + set :protocol, PROTOCOL # to be injected at node.rb set :ignore_score_weakness, false # to be injected at node.rb set :reboot, false # to be injected at node.rb set :home, nil? # to be injected at node.rb set :logging, true # to be injected at node.rb set :log, nil? # to be injected at node.rb @@ -87,14 +88,17 @@ settings.log.debug("#{request.url}: the score is too weak: #{s}") end end end + # @todo #357:30min Test that the headers are being set correctly. + # Currently there are no tests at all that would verify the headers. after do headers['Cache-Control'] = 'no-cache' headers['Connection'] = 'close' headers['X-Zold-Version'] = settings.version + headers['X-Zold-Protocol'] = settings.protocol.to_s headers['Access-Control-Allow-Origin'] = '*' headers[Http::SCORE_HEADER] = score.reduced(16).to_s end get '/robots.txt' do @@ -148,10 +152,12 @@ error 404 unless wallet.exists? content_type 'application/json' { version: settings.version, score: score.to_h, + wallets: settings.wallets.all.count, + mtime: wallet.mtime.utc.iso8601, body: AtomicFile.new(wallet.path).read }.to_json end get %r{/wallet/(?<id>[A-Fa-f0-9]{16})/balance} do @@ -168,26 +174,44 @@ error 404 unless wallet.exists? content_type 'text/plain' wallet.key.to_s end + get %r{/wallet/(?<id>[A-Fa-f0-9]{16})/mtime} do + id = Id.new(params[:id]) + wallet = settings.wallets.find(id) + error 404 unless wallet.exists? + content_type 'text/plain' + wallet.mtime.utc.iso8601.to_s + end + + get %r{/wallet/(?<id>[A-Fa-f0-9]{16})/digest} do + id = Id.new(params[:id]) + wallet = settings.wallets.find(id) + error 404 unless wallet.exists? + content_type 'text/plain' + wallet.digest + end + get %r{/wallet/(?<id>[A-Fa-f0-9]{16})\.txt} do id = Id.new(params[:id]) wallet = settings.wallets.find(id) error 404 unless wallet.exists? content_type 'text/plain' [ wallet.network, - wallet.version, + wallet.protocol, wallet.id.to_s, wallet.key.to_s, '', wallet.txns.map(&:to_text).join("\n"), '', '--', "Balance: #{wallet.balance.to_zld}", - "Transactions: #{wallet.txns.count}" + "Transactions: #{wallet.txns.count}", + "Modified: #{wallet.mtime.utc.iso8601}", + "Digest: #{wallet.digest}" ].join("\n") end put %r{/wallet/(?<id>[A-Fa-f0-9]{16})/?} do id = Id.new(params[:id]) @@ -207,10 +231,11 @@ end settings.log.info("Wallet #{id} is new: #{before.length}b != #{after.length}b") settings.entrance.push(id, after) JSON.pretty_generate( version: settings.version, - score: score.to_h + score: score.to_h, + wallets: settings.wallets.all.count ) end get '/remotes' do content_type 'application/json'