Class: Immudb::Tx

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTx

Returns a new instance of Tx.



17
18
19
20
21
# File 'lib/immudb/tx.rb', line 17

def initialize
  @header = nil
  @entries = nil
  @htree = nil
end

Instance Attribute Details

#entriesObject

Returns the value of attribute entries.



15
16
17
# File 'lib/immudb/tx.rb', line 15

def entries
  @entries
end

#headerObject

Returns the value of attribute header.



15
16
17
# File 'lib/immudb/tx.rb', line 15

def header
  @header
end

#htreeObject

Returns the value of attribute htree.



15
16
17
# File 'lib/immudb/tx.rb', line 15

def htree
  @htree
end

Instance Method Details

#build_hash_treeObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/immudb/tx.rb', line 33

def build_hash_tree
  digests = []
  tx_entry_digest = self.tx_entry_digest
  @entries.each do |e|
    digests << tx_entry_digest.call(e)
  end
  @htree.build_with(digests)
  root = @htree.root
  @header.eh = root
end

#index_of(key) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/immudb/tx.rb', line 44

def index_of(key)
  kindex = nil
  @entries.each_with_index do |v, k|
    if v.key == key
      kindex = k
      break
    end
  end
  if kindex.nil?
    raise VerificationError
  end
  kindex
end

#proof(key) ⇒ Object



58
59
60
61
# File 'lib/immudb/tx.rb', line 58

def proof(key)
  kindex = index_of(key)
  htree.inclusion_proof(kindex)
end

#tx_entry_digestObject



23
24
25
26
27
28
29
30
31
# File 'lib/immudb/tx.rb', line 23

def tx_entry_digest
  if @header.version == 0
    method(:tx_entry_digest_v1_1)
  elsif @header.version == 1
    method(:tx_entry_digest_v1_2)
  else
    raise VerificationError
  end
end