Class: Peatio::Transaction

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/peatio/transaction.rb

Overview

This class represents blockchain transaction.

Using the instant of this class the peatio application will send/recieve income/outcome transactions from a peatio pluggable blockchain.

Examples:


Peatio::Transaction.new(
  {
    hash: '0x5d0ef9697a2f3ea561c9fbefb48e380a4cf3d26ad2be253177c472fdd0e8b486',
    txout: 1,
    to_address: '0x9af4f143cd5ecfba0fcdd863c5ef52d5ccb4f3e5',
    amount: 0.01,
    block_number: 7732274,
    currency_id: 'eth',
    status: 'success'
  }
)

Author:

Constant Summary collapse

STATUSES =
Note:

Statuses list:

pending - the transaction is unconfirmed in the blockchain or wasn't created yet.

success - the transaction is a successfull, the transaction amount has been successfully transferred

failed - the transaction is failed in the blockchain.

List of statuses supported by peatio.

%w[success pending failed].freeze
DEFAULT_STATUS =
'pending'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Transaction

Returns a new instance of Transaction.


93
94
95
96
# File 'lib/peatio/transaction.rb', line 93

def initialize(attributes={})
  super
  @status = @status.present? ? @status.to_s : DEFAULT_STATUS
end

Instance Attribute Details

#amountObject

return [Decimal] amount of the transaction


62
63
64
# File 'lib/peatio/transaction.rb', line 62

def amount
  @amount
end

#block_numberObject

return [Integer] transaction block number


66
67
68
# File 'lib/peatio/transaction.rb', line 66

def block_number
  @block_number
end

#currency_idObject

return [String] transaction currency id


70
71
72
# File 'lib/peatio/transaction.rb', line 70

def currency_id
  @currency_id
end

#hashObject

return [String] transaction hash


50
51
52
# File 'lib/peatio/transaction.rb', line 50

def hash
  @hash
end

#to_addressObject

return [String] transaction recepient address


58
59
60
# File 'lib/peatio/transaction.rb', line 58

def to_address
  @to_address
end

#txoutObject

return [Integer] transaction number in send-to-many request


54
55
56
# File 'lib/peatio/transaction.rb', line 54

def txout
  @txout
end

Instance Method Details

#statusObject

Status for specific transaction.

Examples:


status.failed? # true if transaction status 'failed'
status.success? # true if transaction status 'success'

106
107
108
# File 'lib/peatio/transaction.rb', line 106

def status
  @status&.inquiry
end

#status=(s) ⇒ Object


110
111
112
# File 'lib/peatio/transaction.rb', line 110

def status=(s)
  @status = s.to_s
end