Class: Immudb::TxHeader

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTxHeader

Returns a new instance of TxHeader.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/immudb/tx_header.rb', line 17

def initialize
  @iD = nil
  @ts = nil
  @blTxID = nil
  @blRoot = nil
  @prevAlh = nil

  @version = nil
  @metadata = TxMetadata.new

  @nentries = nil
  @eh = nil
end

Instance Attribute Details

#blRootObject

Returns the value of attribute blRoot.



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

def blRoot
  @blRoot
end

#blTxIDObject

Returns the value of attribute blTxID.



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

def blTxID
  @blTxID
end

#ehObject

Returns the value of attribute eh.



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

def eh
  @eh
end

#iDObject

Returns the value of attribute iD.



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

def iD
  @iD
end

#metadataObject

Returns the value of attribute metadata.



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

def 
  @metadata
end

#nentriesObject

Returns the value of attribute nentries.



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

def nentries
  @nentries
end

#prevAlhObject

Returns the value of attribute prevAlh.



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

def prevAlh
  @prevAlh
end

#tsObject

Returns the value of attribute ts.



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

def ts
  @ts
end

#versionObject

Returns the value of attribute version.



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

def version
  @version
end

Instance Method Details

#alhObject



57
58
59
60
61
62
63
# File 'lib/immudb/tx_header.rb', line 57

def alh
  md = Digest::SHA256.new
  md.update([@iD].pack("Q>"))
  md.update(@prevAlh)
  md.update(inner_hash)
  md.digest
end

#inner_hashObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/immudb/tx_header.rb', line 31

def inner_hash
  md = Digest::SHA256.new
  md.update([@ts].pack("Q>"))
  md.update([@version].pack("n"))
  if @version == 0
    md.update([@nentries].pack("n"))
  elsif @version == 1
    mdbs = "".b
    if !@metadata.nil?
      mdbs = @metadata.bytes
      if mdbs.nil?
        mdbs = "".b
      end
    end
    md.update([mdbs.length].pack("n"))
    md.update(mdbs)
    md.update([@nentries].pack("N"))
  else
    raise VerificationError, "missing tx hash calculation method for version #{@version}"
  end
  md.update(@eh)
  md.update([@blTxID].pack("Q>"))
  md.update(@blRoot)
  md.digest
end