MerkleBlock

Companion:
class
Source:
MerkleBlock.scala
trait Product
trait Mirror
class Object
trait Matchable
class Any

Type members

Inherited types

type MirroredElemLabels <: Tuple

The names of the product elements

The names of the product elements

Inherited from:
Mirror
Source:
Mirror.scala

The name of the type

The name of the type

Inherited from:
Mirror
Source:
Mirror.scala

Value members

Concrete methods

def calcTreeWidth(leafCount: Int, height: Int): Int
Value parameters:
height

tree height (0 == bottom == leaf nodes)

leafCount

total number of leaf nodes

Returns:

the number of nodes at the given height

Source:
MerkleBlock.scala
def computeRoot(count: Int, height: Int, pos: Int, hashes: Seq[ByteVector], bits: List[Boolean], matched: List[(ByteVector, Int)]): (ByteVector, List[(ByteVector, Int)], Seq[ByteVector], List[Boolean])

compute the root hash of a partial merkle tree: Read a bit from the flag bit list: If it is '0': Read a hash from the hashes list, and return it as this node's hash. If it is '1' and this is a leaf node: Read a hash from the hashes list, store it as a matched txid, and return it as this node's hash. If it is '1' and this is an internal node: Descend into its left child tree, and store its computed hash as L. If this node has a right child as well: Descend into its right child, and store its computed hash as R. If L == R, the partial merkle tree object is invalid. Return Hash(L || R). If this node has no right child, return Hash(L || L).

compute the root hash of a partial merkle tree: Read a bit from the flag bit list: If it is '0': Read a hash from the hashes list, and return it as this node's hash. If it is '1' and this is a leaf node: Read a hash from the hashes list, store it as a matched txid, and return it as this node's hash. If it is '1' and this is an internal node: Descend into its left child tree, and store its computed hash as L. If this node has a right child as well: Descend into its right child, and store its computed hash as R. If L == R, the partial merkle tree object is invalid. Return Hash(L || R). If this node has no right child, return Hash(L || L).

Value parameters:
bits

remaining flag bits to read from

count

total number of leaves

hashes

remaining hashes to read from

height

current height (0 == bottom of the tree == leaf nodes)

pos

current position at this height, 0 = first node from the left

Returns:

a (hash, matched, remaining_hashes, remaining_bits) tuple where:

  • hash is the hash at position (height, pos)
  • matched is a list of matched txids and their position in the original block
  • remaining_hashes and remaining_bits are hashes and bits that have not been used
Source:
MerkleBlock.scala
def isBitSet(byte: Byte, bit: Int): Boolean
override def read(input: InputStream, protocolVersion: Long): MerkleBlock
Definition Classes
Source:
MerkleBlock.scala
def topHeight(leafCount: Int): Int
Value parameters:
leafCount

ttoal number of leaf nodes

Returns:

the height of the root node. For example if yo have 5 leaf nodes, the height of the root node is 3.

Source:
MerkleBlock.scala
def verify(merkleBlock: MerkleBlock): Unit
override def write(input: MerkleBlock, out: OutputStream, protocolVersion: Long): Unit
Definition Classes
Source:
MerkleBlock.scala

Inherited methods

Inherited from:
BtcSerializer
Source:
Protocol.scala
def read(in: String, protocolVersion: Long): MerkleBlock

read a message from a hex string

read a message from a hex string

Value parameters:
in

message binary data in hex format

Returns:

a deserialized message of type T

Inherited from:
BtcSerializer
Source:
Protocol.scala
Inherited from:
BtcSerializer
Source:
Protocol.scala
def read(in: Array[Byte], protocolVersion: Long): MerkleBlock

read a message from a byte array

read a message from a byte array

Value parameters:
in

serialized message

Returns:

a deserialized message

Inherited from:
BtcSerializer
Source:
Protocol.scala
def read(in: InputStream): MerkleBlock
Inherited from:
BtcSerializer
Source:
Protocol.scala
def write(t: MerkleBlock, protocolVersion: Long): ByteVector

write a message to a byte array

write a message to a byte array

Value parameters:
t

message

Returns:

a serialized message

Inherited from:
BtcSerializer
Source:
Protocol.scala
def write(t: MerkleBlock, out: OutputStream): Unit
Inherited from:
BtcSerializer
Source:
Protocol.scala