Exemplo n.º 1
0
// Returns the LedgerMR for this block.
func (b *FBlock) GetLedgerMR() interfaces.IHash {

	b.EndOfPeriod(0) // Clean up end of minute markers, if needed.

	hashes := make([]interfaces.IHash, 0, len(b.Transactions))
	marker := 0
	for i, trans := range b.Transactions {
		for marker < len(b.endOfPeriod) && i != 0 && i == b.endOfPeriod[marker] {
			marker++
			hashes = append(hashes, primitives.Sha(constants.ZERO))
		}
		data, err := trans.MarshalBinarySig()
		hash := primitives.Sha(data)
		if err != nil {
			panic("Failed to get LedgerMR: " + err.Error())
		}
		hashes = append(hashes, hash)
	}

	// Add any lagging markers
	for marker < len(b.endOfPeriod) {
		marker++
		hashes = append(hashes, primitives.Sha(constants.ZERO))
	}
	lmr := primitives.ComputeMerkleRoot(hashes)
	return lmr
}
Exemplo n.º 2
0
// Returns the LedgerMR for this block.
func (b *FBlock) GetLedgerMR() interfaces.IHash {
	hashes := make([]interfaces.IHash, 0, len(b.Transactions))
	marker := 0
	for i, trans := range b.Transactions {
		for marker < len(b.endOfPeriod) && i != 0 && i == b.endOfPeriod[marker] {
			marker++
			hashes = append(hashes, primitives.Sha(constants.ZERO))
		}
		hashes = append(hashes, trans.GetSigHash())
	}

	// Add any lagging markers
	for marker < len(b.endOfPeriod) {
		marker++
		hashes = append(hashes, primitives.Sha(constants.ZERO))
	}
	lmr := primitives.ComputeMerkleRoot(hashes)
	return lmr
}
Exemplo n.º 3
0
func (b *FBlock) GetBodyMR() interfaces.IHash {

	b.EndOfPeriod(0) // Clean up end of minute markers, if needed.

	hashes := make([]interfaces.IHash, 0, len(b.Transactions))
	marker := 0
	for i, trans := range b.Transactions {
		for marker < len(b.endOfPeriod) && i != 0 && i == b.endOfPeriod[marker] {
			marker++
			hashes = append(hashes, primitives.Sha(constants.ZERO))
		}
		hashes = append(hashes, trans.GetHash())
	}
	// Add any lagging markers
	for marker < len(b.endOfPeriod) {
		marker++
		hashes = append(hashes, primitives.Sha(constants.ZERO))
	}

	b.BodyMR = primitives.ComputeMerkleRoot(hashes)

	return b.BodyMR
}