Class: Blockchain::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/transaction.rb

Defined Under Namespace

Classes: Input, Output

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(t) ⇒ Transaction



10
11
12
13
14
15
16
# File 'lib/transaction.rb', line 10

def initialize(t)
  @hsh = t.delete('hash')
  t.each_key { |k| instance_variable_set("@#{k}", t[k]) }
  @inputs.map! { |i| Input.new(i) }
  @out.map! { |o| Output.new(o) }
  @time = DateTime.strptime(@time.to_s, '%s')
end

Instance Attribute Details

#block_heightObject (readonly)

Returns the value of attribute block_height.



4
5
6
# File 'lib/transaction.rb', line 4

def block_height
  @block_height
end

#double_spendObject (readonly)

Returns the value of attribute double_spend.



3
4
5
# File 'lib/transaction.rb', line 3

def double_spend
  @double_spend
end

#hshObject (readonly)

Returns the value of attribute hsh.



3
4
5
# File 'lib/transaction.rb', line 3

def hsh
  @hsh
end

#inputsObject (readonly)

Returns the value of attribute inputs.



4
5
6
# File 'lib/transaction.rb', line 4

def inputs
  @inputs
end

#outObject (readonly)

Returns the value of attribute out.



4
5
6
# File 'lib/transaction.rb', line 4

def out
  @out
end

#relayed_byObject (readonly)

Returns the value of attribute relayed_by.



4
5
6
# File 'lib/transaction.rb', line 4

def relayed_by
  @relayed_by
end

#resultObject (readonly)

Returns the value of attribute result.



3
4
5
# File 'lib/transaction.rb', line 3

def result
  @result
end

#sizeObject (readonly)

Returns the value of attribute size.



3
4
5
# File 'lib/transaction.rb', line 3

def size
  @size
end

#timeObject (readonly)

Returns the value of attribute time.



3
4
5
# File 'lib/transaction.rb', line 3

def time
  @time
end

#tx_indexObject (readonly)

Returns the value of attribute tx_index.



4
5
6
# File 'lib/transaction.rb', line 4

def tx_index
  @tx_index
end

#verObject (readonly)

Returns the value of attribute ver.



3
4
5
# File 'lib/transaction.rb', line 3

def ver
  @ver
end

#vin_szObject (readonly)

Returns the value of attribute vin_sz.



3
4
5
# File 'lib/transaction.rb', line 3

def vin_sz
  @vin_sz
end

#vout_szObject (readonly)

Returns the value of attribute vout_sz.



3
4
5
# File 'lib/transaction.rb', line 3

def vout_sz
  @vout_sz
end

Class Method Details

.find(transaction) ⇒ Object



6
7
8
# File 'lib/transaction.rb', line 6

def self.find(transaction)
  self.new(Blockchain.rawtx(transaction))
end

Instance Method Details

#==(o) ⇒ Object



30
31
32
# File 'lib/transaction.rb', line 30

def ==(o)
  o.instance_variables == self.instance_variables
end

#txfeeObject



26
27
28
# File 'lib/transaction.rb', line 26

def txfee
  Btc.from_satoshis(Blockchain.q("txfee/#{@hsh}"))
end

#txtotalbtcinputObject



22
23
24
# File 'lib/transaction.rb', line 22

def txtotalbtcinput
  Btc.from_satoshis(Blockchain.q("txtotalbtcinput/#{@hsh}"))
end

#txtotalbtcoutputObject



18
19
20
# File 'lib/transaction.rb', line 18

def txtotalbtcoutput
  Btc.from_satoshis(Blockchain.q("txtotalbtcoutput/#{@hsh}"))
end