Sha256: c0374782ee25967dca6084921cf5f8951c26de4e83a0e260ccc5ca347a169cdc

Contents?: true

Size: 1.55 KB

Versions: 2

Compression:

Stored size: 1.55 KB

Contents

module OmiseGO
  class Transaction < Base
    attributes :id, :idempotency_token, :from, :to, :exchange,
               :metadata, :encrypted_metadata, :status, :created_at

    class << self
      def all(params: {}, client: nil)
        if params[:provider_user_id]
          all_for_user(
            provider_user_id: params[:provider_user_id],
            address: params[:address],
            params: params,
            client: client
          )
        else
          request(client).send('transaction.all', {}, params: params).data
        end
      end

      def all_for_user(provider_user_id:, address: nil, params: {}, client: nil)
        body = {
          provider_user_id: provider_user_id,
          address:          address
        }

        request(client).send('user.get_transactions', body, params: params).data
      end
    end

    def create(from_address:, to_address:, token_id:, amount:, metadata: {}, encrypted_metadata: {})
      request(client).send('transfer', {
                             from_address: from_address,
                             to_address: to_address,
                             token_id: token_id,
                             amount: amount,
                             metadata:  metadata,
                             encrypted_metadata:  encrypted_metadata
                           }, params: params).data
    end

    def from
      @_from ||= TransactionSource.new(@from)
    end

    def to
      @_to ||= TransactionSource.new(@to)
    end

    def exchange
      @_exchange ||= Exchange.new(@exchange)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
omisego-0.11.0 lib/omisego/transaction.rb
omisego-0.10.0 lib/omisego/transaction.rb