Class: Event::Participant

Inherits:
ApplicationRecord show all
Includes:
Currency
Defined in:
app/models/event/participant.rb

Constant Summary

Constants included from Currency

Currency::COMMISSION_PRECISION, Currency::LIABILITY_CODES, Currency::RATIO_PRECISION, Currency::REVENUE_CODES, Currency::TOKENS_AMOUNT_PRECISION

Instance Method Summary collapse

Methods included from Currency

#fetch_currency

Instance Method Details

#perform_transfer(transfer_params) ⇒ Object



62
63
64
65
# File 'app/models/event/participant.rb', line 62

def perform_transfer(transfer_params)
  Peatio::ManagementAPIV2::Client.new.create_transfer(transfer_params)
  transfer_keys << transfer_params[:key]
end

#transfer_amountObject

Instance Methods =====================================================



32
33
34
35
# File 'app/models/event/participant.rb', line 32

def transfer_amount
  perform_transfer(transfer_params)
  save!
end

#transfer_paramsObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/models/event/participant.rb', line 37

def transfer_params
  currency = fetch_currency(event.currency_id)
                           .fetch(:type)
                           .to_sym

  operations =
    [
      { # Debit owner main liabilities & credit user main liabilities with base currency.
        currency:    event.currency_id,
        amount:      event.amount,
        account_src: {code: Currency::LIABILITY_CODES[currency][:main],
                      uid:  event.creator_uid},
        account_dst: {code: Currency::LIABILITY_CODES[currency][:main],
                      uid:  uid}
      }
    ]

  {
    key:         "event-#{self.id}",
    category:    :purchases,
    description: "Event deposit participant prize #{uid}",
    operations:  operations
  }
end