Skip to content

Commit

Permalink
add event log show api
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Oct 17, 2018
1 parent 47f2330 commit 97eea5c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/controllers/api/event_logs_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

class Api::EventLogsController < ApplicationController
# params:
# {
# "page": "1", // default 1
# "perPage": "10", // default 10
# }
#
# GET /api/event_logs/:address
def show
address = params[:address]
event_logs = EventLog.where("address ILIKE ?", address).order(id: :desc).page(params[:page]).per(params[:perPage])

render json: {
result: {
count: event_logs.total_count,
event_logs: ActiveModelSerializers::SerializableResource.new(event_logs, each_serializer: ::Api::EventLogSerializer)
}
}
end
end
11 changes: 11 additions & 0 deletions app/serializers/api/event_log_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class Api::EventLogSerializer < ActiveModel::Serializer
attributes :address, :data, :topics
attribute :block_hash, key: :blockHash
attribute :block_number, key: :blockNumber
attribute :log_index, key: :logIndex
attribute :transaction_hash, key: :transactionHash
attribute :transaction_index, key: :transactionIndex
attribute :transaction_log_index, key: :transactionLogIndex
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
resources :sync_errors, only: [:index]
get "erc20/transfers", to: "erc20_transfers#index"
get "transactions/:hash", to: "transactions#show"
get "event_logs/:address", to: "event_logs#show"
end

health_check_routes
Expand Down
5 changes: 5 additions & 0 deletions spec/controllers/api/event_logs_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe Api::EventLogsController, type: :controller do

end

0 comments on commit 97eea5c

Please sign in to comment.