Class: Immudb::Tx

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#AlhObject

Returns the value of attribute Alh.



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

def Alh
  @Alh
end

#BlRootObject

Returns the value of attribute BlRoot.



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

def BlRoot
  @BlRoot
end

#BlTxIDObject

Returns the value of attribute BlTxID.



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

def BlTxID
  @BlTxID
end

#entriesObject

Returns the value of attribute entries.



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

def entries
  @entries
end

#htreeObject

Returns the value of attribute htree.



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

def htree
  @htree
end

#IDObject

Returns the value of attribute ID.



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

def ID
  @ID
end

#nentriesObject

Returns the value of attribute nentries.



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

def nentries
  @nentries
end

#PrevAlhObject

Returns the value of attribute PrevAlh.



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

def PrevAlh
  @PrevAlh
end

#TsObject

Returns the value of attribute Ts.



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

def Ts
  @Ts
end

Instance Method Details

#build_hash_treeObject



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

def build_hash_tree
  digests = []
  @entries.each do |e|
    digests << e.digest
  end
  @htree.build_with(digests)
end

#calc_alhObject



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

def calc_alh
  calc_innerhash
  bi = [@ID].pack("Q>") + @PrevAlh + @InnerHash
  @Alh = Digest::SHA256.digest(bi)
end

#calc_innerhashObject



31
32
33
34
35
# File 'lib/immudb/tx.rb', line 31

def calc_innerhash
  bj = [@Ts, @nentries].pack("Q>L>") + eh
  bj += [@BlTxID].pack("Q>") + @BlRoot
  @InnerHash = Digest::SHA256.digest(bj)
end

#ehObject



37
38
39
# File 'lib/immudb/tx.rb', line 37

def eh
  @htree.root
end

#proof(key) ⇒ Object



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

def proof(key)
  kindex = nil
  # find index of element holding given key
  @entries.each_with_index do |v, k|
    if v.key == key
      kindex = k
      break
    end
  end
  if kindex.nil?
    raise KeyError
  end
  @htree.inclusion_proof(kindex)
end