Class: Receipt

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

Overview

transaction receipt

Constant Summary collapse

@@directory =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tx:, block:, contract: nil) ⇒ Receipt

Returns a new instance of Receipt.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/universum/receipt.rb', line 25

def initialize( tx:,
                block:,
                contract: nil )
   @nonce = tx.nonce
   @from  = tx.from
   @to    = tx.to
   @value = tx.value
   ## todo/fix: add data too!!!

   @block_number    = block.number
   ## todo/fix: add block_hash

   if contract
     ## note: for easier debugging add class name in () to address (needs to get stripped away in lookup)
     @contract_address = "#{contract.address.hex} (#{contract.class.name})"
   else
     @contract_address = nil
   end
end

Instance Attribute Details

#block_numberObject (readonly)

required attributes / fields



20
21
22
# File 'lib/universum/receipt.rb', line 20

def block_number
  @block_number
end

#contract_addressObject (readonly)

optional



23
24
25
# File 'lib/universum/receipt.rb', line 23

def contract_address
  @contract_address
end

#fromObject (readonly)

required attributes / fields



20
21
22
# File 'lib/universum/receipt.rb', line 20

def from
  @from
end

#nonceObject (readonly)

required attributes / fields



20
21
22
# File 'lib/universum/receipt.rb', line 20

def nonce
  @nonce
end

#toObject (readonly)

required attributes / fields



20
21
22
# File 'lib/universum/receipt.rb', line 20

def to
  @to
end

#valueObject (readonly)

required attributes / fields



20
21
22
# File 'lib/universum/receipt.rb', line 20

def value
  @value
end

Class Method Details

.[](tx) ⇒ Object



11
# File 'lib/universum/receipt.rb', line 11

def self.[]( tx ) find( tx ); end

.allObject



16
# File 'lib/universum/receipt.rb', line 16

def self.all() @@directory.values; end

.find(tx) ⇒ Object



7
8
9
10
# File 'lib/universum/receipt.rb', line 7

def self.find( tx )
   key = "#{tx.from}/#{tx.nonce}"
   @@directory[ key ];
end

.store(o) ⇒ Object



13
14
15
# File 'lib/universum/receipt.rb', line 13

def self.store( o )
key = "#{o.from}/#{o.nonce}"
@@directory.store( key, o ); end

Instance Method Details

#contractObject

convenience helper (quick contract lookup)



45
46
47
48
49
50
51
# File 'lib/universum/receipt.rb', line 45

def contract   # convenience helper (quick contract lookup)
  if @contract_address
    Contract.find( @contract_address )
  else
    nil
  end
end