lib/zold/node/front.rb in zold-0.14.13 vs lib/zold/node/front.rb in zold-0.14.14

- old
+ new

@@ -69,11 +69,12 @@ use Rack::Deflater before do check_header(Http::NETWORK_HEADER) do |header| if header != settings.network - raise "Network name mismatch, you are in '#{header}', we are in '#{settings.network}'" + raise "Network name mismatch at #{request.url}, #{request.ip} is in '#{header}', \ +while #{settings.address} is in '#{settings.network}'" end end check_header(Http::PROTOCOL_HEADER) do |header| if header != settings.protocol.to_s raise "Protocol mismatch, you are in '#{header}', we are in '#{settings.protocol}'" @@ -160,19 +161,40 @@ wallet = settings.wallets.find(id) error 404 unless wallet.exists? content_type 'application/json' { version: settings.version, + protocol: settings.protocol, + id: wallet.id.to_s, score: score.to_h, wallets: settings.wallets.all.count, mtime: wallet.mtime.utc.iso8601, digest: wallet.digest, balance: wallet.balance.to_i, body: AtomicFile.new(wallet.path).read }.to_json end + get %r{/wallet/(?<id>[A-Fa-f0-9]{16}).json} do + id = Id.new(params[:id]) + wallet = settings.wallets.find(id) + error 404 unless wallet.exists? + content_type 'application/json' + { + version: settings.version, + protocol: settings.protocol, + id: wallet.id.to_s, + score: score.to_h, + wallets: settings.wallets.all.count, + key: wallet.key.to_pub, + mtime: wallet.mtime.utc.iso8601, + digest: wallet.digest, + balance: wallet.balance.to_i, + txns: wallet.txns.count + }.to_json + end + get %r{/wallet/(?<id>[A-Fa-f0-9]{16})/balance} do id = Id.new(params[:id]) wallet = settings.wallets.find(id) error 404 unless wallet.exists? content_type 'text/plain' @@ -182,11 +204,11 @@ get %r{/wallet/(?<id>[A-Fa-f0-9]{16})/key} do id = Id.new(params[:id]) wallet = settings.wallets.find(id) error 404 unless wallet.exists? content_type 'text/plain' - wallet.key.to_s + wallet.key.to_pub end get %r{/wallet/(?<id>[A-Fa-f0-9]{16})/mtime} do id = Id.new(params[:id]) wallet = settings.wallets.find(id) @@ -223,19 +245,15 @@ "Digest: #{wallet.digest}" ].join("\n") end put %r{/wallet/(?<id>[A-Fa-f0-9]{16})/?} do - id = Id.new(params[:id]) - wallet = settings.wallets.find(id) request.body.rewind - after = request.body.read.to_s - before = wallet.exists? ? AtomicFile.new(wallet.path).read.to_s : '' - if before == after + modified = settings.entrance.push(Id.new(params[:id]), request.body.read.to_s) + if modified.empty? status 304 return end - settings.entrance.push(id, after) JSON.pretty_generate( version: settings.version, score: score.to_h, wallets: settings.wallets.all.count )