Skip to content

Commit

Permalink
feat: filter token transfers by address hash
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitz committed Aug 24, 2023
1 parent 553df75 commit df8a607
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions app/controllers/api/v2/nft/transfers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,23 @@ def index
scope = TokenTransfer.all
end

from = Address.find_by_address_hash(params[:from]) if params[:from]
to = Address.find_by_address_hash(params[:to]) if params[:to]
scope = scope.where(from: from) if from
scope = scope.where(to: to) if to
scope = scope.where(action: params[:transfer_action]) if params[:transfer_action]
scope = scope.includes(:ckb_transaction).where(ckb_transaction: { tx_hash: params[:tx_hash] }) if params[:tx_hash]
if params[:from]
scope = scope.where(from: find_address(params[:from]))
end
if params[:to]
scope = scope.where(to: find_address(params[:to]))
end
if params[:address_hash]
address = find_address(params[:address_hash])
scope = scope.where(from: address).or(scope.where(to: address))
end
if params[:transfer_action]
scope = scope.where(action: params[:transfer_action])
end
if params[:tx_hash]
scope = scope.includes(:ckb_transaction).where(ckb_transaction: { tx_hash: params[:tx_hash] })
end

scope = scope.order(transaction_id: :desc)
pagy, token_transfers = pagy(scope)

Expand All @@ -50,6 +61,12 @@ def download_csv
send_data file, type: "text/csv; charset=utf-8; header=present",
disposition: "attachment;filename=token_transfers.csv"
end

private

def find_address(address_hash)
Address.find_by_address_hash(address_hash)
end
end
end
end
Expand Down

0 comments on commit df8a607

Please sign in to comment.