Class: Immudb::TxHeader
- Inherits:
-
Object
- Object
- Immudb::TxHeader
- Defined in:
- lib/immudb/tx_header.rb
Instance Attribute Summary collapse
-
#blRoot ⇒ Object
Returns the value of attribute blRoot.
-
#blTxID ⇒ Object
Returns the value of attribute blTxID.
-
#eh ⇒ Object
Returns the value of attribute eh.
-
#iD ⇒ Object
Returns the value of attribute iD.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#nentries ⇒ Object
Returns the value of attribute nentries.
-
#prevAlh ⇒ Object
Returns the value of attribute prevAlh.
-
#ts ⇒ Object
Returns the value of attribute ts.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #alh ⇒ Object
-
#initialize ⇒ TxHeader
constructor
A new instance of TxHeader.
- #inner_hash ⇒ Object
Constructor Details
#initialize ⇒ TxHeader
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
#blRoot ⇒ Object
Returns the value of attribute blRoot.
15 16 17 |
# File 'lib/immudb/tx_header.rb', line 15 def blRoot @blRoot end |
#blTxID ⇒ Object
Returns the value of attribute blTxID.
15 16 17 |
# File 'lib/immudb/tx_header.rb', line 15 def blTxID @blTxID end |
#eh ⇒ Object
Returns the value of attribute eh.
15 16 17 |
# File 'lib/immudb/tx_header.rb', line 15 def eh @eh end |
#iD ⇒ Object
Returns the value of attribute iD.
15 16 17 |
# File 'lib/immudb/tx_header.rb', line 15 def iD @iD end |
#metadata ⇒ Object
Returns the value of attribute metadata.
15 16 17 |
# File 'lib/immudb/tx_header.rb', line 15 def @metadata end |
#nentries ⇒ Object
Returns the value of attribute nentries.
15 16 17 |
# File 'lib/immudb/tx_header.rb', line 15 def nentries @nentries end |
#prevAlh ⇒ Object
Returns the value of attribute prevAlh.
15 16 17 |
# File 'lib/immudb/tx_header.rb', line 15 def prevAlh @prevAlh end |
#ts ⇒ Object
Returns the value of attribute ts.
15 16 17 |
# File 'lib/immudb/tx_header.rb', line 15 def ts @ts end |
#version ⇒ Object
Returns the value of attribute version.
15 16 17 |
# File 'lib/immudb/tx_header.rb', line 15 def version @version end |
Instance Method Details
#alh ⇒ Object
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_hash ⇒ Object
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 |