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.

rejected - the transaction is rejected by user.

List of statuses supported by peatio.

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Transaction

Returns a new instance of Transaction.



103
104
105
106
# File 'lib/peatio/transaction.rb', line 103

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

Instance Attribute Details

#amountObject

return [Decimal] amount of the transaction



68
69
70
# File 'lib/peatio/transaction.rb', line 68

def amount
  @amount
end

#block_numberObject

return [Integer] transaction block number



72
73
74
# File 'lib/peatio/transaction.rb', line 72

def block_number
  @block_number
end

#currency_idObject

return [String] transaction currency id



76
77
78
# File 'lib/peatio/transaction.rb', line 76

def currency_id
  @currency_id
end

#from_addressObject

return [Array<String>] transaction source addresses



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

attr_accessor :from_addresses

#from_addressesObject

return [Array<String>] transaction source addresses



60
61
62
# File 'lib/peatio/transaction.rb', line 60

def from_addresses
  @from_addresses
end

#hashObject

return [String] transaction hash



52
53
54
# File 'lib/peatio/transaction.rb', line 52

def hash
  @hash
end

#optionsObject

return [JSON] transaction options



80
81
82
# File 'lib/peatio/transaction.rb', line 80

def options
  @options
end

#to_addressObject

return [String] transaction recepient address



64
65
66
# File 'lib/peatio/transaction.rb', line 64

def to_address
  @to_address
end

#txoutObject

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



56
57
58
# File 'lib/peatio/transaction.rb', line 56

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'


116
117
118
# File 'lib/peatio/transaction.rb', line 116

def status
  @status&.inquiry
end

#status=(s) ⇒ Object



120
121
122
# File 'lib/peatio/transaction.rb', line 120

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