forked from hpyhacking/peatio
/
deposits.rb
45 lines (38 loc) · 1.72 KB
/
deposits.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# encoding: UTF-8
# frozen_string_literal: true
require_relative 'validations'
module APIv2
class Deposits < Grape::API
helpers ::APIv2::NamedParams
before { authenticate! }
before { identity_must_be_verified! }
desc 'Get your deposits history.'
params do
optional :currency, type: String, values: -> { Currency.codes(bothcase: true) }, desc: -> { "Currency value contains #{Currency.codes(bothcase: true).join(',')}" }
optional :limit, type: Integer, range: 1..100, default: 3, desc: "Set result limit."
optional :state, type: String, values: -> { Deposit::STATES.map(&:to_s) }
end
get "/deposits" do
deposits = current_user.deposits.limit(params[:limit]).recent
deposits = deposits.with_currency(params[:currency]) if params[:currency]
deposits = deposits.with_aasm_state(params[:state]) if params[:state].present?
present deposits, with: APIv2::Entities::Deposit
end
desc 'Get details of specific deposit.'
params do
requires :txid
end
get "/deposit" do
deposit = current_user.deposits.find_by(txid: params[:txid])
raise DepositByTxidNotFoundError, params[:txid] unless deposit
present deposit, with: APIv2::Entities::Deposit
end
desc 'Where to deposit. The address field could be empty when a new address is generating (e.g. for bitcoin), you should try again later in that case.'
params do
requires :currency, type: String, values: -> { Currency.codes(bothcase: true) }, desc: -> { "The account to which you want to deposit. Available values: #{Currency.codes(bothcase: true).join(', ')}" }
end
get "/deposit_address" do
current_user.ac(params[:currency]).payment_address.to_json
end
end
end