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

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

	hashes := make([]fct.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, fct.Sha(fct.ZERO))
		}
		data, err := trans.MarshalBinarySig()
		hash := fct.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, fct.Sha(fct.ZERO))
	}
	lmr := fct.ComputeMerkleRoot(hashes)
	return lmr
}
Esempio n. 2
0
func (b *FBlock) GetBodyMR() fct.IHash {

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

	hashes := make([]fct.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, fct.Sha(fct.ZERO))
		}
		hashes = append(hashes, trans.GetHash())
	}
	// Add any lagging markers
	for marker < len(b.endOfPeriod) {
		marker++
		hashes = append(hashes, fct.Sha(fct.ZERO))
	}

	b.BodyMR = fct.ComputeMerkleRoot(hashes)

	return b.BodyMR
}